Place initial gameplay actors in test map

This commit is contained in:
2026-05-13 19:04:41 -07:00
parent 744b3c35e2
commit 46d0e080b5
11 changed files with 288 additions and 21 deletions
+85
View File
@@ -0,0 +1,85 @@
import unreal
MAP_PATH = "/Game/ThirdPerson/Lvl_ThirdPerson"
PLACEMENTS = [
{
"label": "AGR_WoodResourceNode_01",
"class_path": "/Game/Agrarian/Blueprints/Resources/BP_WoodResourceNode",
"location": unreal.Vector(650.0, -150.0, 120.0),
"rotation": unreal.Rotator(0.0, 15.0, 0.0),
},
{
"label": "AGR_Campfire_01",
"class_path": "/Game/Agrarian/Blueprints/Structures/BP_Campfire",
"location": unreal.Vector(900.0, 120.0, 60.0),
"rotation": unreal.Rotator(0.0, 0.0, 0.0),
},
{
"label": "AGR_PrimitiveShelter_01",
"class_path": "/Game/Agrarian/Blueprints/Structures/BP_PrimitiveShelter",
"location": unreal.Vector(1200.0, -260.0, 140.0),
"rotation": unreal.Rotator(0.0, -20.0, 0.0),
},
{
"label": "AGR_RabbitWildlife_01",
"class_path": "/Game/Agrarian/Blueprints/Wildlife/BP_RabbitWildlife",
"location": unreal.Vector(450.0, 420.0, 100.0),
"rotation": unreal.Rotator(0.0, 135.0, 0.0),
},
]
def load_blueprint_class(path):
generated_class = unreal.EditorAssetLibrary.load_blueprint_class(path)
if not generated_class:
raise RuntimeError(f"Could not load Blueprint class: {path}")
return generated_class
def get_actor_label(actor):
try:
return actor.get_actor_label()
except Exception:
return actor.get_name()
def remove_existing_placed_actors(labels):
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
if get_actor_label(actor) in labels:
unreal.EditorLevelLibrary.destroy_actor(actor)
def set_actor_label(actor, label):
try:
actor.set_actor_label(label, mark_dirty=True)
except TypeError:
actor.set_actor_label(label)
def main():
if not unreal.EditorLevelLibrary.load_level(MAP_PATH):
raise RuntimeError(f"Could not load map: {MAP_PATH}")
labels = {placement["label"] for placement in PLACEMENTS}
remove_existing_placed_actors(labels)
for placement in PLACEMENTS:
actor_class = load_blueprint_class(placement["class_path"])
actor = unreal.AgrarianEditorAutomationLibrary.spawn_actor_in_editor_world(
actor_class,
placement["location"],
placement["rotation"],
placement["label"],
)
if not actor:
raise RuntimeError(f"Could not spawn {placement['class_path']}")
unreal.log(f"Placed {placement['label']} at {placement['location']}")
unreal.EditorLevelLibrary.save_current_level()
unreal.log("Agrarian test map placement setup complete.")
main()
+91
View File
@@ -0,0 +1,91 @@
import unreal
MAP_PATH = "/Game/ThirdPerson/Lvl_ThirdPerson"
EXPECTED_PLACEMENTS = {
"AGR_WoodResourceNode_01": {
"class_path": "/Game/Agrarian/Blueprints/Resources/BP_WoodResourceNode",
"location": unreal.Vector(650.0, -150.0, 120.0),
"properties": {
"remaining_harvests": 6,
"quantity_per_harvest": 2,
},
},
"AGR_Campfire_01": {
"class_path": "/Game/Agrarian/Blueprints/Structures/BP_Campfire",
"location": unreal.Vector(900.0, 120.0, 60.0),
"properties": {
"fuel_seconds": 180.0,
"warmth_radius": 650.0,
},
},
"AGR_PrimitiveShelter_01": {
"class_path": "/Game/Agrarian/Blueprints/Structures/BP_PrimitiveShelter",
"location": unreal.Vector(1200.0, -260.0, 140.0),
"properties": {
"weather_protection": 0.7,
},
},
"AGR_RabbitWildlife_01": {
"class_path": "/Game/Agrarian/Blueprints/Wildlife/BP_RabbitWildlife",
"location": unreal.Vector(450.0, 420.0, 100.0),
"properties": {
"wildlife_id": "rabbit",
"max_health": 12.0,
},
},
}
def nearly_equal(left, right):
return abs(float(left) - float(right)) < 0.001
def vectors_close(left, right):
return (
abs(left.x - right.x) < 0.1
and abs(left.y - right.y) < 0.1
and abs(left.z - right.z) < 0.1
)
def get_actor_label(actor):
try:
return actor.get_actor_label()
except Exception:
return actor.get_name()
def main():
if not unreal.EditorLevelLibrary.load_level(MAP_PATH):
raise RuntimeError(f"Could not load map: {MAP_PATH}")
failures = []
actors_by_label = {get_actor_label(actor): actor for actor in unreal.EditorLevelLibrary.get_all_level_actors()}
for label, expected in EXPECTED_PLACEMENTS.items():
actor = actors_by_label.get(label)
if not actor:
failures.append(f"{label} missing")
continue
actor_location = actor.get_actor_location()
if not vectors_close(actor_location, expected["location"]):
failures.append(f"{label} expected location {expected['location']}, got {actor_location}")
for property_name, expected_value in expected.get("properties", {}).items():
actual_value = actor.get_editor_property(property_name)
if isinstance(expected_value, (int, float)):
if not nearly_equal(actual_value, expected_value):
failures.append(f"{label} {property_name} expected {expected_value}, got {actual_value}")
elif str(actual_value) != expected_value:
failures.append(f"{label} {property_name} expected {expected_value}, got {actual_value}")
if failures:
raise RuntimeError("Test map placement verification failed: " + "; ".join(failures))
unreal.log("Agrarian test map placement verification complete.")
main()