Fish per water type in data/fish.json; worldlets design
- data/fish.json: fish, weights, dawn/dusk odds, bite timing and minimum depth per water type; ItemDB.define_water() registers them - world.water_at(x, z) answers lake / sea / dry land; the float uses it, so a worldlet with a sea only needs a "sea" entry - Clear messages for shallow water and water with nothing to catch - Lake fish: more of them, bigger, nearer the shore, jumping with splash rings - docs/WORLDLETS_DESIGN.md: proposal for data-defined world types
This commit is contained in:
@@ -14,11 +14,14 @@ const ICON_SIZE := 96
|
||||
var items: Dictionary = {} # id -> definition Dictionary
|
||||
var recipes: Dictionary = {} # id -> recipe Dictionary (insertion order kept)
|
||||
var icons: Dictionary = {} # id -> Texture2D
|
||||
## Fishing by water type (data/fish.json): {"modifiers": {...}, "waters": {type: {...}}}.
|
||||
var fishing: Dictionary = {"modifiers": {}, "waters": {}}
|
||||
var _item_mat: StandardMaterial3D
|
||||
|
||||
func _ready() -> void:
|
||||
_load("res://data/items.json", "items", define_item)
|
||||
_load("res://data/recipes.json", "recipes", define_recipe)
|
||||
_load_fishing("res://data/fish.json")
|
||||
if DisplayServer.get_name() != "headless":
|
||||
_render_icons.call_deferred()
|
||||
|
||||
@@ -51,6 +54,31 @@ func define_recipe(r: Dictionary) -> void:
|
||||
r.station = String(r.get("station", ""))
|
||||
recipes[r.id] = r
|
||||
|
||||
func _load_fishing(path: String) -> void:
|
||||
var data = JSON.parse_string(FileAccess.get_file_as_string(path))
|
||||
if typeof(data) != TYPE_DICTIONARY or not data.has("waters"):
|
||||
push_error("ItemDB: could not parse %s" % path)
|
||||
return
|
||||
fishing.modifiers = data.get("modifiers", {})
|
||||
for water in data.waters:
|
||||
define_water(water, data.waters[water])
|
||||
|
||||
## Registers (or replaces) the fish for one water type. Same shape an addon
|
||||
## would use to add, say, a "swamp" water with its own catch.
|
||||
func define_water(water: String, d: Dictionary) -> void:
|
||||
var fish: Array = []
|
||||
for f in d.get("fish", []):
|
||||
if not items.has(f.get("id", "")):
|
||||
push_error("ItemDB: fish '%s' in water '%s' is not an item" % [f.get("id", "?"), water])
|
||||
continue
|
||||
fish.append({"id": f.id, "weight": float(f.get("weight", 1)), "dawn_dusk": float(f.get("dawn_dusk", f.get("weight", 1)))})
|
||||
var w: Array = d.get("bite_wait", [5.0, 14.0])
|
||||
fishing.waters[water] = {"min_depth": float(d.get("min_depth", 0.5)), "bite_wait": [float(w[0]), float(w[1])], "fish": fish}
|
||||
|
||||
## The fishing table for a water type ({} = nothing to catch there).
|
||||
func water_fishing(water: String) -> Dictionary:
|
||||
return fishing.waters.get(water, {})
|
||||
|
||||
func get_item(id: String) -> Dictionary:
|
||||
return items.get(id, {})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user