Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/AI_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ server (docs/MCP.md), and to see the result in the game with OpenRAC's game serv
Then `level_place` with the new things' `names` and `move`: it sets each one down on its whole
underside (no floating, no sinking, none in a wall) and moves a crate off a slope.
4. `scene_save`, then `level_check` and `job_wait`: each refused edit comes with the node's path
and why. Fix and check again until none is left.
and why. Fix and check again until none is left. Check also lists what a player would see wrong
(cracks in the ground, collision off what is drawn, things floating or inside each other): run
`level_check_map` with `fix`, then mend the rest by hand.
5. To play it: `level_play` (the game starts on the level), or `planet_set` then `planet_add` for a
new planet the ship can fly to.
6. To see it in the game, use the game server: `game_start` on the level with the packed folder,
Expand Down
19 changes: 19 additions & 0 deletions docs/MAP_MODDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ In practice, memory and frame time become the useful limits well before that.

## 3. Pack and export an added destination

### The map check

Play, Check, Pack, **Add as a new planet** and map export first check the level for what a
player would see wrong, and stop when they find any:

- cracks and holes in your own terrain (a line of sky through the ground);
- collision that does not follow what is drawn (the hero falls through, stands in the air or
sinks in);
- things floating over the ground, sunk into it or standing in a wall;
- ties and models standing inside each other.

Each problem names its node and place; click it in the dialog to select the node. Press **Fix**
to mend what can be mended without a choice: cracks are welded and small holes filled, the
collision of your terrain is made again from what is drawn, ties and models are moved out of each
other and things are set down on the ground. What is left is listed again for you to mend by hand.
From a terminal: `openrac_editor.py check-map PROJECT [--fix] [--report FILE]` (`--report` also
writes a top view of the problems). Set `map/water` in `project.godot`'s `[openrac]` section to your
sea's height so nothing under it counts. `--keep-problems` packs a level as it is.

### The quick way

1. In the editor, click the level (the top object in the **Level** list). Its **Properties**
Expand Down
1 change: 1 addition & 0 deletions docs/MCP.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ x and y across, z up, headings in degrees):
| `behaviour_list` | The behaviour presets and their numbers |
| `ground_at` | The floor under a point, from the level's collision |
| `level_place` | Sets mobys, ties and shrubs down on their whole underside: no floating, sinking or wall (a job; `move` finds a level spot) |
| `level_check_map` | Lists what a player would see wrong (cracks, holes, collision off the drawn ground, things floating or inside each other); with `fix` mends what it can first (a job) |
| `cutscene_list`, `cutscene_get`, `cutscene_remove` | The level's cutscenes as `.cutscene` documents ([CUTSCENE_FORMAT.md](CUTSCENE_FORMAT.md)) |
| `cutscene_write`, `cutscene_add` | Write a whole cutscene, or add shots, actors, lines, sounds and events to one |
| `cutscene_check` | What the game would not take or would skip |
Expand Down
40 changes: 40 additions & 0 deletions openrac/project/addons/openrac_library/mcp_tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func register(on: Object, owner: EditorPlugin) -> void:
"move": prop("boolean", "A thing that cannot stand where it is moves to the nearest good spot (default false: only listed)."),
"water": prop("number", "The water's height: things afloat on it stay."),
"check": prop("boolean", "Only list what is off; change nothing.")}, [], level_place)
add("level_check_map", "Checks the level for what a player would see wrong: cracks and holes in the level's own "
+ "ground, collision off what is drawn (falls through, stands in the air), things floating, sunk or inside "
+ "each other. Each problem as {node, path, why} (why ends with \"at (x, y, z)\"). Pack, Play, Add as planet "
+ "and map export refuse a level with any. With fix it first mends what it can: cracks welded, collision "
+ "made from the drawn ground, things set down and moved apart; the scene is read again. A job.", {
"fix": prop("boolean", "Mend what can be mended first (default false: only list)."),
"water": prop("number", "The sea's height: nothing under it shows (default: the project's map/water).")},
[], level_check_map)
add("planet_get", "The planet's name in the ship's menu and its id (set once it was added).", {}, [], planet_get, read_only)
add("planet_set", "Names this level as a planet (the ship's menu): plain letters A-Z, digits, spaces and punctuation, "
+ "at most 40 characters. Saved in project.godot.", {"name": prop("string", "The planet's name.")}, ["name"], planet_set)
Expand Down Expand Up @@ -212,6 +220,26 @@ func parsed(code: int, lines: PackedStringArray, kind: String) -> Dictionary:

var result: Dictionary = {"ok": code == 0 and problems.is_empty(), "kind": kind, "problems": problems, "said": said}

if kind == "check-map":
var fixed: bool = false

for line in said:
fixed = fixed or String(line).begins_with("fixed: ")

# The fix wrote the scene under the editor: read it again.
if fixed and at != null:
EditorInterface.reload_scene_from_path.call_deferred(at.scene_file_path)

if not result["ok"]:
if not problems.is_empty():
result["error"] = "%d problem(s) a player would see: run with fix, then mend the rest (path) by hand." % problems.size()
elif not said.is_empty():
result["error"] = "\n".join(PackedStringArray(said.slice(-5)))
else:
result["error"] = "It did not run."

