diff options
| author | tpart <tpart120@proton.me> | 2025-10-11 16:47:42 +0200 |
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2025-10-11 16:47:42 +0200 |
| commit | 7fc7f5e9c1b9aa7230186adc2f1fc0e9f4bfc1bb (patch) | |
| tree | 0a954549e345513ecf286fb6487894518a8b3e38 /client | |
| parent | 41c893d268b7cbb0faeb966dc6c4c801a97a9c51 (diff) | |
| download | hurrycurry-7fc7f5e9c1b9aa7230186adc2f1fc0e9f4bfc1bb.tar hurrycurry-7fc7f5e9c1b9aa7230186adc2f1fc0e9f4bfc1bb.tar.bz2 hurrycurry-7fc7f5e9c1b9aa7230186adc2f1fc0e9f4bfc1bb.tar.zst | |
Refactor background.gd
Diffstat (limited to 'client')
| -rw-r--r-- | client/gui/menus/main/background.gd | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/client/gui/menus/main/background.gd b/client/gui/menus/main/background.gd index 85ac258f..e2a0d3be 100644 --- a/client/gui/menus/main/background.gd +++ b/client/gui/menus/main/background.gd @@ -15,9 +15,9 @@ # extends Node3D -const CRATES = ["tomato-crate", "bun-crate", "steak-crate", "cheese-crate", "lettuce-crate", "flour-crate", "coconut-crate"] +const CRATES = ["tomato-crate", "bun-crate", "steak-crate", "cheese-crate", "lettuce-crate", "mushroom-crate"] const TOOLS = ["stove", "stove", "stove", "sink", "cutting-board", "sink", "cutting-board", "rolling-board", "oven", "freezer", "deep-fryer", "rolling-board"] -const ITEMS = ["pot", "pan", "foodprocessor", "plate", "basket", "lettuce", "dirty-plate", "cheese", "nigiri"] +const ITEMS = ["pot", "pan", "foodprocessor", "plate", "basket", "lettuce", "dirty-plate", "cheese"] @onready var environment: WorldEnvironment = $Environment @onready var map: Map = $Map @@ -26,29 +26,29 @@ func _ready(): if !Global.on_vulkan(): environment.environment.tonemap_exposure = 0.25 - var tiles = {} + var tiles: Dictionary[Vector2i, Variant] = {} # : Dictionary[Vector2i, String?] var item_counters := [] for x in range(-10, 11): for y in range(-10, 11): - var w = exp(-sqrt(x * x + y * y) * 0.15) + var w = exp(-Vector2(x, y).length() * 0.15) var k = randf() * w - var tn = null - if k > 0.25: tn = "floor" - if k > 0.4: tn = choose(CRATES) if randf() > 0.3 else "counter" - if k > 0.6: tn = choose(TOOLS) - if k > 0.7: tn = "tree" if randf() > 0.4 else "grass" - if tn != null: - tiles[str(Vector2i(x,y))] = [tn,[x,y]] - if tn == "counter" and randf() > 0.1 and k > 0.45: + var tile = null # : String? + if k > 0.25: tile = "floor" + if k > 0.4: tile = choose(CRATES) if randf() > 0.7 else "counter" + if k > 0.6: tile = choose(TOOLS) + if tile != null: + tiles[Vector2i(x,y)] = tile + if tile == "counter" and randf() > 0.5 and w > 0.45: item_counters.push_back(Vector2i(x, y)) - var gt = func (cs): - var t = tiles.get(str(Vector2i(cs[0],cs[1]))) - return null if t == null else t[0] - for pk in tiles.keys(): - var x = tiles[pk][1][0] - var y = tiles[pk][1][1] - var t = gt.call([x,y]) - if t != null: map.set_tile(Vector2i(x,y), t, [[x,y-1],[x-1,y],[x,y+1],[x+1,y]].map(gt)) + var get_tile := func (cs: Vector2i): + return tiles.get(cs) + for tile_pos: Vector2i in tiles.keys(): + var x := tile_pos.x + var y := tile_pos.y + var tile = get_tile.call(tile_pos) + if tile != null: + map.set_tile(Vector2i(x,y), tile, + [Vector2i(x,y-1),Vector2i(x-1,y),Vector2i(x,y+1),Vector2i(x+1,y)].map(get_tile)) map.flush() @@ -61,4 +61,5 @@ func _ready(): item.rotation.y = rot item.rotation_target = rot t.set_item(item) + func choose(a): return a[floor(a.size() * randf())] |