Compare commits
3 Commits
501834279e
...
a8cedcbd64
| Author | SHA1 | Date |
|---|---|---|
|
|
a8cedcbd64 | |
|
|
d6d95ec438 | |
|
|
f939132f38 |
|
|
@ -40,6 +40,7 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
|
||||||
if rid.is_empty():
|
if rid.is_empty():
|
||||||
return false
|
return false
|
||||||
_current_recipe_id = rid
|
_current_recipe_id = rid
|
||||||
|
_busy = true
|
||||||
var payload: Dictionary = {
|
var payload: Dictionary = {
|
||||||
"schemaVersion": SCHEMA_VERSION,
|
"schemaVersion": SCHEMA_VERSION,
|
||||||
"recipeId": rid,
|
"recipeId": rid,
|
||||||
|
|
@ -49,10 +50,10 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
|
||||||
var headers := PackedStringArray(["Content-Type: application/json"])
|
var headers := PackedStringArray(["Content-Type: application/json"])
|
||||||
var err: Error = _http.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
var err: Error = _http.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
||||||
if err != OK:
|
if err != OK:
|
||||||
|
_busy = false
|
||||||
_current_recipe_id = ""
|
_current_recipe_id = ""
|
||||||
push_warning("CraftClient: POST failed to start (%s)" % err)
|
push_warning("CraftClient: POST failed to start (%s)" % err)
|
||||||
return false
|
return false
|
||||||
_busy = true
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -366,11 +366,11 @@ func _apply_authority_http_config_to_client(client: Node) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_item_definitions_ready(_definitions_by_id: Dictionary) -> void:
|
func _on_item_definitions_ready(_definitions_by_id: Dictionary) -> void:
|
||||||
|
_populate_craft_recipe_panel_if_ready()
|
||||||
if not _inventory_error.is_empty():
|
if not _inventory_error.is_empty():
|
||||||
return
|
return
|
||||||
if not _last_inventory_snapshot.is_empty():
|
if not _last_inventory_snapshot.is_empty():
|
||||||
_render_inventory_label()
|
_render_inventory_label()
|
||||||
_populate_craft_recipe_panel_if_ready()
|
|
||||||
|
|
||||||
|
|
||||||
func _on_inventory_received(snapshot: Dictionary) -> void:
|
func _on_inventory_received(snapshot: Dictionary) -> void:
|
||||||
|
|
|
||||||
|
|
@ -41,20 +41,6 @@ func request_sync_from_server() -> void:
|
||||||
recipes_sync_failed.emit(reason)
|
recipes_sync_failed.emit(reason)
|
||||||
|
|
||||||
|
|
||||||
func recipes_snapshot() -> Array:
|
|
||||||
return _recipes.duplicate(true)
|
|
||||||
|
|
||||||
|
|
||||||
func recipe_by_id(recipe_id: String) -> Dictionary:
|
|
||||||
for row_variant in _recipes:
|
|
||||||
if not row_variant is Dictionary:
|
|
||||||
continue
|
|
||||||
var row: Dictionary = row_variant
|
|
||||||
if str(row.get("id", "")) == recipe_id:
|
|
||||||
return row.duplicate(true)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
func _base_root() -> String:
|
func _base_root() -> String:
|
||||||
return base_url.strip_edges().rstrip("/")
|
return base_url.strip_edges().rstrip("/")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,3 +130,15 @@ func test_http_error_emits_craft_request_failed() -> void:
|
||||||
c.call("request_craft", "refine_scrap_standard")
|
c.call("request_craft", "refine_scrap_standard")
|
||||||
# Assert
|
# Assert
|
||||||
assert_that(_failed_reason).contains("404")
|
assert_that(_failed_reason).contains("404")
|
||||||
|
|
||||||
|
|
||||||
|
func test_request_craft_clears_busy_after_sync_mock_response() -> void:
|
||||||
|
# Arrange
|
||||||
|
var transport := MockHttpTransport.new()
|
||||||
|
transport.body_json = _success_craft_json()
|
||||||
|
var c := _make_client(transport)
|
||||||
|
# Act
|
||||||
|
var started: bool = bool(c.call("request_craft", "refine_scrap_standard", 1))
|
||||||
|
# Assert
|
||||||
|
assert_that(started).is_true()
|
||||||
|
assert_that(bool(c.call("is_busy"))).is_false()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
extends GdUnitTestSuite
|
extends GdUnitTestSuite
|
||||||
|
|
||||||
## NEO-74: `RecipeDefinitionsClient` GET parse + `recipes_ready` signal.
|
## NEO-74: `RecipeDefinitionsClient` GET parse + `recipes_ready` signal.
|
||||||
|
## `main.gd` repopulates craft panel on item `definitions_ready` even when inventory GET failed.
|
||||||
|
|
||||||
const RecipeDefinitionsClient := preload("res://scripts/recipe_definitions_client.gd")
|
const RecipeDefinitionsClient := preload("res://scripts/recipe_definitions_client.gd")
|
||||||
|
|
||||||
|
|
@ -102,9 +103,10 @@ func test_http_error_emits_recipes_sync_failed_with_status() -> void:
|
||||||
var transport := MockHttpTransport.new()
|
var transport := MockHttpTransport.new()
|
||||||
transport.response_code = 503
|
transport.response_code = 503
|
||||||
var c := _make_client(transport)
|
var c := _make_client(transport)
|
||||||
var failed_reason := ""
|
var got: Array = []
|
||||||
c.connect("recipes_sync_failed", func(reason: String) -> void: failed_reason = reason)
|
c.connect("recipes_sync_failed", func(reason: String) -> void: got.append(reason))
|
||||||
# Act
|
# Act
|
||||||
c.call("request_sync_from_server")
|
c.call("request_sync_from_server")
|
||||||
# Assert
|
# Assert
|
||||||
assert_that(failed_reason).contains("503")
|
assert_that(got.size()).is_equal(1)
|
||||||
|
assert_that(str(got[0])).contains("503")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue