diff options
| author | tpart <tpart120@proton.me> | 2026-03-01 21:14:11 +0100 |
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2026-03-01 21:14:11 +0100 |
| commit | 4e17ada3d54352fcfd013b6bdb6e92950d802135 (patch) | |
| tree | 4873874442b1462b12b1e4445595e5cbb2b61186 | |
| parent | 453684af1095c1fd90aaa56c069184b921c02448 (diff) | |
| download | hurrycurry-4e17ada3d54352fcfd013b6bdb6e92950d802135.tar hurrycurry-4e17ada3d54352fcfd013b6bdb6e92950d802135.tar.bz2 hurrycurry-4e17ada3d54352fcfd013b6bdb6e92950d802135.tar.zst | |
Add weighted tools function in main menu background; Fix #561
| -rw-r--r-- | client/gui/menus/main/background.gd | 23 | ||||
| -rw-r--r-- | client/map/tile_factory.gd | 2 | ||||
| -rw-r--r-- | client/map/tiles/deep_fryer.gd | 30 | ||||
| -rw-r--r-- | client/map/tiles/deep_fryer.gd.uid | 1 |
4 files changed, 22 insertions, 34 deletions
diff --git a/client/gui/menus/main/background.gd b/client/gui/menus/main/background.gd index 7a2adef4..f4a66c93 100644 --- a/client/gui/menus/main/background.gd +++ b/client/gui/menus/main/background.gd @@ -16,7 +16,15 @@ extends Node3D 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 TOOLS_WEIGHTED: Dictionary[Array, float] = { + ["stove"]: 3, + ["counter", "sink"]: 2, + ["counter", "cutting-board"]: 2, + ["counter", "rolling-board"]: 2, + ["oven"]: 1, + ["freezer"]: 1, + ["counter", "deep-fryer"]: 1 +} const ITEMS = ["pot", "pan", "foodprocessor", "plate", "basket", "lettuce", "dirty-plate", "cheese"] @onready var environment: WorldEnvironment = $Environment @@ -35,7 +43,7 @@ func _ready(): var tiles: Array = [] if k > 0.25: tiles = ["floor"] if k > 0.4: tiles = ["floor"] + [choose(CRATES)] if randf() > 0.7 else ["floor", "counter"] - if k > 0.6: tiles = ["floor"] + [choose(TOOLS)] + if k > 0.6: tiles = ["floor"] + choose_weighted(TOOLS_WEIGHTED) if not tiles.is_empty(): tiles_dict[Vector2i(x,y)] = tiles if tiles.has("counter") and randf() > 0.5 and w > 0.45: @@ -54,3 +62,14 @@ func _ready(): t.set_item(item) func choose(a): return a[floor(a.size() * randf())] + +func choose_weighted(weighted_options: Dictionary[Array, float]): # -> Array? + var weight_sum := 0. + var areas: Dictionary[float, Array] = {} + for k in weighted_options: + weight_sum += weighted_options[k] + areas[weight_sum] = k + var selection = randf() * weight_sum + for k in areas: + if k >= selection: + return areas[k] diff --git a/client/map/tile_factory.gd b/client/map/tile_factory.gd index dc108392..ce239f4c 100644 --- a/client/map/tile_factory.gd +++ b/client/map/tile_factory.gd @@ -72,7 +72,7 @@ func produce(raw_name: String, position: Vector2i, neighbors: Array) -> Tile: "path": return Path.new(ctx) "rolling-board": return RollingBoard.new(ctx) "screen": return Screen.new(ctx) - "deep-fryer": return DeepFryer.new(ctx) + "deep-fryer": return GenericTile.new(ctx, preload("res://map/tiles/deep_fryer.tscn")) "sink": return Sink.new(ctx) "stove": return Stove.new(ctx) "street": return Street.new(ctx) diff --git a/client/map/tiles/deep_fryer.gd b/client/map/tiles/deep_fryer.gd deleted file mode 100644 index 229028e7..00000000 --- a/client/map/tiles/deep_fryer.gd +++ /dev/null @@ -1,30 +0,0 @@ -# Hurry Curry! - a game about cooking -# Copyright (C) 2025 Hurry Curry! contributors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, version 3 of the License only. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. -# -class_name DeepFryer -extends CounterBase - -var deep_fryer = preload("res://map/tiles/deep_fryer.tscn") - -func _init(ctx: TileFactory.TileCC): - super(ctx, deep_fryer) - -func set_item(i: Item): - super(i) - if i != null: - i.rotation_target = item_base.global_rotation.y + PI - -static func interact_target() -> Vector3: - return Vector3(0., 0.55, 0.) diff --git a/client/map/tiles/deep_fryer.gd.uid b/client/map/tiles/deep_fryer.gd.uid deleted file mode 100644 index 0fc161a4..00000000 --- a/client/map/tiles/deep_fryer.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://x4gtbub0vfun |