J1: the cliff tunnel (seam, six propped stretches, dark, lights), travel Valley <-> Cove through the sea cave, a save file per worldlet; New World has no Where (--dev-worldlets to try others)

This commit is contained in:
Paul Bailey
2026-11-06 17:51:58 +00:00
parent 793b214786
commit 980ee53579
22 changed files with 1181 additions and 33 deletions

View File

@@ -257,6 +257,14 @@ func harvest_hit(player: Node3D, node: Node3D, hit_point: Vector3) -> bool:
return false
var held: Dictionary = ItemDB.get_item(player.held_item_id())
var tool: Dictionary = held.get("tool", {})
if node.has_method("refusal"): # (the cliff tunnel's faces: their own rules first)
var why: String = node.refusal()
if not why.is_empty():
notify.emit(why)
return false
if tool.get("kind", "") == node.tool_kind and int(tool.get("tier", 0)) < node.min_tier:
notify.emit("Too hard: you need a better pick")
return false
if tool.get("kind", "") != node.tool_kind or int(tool.get("tier", 0)) < node.min_tier:
notify.emit("Needs a %s (Tab to craft)" % ItemDB.item_name("stone_" + node.tool_kind))
return false

View File

@@ -60,6 +60,7 @@ func create_world(world_name: String, seed: int, options: Dictionary = {}) -> St
}
for k in options:
meta[k] = options[k]
meta["home"] = String(meta.worldlet)
_write_json(_dir(id).path_join("meta.json"), meta)
return id
@@ -84,6 +85,8 @@ func delete_world(id: String) -> void:
var d := DirAccess.open(dir)
if d == null:
return
for sub in d.get_directories(): # (worldlets/, and a server's backups/)
_remove_tree(dir.path_join(sub))
for f in d.get_files():
d.remove(f)
DirAccess.remove_absolute(dir)
@@ -93,16 +96,64 @@ func delete_world(id: String) -> void:
func read_meta(id: String) -> Dictionary:
return _read_json(_dir(id).path_join("meta.json"))
func load_state(id: String) -> Dictionary:
var s := _read_json(_dir(id).path_join("world.json"))
if s.is_empty() and FileAccess.file_exists(_dir(id).path_join("world.json.bak")):
push_warning("Saves: world.json unreadable, using backup")
s = _read_json(_dir(id).path_join("world.json.bak"))
# --- worldlets in one world (J1, docs/WORLDLETS_DESIGN.md §10) --------------------
# A world can span several worldlets (the journey). Each keeps its own state
# file: the one it began in (its "home") is world.json, as before, so older
# saves are unchanged; the others are worldlets/<id>.json. meta.json's
# "worldlet" is where you are now, so that's the one loaded.
## The worldlet world `id` is being played in now.
func worldlet_of(id: String) -> String:
return String(read_meta(id).get("worldlet", "valley"))
## The worldlet world `id` began in (its world.json).
func home_of(id: String) -> String:
var m := read_meta(id)
return String(m.get("home", m.get("worldlet", "valley")))
## The state file for worldlet `w` of world `id`.
func state_path(id: String, w: String) -> String:
if w == home_of(id):
return _dir(id).path_join("world.json")
return _dir(id).path_join("worldlets/%s.json" % w)
## Whether world `id` has been to worldlet `w` (has a state for it).
func has_state(id: String, w: String) -> bool:
return FileAccess.file_exists(state_path(id, w))
## Moves world `id` to worldlet `to` (the next load is there), arriving at
## `arrive` (a place the arriving world puts you: "sea_cave", "tunnel_bottom").
func set_worldlet(id: String, to: String, arrive: String) -> void:
var m := read_meta(id)
if not m.has("home"):
m["home"] = String(m.get("worldlet", "valley")) # (pin it before "worldlet" moves)
m["worldlet"] = to
m["arrive"] = arrive
_write_json(_dir(id).path_join("meta.json"), m)
## Where the next load should put you, once (then forgotten).
func take_arrival(id: String) -> String:
var m := read_meta(id)
var a := String(m.get("arrive", ""))
if not a.is_empty():
m.erase("arrive")
_write_json(_dir(id).path_join("meta.json"), m)
return a
## The state of the worldlet being played (or of worldlet `w`).
func load_state(id: String, w: String = "") -> Dictionary:
var path := state_path(id, worldlet_of(id) if w.is_empty() else w)
var s := _read_json(path)
if s.is_empty() and FileAccess.file_exists(path + ".bak"):
push_warning("Saves: %s unreadable, using backup" % path.get_file())
s = _read_json(path + ".bak")
return s
## Writes the state for `id` and updates its meta. Returns true on success.
func save_state(id: String, state: Dictionary, session_seconds: float) -> bool:
var path := _dir(id).path_join("world.json")
## Writes the state for `id` (the worldlet being played, or `w`) and
## updates its meta. Returns true on success.
func save_state(id: String, state: Dictionary, session_seconds: float, w: String = "") -> bool:
var path := state_path(id, worldlet_of(id) if w.is_empty() else w)
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
if FileAccess.file_exists(path):
DirAccess.copy_absolute(path, path + ".bak")
state["version"] = VERSION
@@ -129,3 +180,10 @@ func _read_json(path: String) -> Dictionary:
return {}
var data = JSON.parse_string(FileAccess.get_file_as_string(path))
return data if typeof(data) == TYPE_DICTIONARY else {}
static func _remove_tree(d: String) -> void:
for sub in DirAccess.get_directories_at(d):
_remove_tree(d.path_join(sub))
for f in DirAccess.get_files_at(d):
DirAccess.remove_absolute(d.path_join(f))
DirAccess.remove_absolute(d)