Compare commits

..

No commits in common. "a8cedcbd64d55bfff840f76ef893ca3c5c565abc" and "501834279e216edbee4322309a1e679a2830cc87" have entirely different histories.

5 changed files with 19 additions and 20 deletions

View File

@ -40,7 +40,6 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
if rid.is_empty():
return false
_current_recipe_id = rid
_busy = true
var payload: Dictionary = {
"schemaVersion": SCHEMA_VERSION,
"recipeId": rid,
@ -50,10 +49,10 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
var headers := PackedStringArray(["Content-Type: application/json"])
var err: Error = _http.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
if err != OK:
_busy = false
_current_recipe_id = ""
push_warning("CraftClient: POST failed to start (%s)" % err)
return false
_busy = true
return true

View File

@ -366,11 +366,11 @@ func _apply_authority_http_config_to_client(client: Node) -> void:
func _on_item_definitions_ready(_definitions_by_id: Dictionary) -> void:
_populate_craft_recipe_panel_if_ready()
if not _inventory_error.is_empty():
return
if not _last_inventory_snapshot.is_empty():
_render_inventory_label()
_populate_craft_recipe_panel_if_ready()
func _on_inventory_received(snapshot: Dictionary) -> void:

View File

@ -41,6 +41,20 @@ func request_sync_from_server() -> void:
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:
return base_url.strip_edges().rstrip("/")

View File

@ -130,15 +130,3 @@ func test_http_error_emits_craft_request_failed() -> void:
c.call("request_craft", "refine_scrap_standard")
# Assert
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()

View File

@ -1,7 +1,6 @@
extends GdUnitTestSuite
## 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")
@ -103,10 +102,9 @@ func test_http_error_emits_recipes_sync_failed_with_status() -> void:
var transport := MockHttpTransport.new()
transport.response_code = 503
var c := _make_client(transport)
var got: Array = []
c.connect("recipes_sync_failed", func(reason: String) -> void: got.append(reason))
var failed_reason := ""
c.connect("recipes_sync_failed", func(reason: String) -> void: failed_reason = reason)
# Act
c.call("request_sync_from_server")
# Assert
assert_that(got.size()).is_equal(1)
assert_that(str(got[0])).contains("503")
assert_that(failed_reason).contains("503")