return result

if kind == "place":
# The scene file was written under the editor: read it again (nothing changed with --check).
if at != null and not said.is_empty() and not String(said[-1]).begins_with("would") and not String(said[-1]).begins_with("set 0 "):
Expand Down Expand Up @@ -265,6 +293,18 @@ func level_place(args: Dictionary) -> Variant:
return run_tool("place", "Set things down", extra)


func level_check_map(args: Dictionary) -> Variant:
var extra := PackedStringArray()

if bool(args.get("fix", false)):
extra.append("--fix")

if args.get("water") != null:
extra.append_array(["--water", str(float(args["water"]))])

return run_tool("check-map", "Check the map", extra)


func planet_get(_args: Dictionary) -> Dictionary:
PlanetInspector.sync_id()
return {"name": String(ProjectSettings.get_setting("openrac/planet/name", "")),
Expand Down
63 changes: 58 additions & 5 deletions openrac/project/addons/openrac_library/play.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var dialog: AcceptDialog
var problems: ItemList
var summary: Label
var worker: Thread
## Fix in the dialog when the map has problems (openrac_editor.py check-map --fix).
var fix_button: Button


func _init() -> void:
Expand All @@ -42,6 +44,12 @@ func _init() -> void:
problems.item_clicked.connect(func(index: int, _at: Vector2, _button: int) -> void: select_problem(index))
box.add_child(problems)
dialog.add_child(box)
fix_button = dialog.add_button("Fix", true, "fix")
fix_button.tooltip_text = "Mends what can be mended without a choice: cracks and holes in your ground welded, collision made from what you see, things set down on the ground and moved out of each other."
fix_button.visible = false
dialog.custom_action.connect(func(action: StringName) -> void:
if action == &"fix":
fix())
add_child(dialog)


Expand Down Expand Up @@ -126,7 +134,7 @@ static func game_beside(states: String) -> String:
return states.left(states.length() - name.length()) + name.replace("-states", "")


## The command for KIND ("check" or "play"), or a sentence saying what is missing.
## The command for KIND ("check", "check-map" or "play"), or a sentence saying what is missing.
static func command_for(kind: String, level: Dictionary) -> Variant:
var python: String = user_arg("--openrac-python")
var tools: String = user_arg("--openrac-tools")
Expand Down Expand Up @@ -170,24 +178,56 @@ func start() -> void:
worker.start(run.bind(command))


## Saves, then runs check-map --fix on this level in the background; the scene is read again after.
func fix() -> void:
if worker != null and worker.is_started():
return

var command: Variant = command_for("check-map", this_level())

if command is String:
show_result(1, PackedStringArray([command]))
return

var args: PackedStringArray = command["args"]
args.append("--fix")
command["args"] = args
EditorInterface.save_all_scenes()
dialog.hide()
play_button.disabled = true
play_button.text = "Fixing"
worker = Thread.new()
worker.start(run.bind(command, true))


## On the worker's thread: runs the command and hands its lines back to the editor's thread.
func run(command: Dictionary) -> void:
func run(command: Dictionary, fixing: bool = false) -> void:
var output: Array = []
var code: int = OS.execute(command["program"], command["args"], output, true)
var lines := PackedStringArray()

for chunk in output:
lines.append_array(String(chunk).split("\n", false))

finish.call_deferred(code, lines)
finish.call_deferred(code, lines, fixing)


func finish(code: int, lines: PackedStringArray) -> void:
func finish(code: int, lines: PackedStringArray, fixing: bool = false) -> void:
worker.wait_to_finish()
worker = null
play_button.disabled = false
play_button.text = "Play Level"

# The fix wrote the level's scene and ground: show them as they are now.
if fixing:
var root: Node = EditorInterface.get_edited_scene_root()

if root != null and not root.scene_file_path.is_empty():
EditorInterface.reload_scene_from_path(root.scene_file_path)

if code != 0:
lines.append("openrac-map-problems")

# The game is up: its window says so, a dialog would only stand in the way.
if code == 0 and lines.has("openrac-started"):
play_button.text = "Game Started"
Expand All @@ -213,7 +253,20 @@ func show_result(code: int, lines: PackedStringArray) -> void:
elif not line.begins_with("openrac-"):
said.append(line)

if problems.item_count > 0:
var map: bool = lines.has("openrac-map-problems")
var fixed := PackedStringArray()

for line in said:
if line.begins_with("fixed: "):
fixed.append(line.trim_prefix("fixed: "))

fix_button.visible = map and fixed.is_empty()

if problems.item_count > 0 and map:
summary.text = ("Fixed: %s.\n" % "; ".join(fixed) if not fixed.is_empty() else "") \
+ "The map has %d problems a player would see. %s Click one to find it." % [problems.item_count,
"These are left for you." if not fixed.is_empty() else "Fix mends what it can."]
elif problems.item_count > 0:
summary.text = "%d edits can't be built. Click one, fix it, then play again." % problems.item_count
elif code == 0:
summary.text = "\n".join(said) if not said.is_empty() else "Done."
Expand Down
Loading
Loading