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

40 lines
849 B
GDScript

class_name BuildingApi
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 upgrade_house(token: String) -> Dictionary:
return await _post("farm/upgrade", {"token": token})
func extend_land(token: String) -> Dictionary:
return await _post("farm/extend-land", {"token": token})
func upgrade_land(token: String, level: int) -> Dictionary:
return await _post("farm/upgrade-land", {
"token": token,
"level": level
})
func _post(path: String, payload: Dictionary) -> Dictionary:
if _api_client == null:
return {
"ok": false,
"offline": true,
"status": 0,
"body": {},
"text": "BuildingApi missing ApiClient."
}
return await _api_client.post_json(path, payload)