Add networked crab gathering prototype
This commit is contained in:
parent
f55663c105
commit
a62cce6404
56 changed files with 2692 additions and 56 deletions
|
|
@ -48,8 +48,8 @@ func _run() -> void:
|
|||
as PlayerAssetReservationService
|
||||
)
|
||||
assert(player != null)
|
||||
assert(catalog != null and catalog.candidates.size() == 313)
|
||||
assert(LogbookCatalog.ordered_species(catalog.candidates).size() == 53)
|
||||
assert(catalog != null and catalog.candidates.size() == 314)
|
||||
assert(LogbookCatalog.ordered_species(catalog.candidates).size() == 54)
|
||||
assert(sale_service != null)
|
||||
assert(shop_service != null)
|
||||
assert(session != null and session.is_host())
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func _validate_weight_based_display_scale() -> void:
|
|||
|
||||
|
||||
func _validate_catalog_and_pools() -> void:
|
||||
assert(Catalog.candidates.size() == 313)
|
||||
assert(Catalog.candidates.size() == 314)
|
||||
assert(PondPool.candidates.size() == 19)
|
||||
assert(OceanPool.candidates.size() == 34)
|
||||
var active_count: int = 0
|
||||
|
|
@ -142,7 +142,7 @@ func _validate_catalog_and_pools() -> void:
|
|||
inactive_count += 1
|
||||
assert(not fish.is_selectable())
|
||||
assert(fish.display_texture == null)
|
||||
assert(active_count == 53)
|
||||
assert(active_count == 54)
|
||||
assert(inactive_count == 260)
|
||||
var inactive_fish: FishDataType = Catalog.get_fish_by_id(&"bowfin")
|
||||
assert(inactive_fish != null and not inactive_fish.active)
|
||||
|
|
@ -173,14 +173,20 @@ func _validate_catalog_and_pools() -> void:
|
|||
assert(OceanPool.get_fish_by_id(fish_id) == null)
|
||||
assert(fresh_fish.is_allowed_in_water(WaterType.Type.FRESH_WATER))
|
||||
assert(not fresh_fish.is_allowed_in_water(WaterType.Type.SALT_WATER))
|
||||
assert(LogbookCatalog.category_for(fresh_fish) == WaterType.Type.FRESH_WATER)
|
||||
assert(
|
||||
LogbookCatalog.category_for(fresh_fish)
|
||||
== LogbookCatalog.Category.FRESH_WATER
|
||||
)
|
||||
for fish_id: StringName in SALT_WATER_IDS:
|
||||
var salt_fish: FishDataType = Catalog.get_fish_by_id(fish_id)
|
||||
assert(OceanPool.get_fish_by_id(fish_id) == salt_fish)
|
||||
assert(PondPool.get_fish_by_id(fish_id) == null)
|
||||
assert(salt_fish.is_allowed_in_water(WaterType.Type.SALT_WATER))
|
||||
assert(not salt_fish.is_allowed_in_water(WaterType.Type.FRESH_WATER))
|
||||
assert(LogbookCatalog.category_for(salt_fish) == WaterType.Type.SALT_WATER)
|
||||
assert(
|
||||
LogbookCatalog.category_for(salt_fish)
|
||||
== LogbookCatalog.Category.SALT_WATER
|
||||
)
|
||||
for fish_id: StringName in CATFISH_IDS:
|
||||
var fish: FishDataType = Catalog.get_fish_by_id(fish_id)
|
||||
assert(fish != null)
|
||||
|
|
@ -188,13 +194,19 @@ func _validate_catalog_and_pools() -> void:
|
|||
assert(PondPool.get_fish_by_id(fish_id) == fish)
|
||||
assert(OceanPool.get_fish_by_id(fish_id) == null)
|
||||
assert(fish.availability.allowed_location_tags == [&"starter_pond"])
|
||||
assert(LogbookCatalog.category_for(fish) == WaterType.Type.FRESH_WATER)
|
||||
assert(
|
||||
LogbookCatalog.category_for(fish)
|
||||
== LogbookCatalog.Category.FRESH_WATER
|
||||
)
|
||||
for fish_id: StringName in NEW_FRESH_WATER_IDS:
|
||||
var fish: FishDataType = Catalog.get_fish_by_id(fish_id)
|
||||
assert(fish != null and fish.is_selectable())
|
||||
assert(PondPool.get_fish_by_id(fish_id) == fish)
|
||||
assert(OceanPool.get_fish_by_id(fish_id) == null)
|
||||
assert(LogbookCatalog.category_for(fish) == WaterType.Type.FRESH_WATER)
|
||||
assert(
|
||||
LogbookCatalog.category_for(fish)
|
||||
== LogbookCatalog.Category.FRESH_WATER
|
||||
)
|
||||
|
||||
var expected_values: Dictionary[StringName, Array] = {
|
||||
&"catfish_blue": [1, 1.25, 3.0, 12.0, 6, 9],
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ func _run() -> void:
|
|||
var invalid_state: Dictionary = valid_state.duplicate(true)
|
||||
invalid_state["display_scale"] = 1000.0
|
||||
assert(not NetworkFishShowcaseProtocol.validate_state(invalid_state))
|
||||
assert(NetworkProtocol.PROTOCOL_VERSION == 4)
|
||||
assert(NetworkProtocol.PROTOCOL_VERSION == 5)
|
||||
assert(NetworkProtocol.ENET_CHANNEL_COUNT == 10)
|
||||
assert(
|
||||
NetworkProtocol.FISH_QUALITY_CAPABILITY
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func _run() -> void:
|
|||
_validate_mail_round_trip()
|
||||
_validate_collection_mastery()
|
||||
_validate_version_four_migration()
|
||||
assert(NetworkProtocol.PROTOCOL_VERSION == 4)
|
||||
assert(NetworkProtocol.PROTOCOL_VERSION == 5)
|
||||
assert(NetworkProtocol.ENET_CHANNEL_COUNT == 10)
|
||||
assert(NetworkProtocol.FISH_QUALITY_CAPABILITY == "fish_quality_v1")
|
||||
print("Fish quality validation: PASS")
|
||||
|
|
|
|||
89
tests/gathering_showcase_validation.gd
Normal file
89
tests/gathering_showcase_validation.gd
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
extends SceneTree
|
||||
|
||||
const MainScene: PackedScene = preload("res://main/main.tscn")
|
||||
const TEST_PORT: int = 18142
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
root.size = Vector2i(1280, 720)
|
||||
var main: Node = MainScene.instantiate()
|
||||
root.add_child(main)
|
||||
for _frame: int in 4:
|
||||
await process_frame
|
||||
if not bool(main.get("_application_initialized")):
|
||||
main.call("_activate_selected_data_path", "", true)
|
||||
for _frame: int in 8:
|
||||
await process_frame
|
||||
assert(bool(main.get("_application_initialized")))
|
||||
|
||||
var session := main.get_node("%NetworkSession") as NetworkSession
|
||||
assert(session.start_private_host(TEST_PORT))
|
||||
var save_manager := main.get("_save_manager") as PlayerSaveManager
|
||||
assert(save_manager.initialize_new_game())
|
||||
main.call("_enter_gameplay")
|
||||
for _frame: int in 8:
|
||||
await process_frame
|
||||
|
||||
var player := main.get("_player") as Player
|
||||
var fishing_spot := main.get_node("%FishingSpot") as FishingSpot
|
||||
var catalog := main.get("fish_catalog") as FishPool
|
||||
assert(player != null and fishing_spot != null and catalog != null)
|
||||
assert(player.bag.add_item(&"crab_net"))
|
||||
assert(player.hotbar.assign_item(0, &"crab_net"))
|
||||
assert(player.hotbar.select_slot(0))
|
||||
await process_frame
|
||||
assert(player.hotbar.get_selected_item_id() == &"crab_net")
|
||||
assert(bool(player.get("_active_item_is_net")))
|
||||
|
||||
var crab: FishData = catalog.get_fish_by_id(&"crab_brown")
|
||||
assert(crab != null and crab.is_selectable())
|
||||
var crab_catch := FishCatch.new()
|
||||
crab_catch.fish = crab
|
||||
crab_catch.fish_id = crab.id
|
||||
crab_catch.weight_lb = crab.get_minimum_weight()
|
||||
crab_catch.display_scale = crab.get_display_scale_for_weight(
|
||||
crab_catch.weight_lb
|
||||
)
|
||||
crab_catch.sale_value = crab.get_sale_value_for_weight(
|
||||
crab_catch.weight_lb
|
||||
)
|
||||
crab_catch.ensure_identity()
|
||||
player.inventory.add_catch(crab_catch)
|
||||
player.collection_log.mark_discovered(crab.id)
|
||||
|
||||
assert(fishing_spot.present_external_catch(crab_catch))
|
||||
assert(fishing_spot.state == FishingSpot.FishingState.SHOWING_CATCH)
|
||||
assert(not player.is_movement_enabled())
|
||||
Input.action_release("fish_primary")
|
||||
await process_frame
|
||||
assert(bool(fishing_spot.get("_put_away_press_armed")))
|
||||
|
||||
var pocket_event := InputEventAction.new()
|
||||
pocket_event.action = &"fish_primary"
|
||||
pocket_event.pressed = true
|
||||
Input.parse_input_event(pocket_event)
|
||||
await process_frame
|
||||
assert(fishing_spot.get("_pending_catch") == null)
|
||||
|
||||
var pocket_deadline: int = Time.get_ticks_msec() + 6000
|
||||
while (
|
||||
Time.get_ticks_msec() < pocket_deadline
|
||||
and fishing_spot.state != FishingSpot.FishingState.READY
|
||||
):
|
||||
await process_frame
|
||||
assert(fishing_spot.state == FishingSpot.FishingState.READY)
|
||||
assert(player.is_movement_enabled())
|
||||
assert(player.inventory.contains_catch_id(crab_catch.catch_id))
|
||||
assert(bool(player.get("_active_item_is_net")))
|
||||
print("Gathering showcase validation: PASS")
|
||||
|
||||
session.disconnect_session("")
|
||||
main.queue_free()
|
||||
for _frame: int in 4:
|
||||
await process_frame
|
||||
await create_timer(0.1).timeout
|
||||
quit()
|
||||
1
tests/gathering_showcase_validation.gd.uid
Normal file
1
tests/gathering_showcase_validation.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cedarlvsw4bpm
|
||||
|
|
@ -108,9 +108,9 @@ func _validate_save_round_trip(
|
|||
var player := main.get("_player") as Player
|
||||
var catalog := main.get("fish_catalog") as FishPool
|
||||
assert(catalog != null)
|
||||
assert(catalog.candidates.size() == 313)
|
||||
assert(catalog.candidates.size() == 314)
|
||||
var active_species := LogbookCatalog.ordered_species(catalog.candidates)
|
||||
assert(active_species.size() == 53)
|
||||
assert(active_species.size() == 54)
|
||||
for index: int in 4:
|
||||
_add_test_catch(player, active_species[index])
|
||||
assert(save_manager.save_now())
|
||||
|
|
@ -131,7 +131,7 @@ func _validate_save_round_trip(
|
|||
assert(player.inventory.replace_all_catches(no_catches, 1))
|
||||
assert(player.collection_log.replace_discovered_ids(no_discoveries))
|
||||
assert(save_manager.load_player_data())
|
||||
assert(player.inventory.get_all_catches().size() == 53)
|
||||
assert(player.inventory.get_all_catches().size() == 54)
|
||||
for fish: FishData in active_species:
|
||||
assert(player.inventory.get_count(fish.id) == 1)
|
||||
assert(player.collection_log.has_discovered(fish.id))
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ func _run() -> void:
|
|||
|
||||
|
||||
func _validate_catalog() -> void:
|
||||
assert(CatalogResource.candidates.size() == 313)
|
||||
assert(CatalogResource.candidates.size() == 314)
|
||||
var ordered := LogbookCatalog.ordered_species(CatalogResource.candidates)
|
||||
assert(ordered.size() == 53)
|
||||
assert(ordered.size() == 54)
|
||||
var previous_number: int = 0
|
||||
var catalog_numbers: Dictionary[int, bool] = {}
|
||||
for fish: FishDataType in CatalogResource.candidates:
|
||||
|
|
@ -62,7 +62,7 @@ func _validate_catalog() -> void:
|
|||
assert(LogbookCatalog.catalog_number(fish) == fish.catalog_number)
|
||||
previous_number = fish.catalog_number
|
||||
assert(
|
||||
LogbookCatalog.empty_state(WaterType.Type.SALT_WATER)
|
||||
LogbookCatalog.empty_state(LogbookCatalog.Category.SALT_WATER)
|
||||
== "No saltwater catches cataloged yet."
|
||||
)
|
||||
|
||||
|
|
@ -78,7 +78,9 @@ func _validate_page() -> void:
|
|||
page.setup(collection, inventory, CatalogResource)
|
||||
page.activate()
|
||||
await process_frame
|
||||
assert(page.get("_category") == WaterType.Type.FRESH_WATER)
|
||||
assert(
|
||||
page.get("_category") == LogbookCatalog.Category.FRESH_WATER
|
||||
)
|
||||
assert((page.get("_catalog_grid") as GridContainer).columns == 4)
|
||||
var initial_detail_body := page.get("_detail_body") as VBoxContainer
|
||||
assert(not initial_detail_body.get_parent() is ScrollContainer)
|
||||
|
|
@ -89,14 +91,17 @@ func _validate_page() -> void:
|
|||
|
||||
var shared_material: Material
|
||||
var silhouette_count: int = 0
|
||||
for category: WaterType.Type in [
|
||||
WaterType.Type.FRESH_WATER,
|
||||
WaterType.Type.SALT_WATER,
|
||||
for category: LogbookCatalog.Category in [
|
||||
LogbookCatalog.Category.FRESH_WATER,
|
||||
LogbookCatalog.Category.SALT_WATER,
|
||||
]:
|
||||
page.call("_select_category", category)
|
||||
await create_timer(0.25).timeout
|
||||
var entries: Dictionary = page.get("_entry_buttons")
|
||||
assert(entries.size() == (19 if category == WaterType.Type.FRESH_WATER else 34))
|
||||
assert(
|
||||
entries.size()
|
||||
== (19 if category == LogbookCatalog.Category.FRESH_WATER else 34)
|
||||
)
|
||||
for fish: FishDataType in LogbookCatalog.ordered_species(
|
||||
CatalogResource.candidates
|
||||
):
|
||||
|
|
@ -148,14 +153,20 @@ func _validate_page() -> void:
|
|||
)
|
||||
assert(silhouette_count == 53)
|
||||
|
||||
page.call("_select_category", WaterType.Type.OTHER)
|
||||
page.call("_select_category", LogbookCatalog.Category.SHELLFISH)
|
||||
await create_timer(0.25).timeout
|
||||
assert((page.get("_entry_buttons") as Dictionary).size() == 1)
|
||||
assert(
|
||||
(page.get("_entry_buttons") as Dictionary).has(&"unknown_3906")
|
||||
)
|
||||
page.call("_select_category", LogbookCatalog.Category.OTHER)
|
||||
await create_timer(0.25).timeout
|
||||
assert((page.get("_entry_buttons") as Dictionary).is_empty())
|
||||
assert(
|
||||
(page.get("_empty_state") as Label).text
|
||||
== "No entries available."
|
||||
)
|
||||
page.call("_select_category", WaterType.Type.FRESH_WATER)
|
||||
page.call("_select_category", LogbookCatalog.Category.FRESH_WATER)
|
||||
await create_timer(0.25).timeout
|
||||
|
||||
var bluegill = CatalogResource.get_fish_by_id(&"bluegill")
|
||||
|
|
|
|||
168
tests/world_spawn_multiplayer_validation.gd
Normal file
168
tests/world_spawn_multiplayer_validation.gd
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
extends SceneTree
|
||||
|
||||
const MainScene: PackedScene = preload("res://main/main.tscn")
|
||||
const TEST_PORT: int = 18141
|
||||
const EXPECTED_POPULATION: int = 2
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var arguments: PackedStringArray = OS.get_cmdline_user_args()
|
||||
if arguments.has("host"):
|
||||
await _run_host()
|
||||
return
|
||||
if arguments.has("client"):
|
||||
await _run_client()
|
||||
return
|
||||
push_error("World spawn multiplayer validation needs host or client mode.")
|
||||
quit(1)
|
||||
|
||||
|
||||
func _run_host() -> void:
|
||||
var main: Node = await _create_initialized_main()
|
||||
var session := main.get_node("%NetworkSession") as NetworkSession
|
||||
var service: Node = main.get_node("%NetworkWorldSpawnService")
|
||||
assert(session.start_dedicated_host(TEST_PORT, 8, "127.0.0.1"))
|
||||
assert(session.set_host_open(true))
|
||||
await _wait_for_population(service)
|
||||
_validate_population(service)
|
||||
|
||||
var remote_peer_id: int = 0
|
||||
var join_deadline: int = Time.get_ticks_msec() + 20000
|
||||
while Time.get_ticks_msec() < join_deadline and remote_peer_id == 0:
|
||||
await process_frame
|
||||
for peer_id: int in session.get_authenticated_peer_ids():
|
||||
if peer_id != session.get_local_peer_id():
|
||||
remote_peer_id = peer_id
|
||||
break
|
||||
assert(remote_peer_id > 1)
|
||||
assert(session.peer_supports_capability(
|
||||
remote_peer_id,
|
||||
NetworkProtocol.WORLD_SPAWN_CAPABILITY,
|
||||
))
|
||||
|
||||
var disconnect_deadline: int = Time.get_ticks_msec() + 12000
|
||||
while (
|
||||
Time.get_ticks_msec() < disconnect_deadline
|
||||
and session.is_authenticated_peer(remote_peer_id)
|
||||
):
|
||||
await process_frame
|
||||
assert(not session.is_authenticated_peer(remote_peer_id))
|
||||
_validate_population(service)
|
||||
_validate_respawn_budget(service)
|
||||
print("World spawn multiplayer host validation: PASS")
|
||||
session.disconnect_session("")
|
||||
main.queue_free()
|
||||
for _frame: int in 4:
|
||||
await process_frame
|
||||
await create_timer(0.1).timeout
|
||||
quit()
|
||||
|
||||
|
||||
func _run_client() -> void:
|
||||
var main: Node = await _create_initialized_main()
|
||||
main.call(
|
||||
"_on_title_join_game_requested",
|
||||
"127.0.0.1:%d" % TEST_PORT,
|
||||
)
|
||||
var session := main.get_node("%NetworkSession") as NetworkSession
|
||||
var service: Node = main.get_node("%NetworkWorldSpawnService")
|
||||
var join_deadline: int = Time.get_ticks_msec() + 20000
|
||||
while Time.get_ticks_msec() < join_deadline:
|
||||
await process_frame
|
||||
if session.state == NetworkSession.State.VERIFYING_SERVER_IDENTITY:
|
||||
main.call("_confirm_server_trust")
|
||||
if session.is_joined_client() and bool(main.get("_gameplay_started")):
|
||||
break
|
||||
assert(session.is_joined_client())
|
||||
assert(session.supports_server_capability(
|
||||
NetworkProtocol.WORLD_SPAWN_CAPABILITY
|
||||
))
|
||||
await _wait_for_population(service)
|
||||
_validate_population(service)
|
||||
print("World spawn multiplayer client validation: PASS")
|
||||
session.disconnect_session("")
|
||||
main.queue_free()
|
||||
for _frame: int in 4:
|
||||
await process_frame
|
||||
await create_timer(0.1).timeout
|
||||
quit()
|
||||
|
||||
|
||||
func _wait_for_population(service: Node) -> void:
|
||||
var deadline: int = Time.get_ticks_msec() + 12000
|
||||
while Time.get_ticks_msec() < deadline:
|
||||
await process_frame
|
||||
if (service.get("_entities") as Dictionary).size() == EXPECTED_POPULATION:
|
||||
return
|
||||
assert(false, "Timed out waiting for the world spawn population.")
|
||||
|
||||
|
||||
func _validate_population(service: Node) -> void:
|
||||
var entities: Dictionary = service.get("_entities")
|
||||
var presentations: Dictionary = service.get("_presentations")
|
||||
assert(entities.size() == EXPECTED_POPULATION)
|
||||
assert(presentations.size() == EXPECTED_POPULATION)
|
||||
for state: Dictionary in entities.values():
|
||||
assert(state.get("type_id") == &"crab_brown")
|
||||
var position: Variant = state.get("position")
|
||||
assert(typeof(position) == TYPE_VECTOR3)
|
||||
assert((position as Vector3).is_finite())
|
||||
assert((position as Vector3).y > 0.08)
|
||||
|
||||
|
||||
func _validate_respawn_budget(service: Node) -> void:
|
||||
var entities: Dictionary = service.get("_entities")
|
||||
var entity_ids: Array = entities.keys()
|
||||
assert(entity_ids.size() == EXPECTED_POPULATION)
|
||||
for entity_id: Variant in entity_ids:
|
||||
service.call(
|
||||
"_despawn_entity",
|
||||
str(entity_id),
|
||||
&"captured",
|
||||
false,
|
||||
true,
|
||||
)
|
||||
assert((service.get("_entities") as Dictionary).is_empty())
|
||||
|
||||
var now: float = Time.get_ticks_msec() / 1000.0
|
||||
var respawns: Array = service.get("_respawns")
|
||||
assert(respawns.size() == EXPECTED_POPULATION)
|
||||
for index: int in respawns.size():
|
||||
var respawn: Dictionary = respawns[index]
|
||||
var delay: float = float(respawn.get("due", 0.0)) - now
|
||||
assert(delay >= 479.0 and delay <= 721.0)
|
||||
respawn["due"] = now - 1.0
|
||||
respawns[index] = respawn
|
||||
|
||||
service.call("_update_respawns")
|
||||
assert((service.get("_entities") as Dictionary).size() == 1)
|
||||
assert((service.get("_respawns") as Array).size() == 1)
|
||||
var next_by_type: Dictionary = service.get("_next_respawn_by_type")
|
||||
var next_allowed: float = float(next_by_type.get(&"crab_brown", 0.0))
|
||||
assert(next_allowed - now >= 179.0)
|
||||
|
||||
service.call("_update_respawns")
|
||||
assert((service.get("_entities") as Dictionary).size() == 1)
|
||||
assert((service.get("_respawns") as Array).size() == 1)
|
||||
next_by_type[&"crab_brown"] = now - 1.0
|
||||
service.call("_update_respawns")
|
||||
assert((service.get("_entities") as Dictionary).size() == 2)
|
||||
assert((service.get("_respawns") as Array).is_empty())
|
||||
|
||||
|
||||
func _create_initialized_main() -> Node:
|
||||
root.size = Vector2i(1280, 720)
|
||||
var main: Node = MainScene.instantiate()
|
||||
root.add_child(main)
|
||||
for _frame: int in 4:
|
||||
await process_frame
|
||||
if not bool(main.get("_application_initialized")):
|
||||
main.call("_activate_selected_data_path", "", true)
|
||||
for _frame: int in 8:
|
||||
await process_frame
|
||||
assert(bool(main.get("_application_initialized")))
|
||||
return main
|
||||
1
tests/world_spawn_multiplayer_validation.gd.uid
Normal file
1
tests/world_spawn_multiplayer_validation.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://wumg5ev7jr6e
|
||||
102
tests/world_spawn_protocol_validation.gd
Normal file
102
tests/world_spawn_protocol_validation.gd
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
extends SceneTree
|
||||
|
||||
const Gatherables: GatherableCatalog = preload(
|
||||
"res://gathering/catalog/gatherable_catalog.tres"
|
||||
)
|
||||
const FishCatalog: FishPool = preload("res://fish/pools/fish_catalog.tres")
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
assert(NetworkProtocol.PROTOCOL_VERSION == 5)
|
||||
assert(
|
||||
NetworkWorldSpawnProtocol.CAPABILITY
|
||||
== NetworkProtocol.WORLD_SPAWN_CAPABILITY
|
||||
)
|
||||
assert(NetworkWorldSpawnProtocol.SNAPSHOT_ENTITIES_PER_ENVELOPE <= 4)
|
||||
_validate_catalog_statuses()
|
||||
_validate_envelopes()
|
||||
print("World spawn protocol validation: PASS")
|
||||
quit()
|
||||
|
||||
|
||||
func _validate_catalog_statuses() -> void:
|
||||
var brown: GatherableData = Gatherables.get_entry(&"crab_brown")
|
||||
assert(brown != null and brown.is_available())
|
||||
assert(brown.catch_data.active)
|
||||
assert(brown.catch_data.collection_method == FishData.CollectionMethod.NET)
|
||||
assert(brown.catch_data.logbook_section == FishData.LogbookSection.SHELLFISH)
|
||||
assert(brown.population == 2)
|
||||
assert(is_equal_approx(brown.charge_duration, 2.0))
|
||||
assert(is_equal_approx(brown.capture_respawn_min_seconds, 480.0))
|
||||
assert(is_equal_approx(brown.capture_respawn_max_seconds, 720.0))
|
||||
assert(is_equal_approx(brown.scare_respawn_min_seconds, 45.0))
|
||||
assert(is_equal_approx(brown.scare_respawn_max_seconds, 90.0))
|
||||
assert(is_equal_approx(brown.minimum_respawn_spacing_seconds, 180.0))
|
||||
assert(brown.required_tool_id == &"crab_net")
|
||||
assert(FishCatalog.get_fish_by_id(&"crab_brown") == brown.catch_data)
|
||||
assert(not brown.catch_data.is_fishable())
|
||||
|
||||
for type_id: StringName in [
|
||||
&"crab_ghost",
|
||||
&"crab_blue",
|
||||
&"crab_dungeness",
|
||||
]:
|
||||
var entry: GatherableData = Gatherables.get_entry(type_id)
|
||||
assert(entry != null)
|
||||
assert(entry.is_valid())
|
||||
assert(not entry.catch_data.active)
|
||||
assert(not entry.is_available())
|
||||
assert(entry.catch_data.collection_method == FishData.CollectionMethod.NET)
|
||||
assert(
|
||||
entry.catch_data.logbook_section
|
||||
== FishData.LogbookSection.SHELLFISH
|
||||
)
|
||||
|
||||
var available: Array[GatherableData] = Gatherables.get_available_entries()
|
||||
assert(available.size() == 1)
|
||||
assert(available.front() == brown)
|
||||
var rng := RandomNumberGenerator.new()
|
||||
rng.seed = 24680
|
||||
var captured_delay: float = brown.get_respawn_delay(&"captured", rng)
|
||||
var scared_delay: float = brown.get_respawn_delay(&"scared", rng)
|
||||
assert(captured_delay >= 480.0 and captured_delay <= 720.0)
|
||||
assert(scared_delay >= 45.0 and scared_delay <= 90.0)
|
||||
|
||||
|
||||
func _validate_envelopes() -> void:
|
||||
var entity: Dictionary = {
|
||||
"entity_id": "world:sample",
|
||||
"type_id": "future_shellfish",
|
||||
"position": [1.0, 2.0, 3.0],
|
||||
"yaw": 0.5,
|
||||
"revision": 7,
|
||||
}
|
||||
assert(NetworkWorldSpawnProtocol.validate_entity_state(entity))
|
||||
var future_entity: Dictionary = entity.duplicate(true)
|
||||
future_entity["future_state"] = {"buried": false}
|
||||
assert(NetworkWorldSpawnProtocol.validate_entity_state(future_entity))
|
||||
|
||||
var envelope: Dictionary = NetworkWorldSpawnProtocol.make_envelope(
|
||||
"session-test",
|
||||
12,
|
||||
&"future_spawn_type",
|
||||
{"entity": entity, "future_payload": [1, 2, 3]},
|
||||
)
|
||||
assert(NetworkWorldSpawnProtocol.validate_envelope(envelope))
|
||||
|
||||
var malformed_position: Dictionary = entity.duplicate(true)
|
||||
malformed_position["position"] = [1.0, "not-a-number", 3.0]
|
||||
assert(
|
||||
not NetworkWorldSpawnProtocol.validate_entity_state(
|
||||
malformed_position
|
||||
)
|
||||
)
|
||||
assert(
|
||||
not NetworkWorldSpawnProtocol.array_to_vector3(
|
||||
malformed_position["position"]
|
||||
).is_finite()
|
||||
)
|
||||
|
||||
var invalid_envelope: Dictionary = envelope.duplicate(true)
|
||||
invalid_envelope["envelope_version"] = 0
|
||||
assert(not NetworkWorldSpawnProtocol.validate_envelope(invalid_envelope))
|
||||
1
tests/world_spawn_protocol_validation.gd.uid
Normal file
1
tests/world_spawn_protocol_validation.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://clu8j64mh4x54
|
||||
Loading…
Add table
Add a link
Reference in a new issue