2026-05-29 19:54:56 +08:00

70 lines
1.5 KiB
GDScript

class_name FarmApi
extends RefCounted
var _api_client: ApiClient
func _init(api_client: ApiClient = null) -> void:
_api_client = api_client
func set_api_client(api_client: ApiClient) -> void:
_api_client = api_client
func sow_seed(token: String, position: int, item_id: int) -> Dictionary:
return await _post("farm/sow-seeds", {
"position": position,
"item_id": item_id,
"token": token
})
func gather_crop(token: String, position: int) -> Dictionary:
return await _post("farm/gather-crop", {
"position": position,
"token": token
})
func clear_land(token: String, position: int) -> Dictionary:
return await _post("farm/clear-land", {
"position": position,
"token": token
})
func fertilize(token: String, position: int, item_id: int) -> Dictionary:
return await _post("farm/fertilize", {
"position": position,
"item_id": item_id,
"token": token
})
func kick_disease(token: String, position: int, disease_type: int) -> Dictionary:
return await _post("farm/disease", {
"position": position,
"type": disease_type,
"token": token
})
func change_bg(token: String, item_id: int) -> Dictionary:
return await _post("farm/change-bg", {
"item_id": item_id,
"token": token
})
func _post(path: String, payload: Dictionary) -> Dictionary:
if _api_client == null:
return {
"ok": false,
"offline": true,
"status": 0,
"body": {},
"text": "FarmApi missing ApiClient."
}
return await _api_client.post_json(path, payload)