aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-27 00:55:20 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-27 00:55:23 +0200
commit9a5eb8ddf73fecc0ef5907983e136a1018937621 (patch)
tree3c692f6e7702c59abffa19c7b5c1da868b0f0c7b /client
parent2ff484a85dec4abed71071ba509ac5cd307ff2f9 (diff)
downloadhurrycurry-9a5eb8ddf73fecc0ef5907983e136a1018937621.tar
hurrycurry-9a5eb8ddf73fecc0ef5907983e136a1018937621.tar.bz2
hurrycurry-9a5eb8ddf73fecc0ef5907983e136a1018937621.tar.zst
Add client cli tool to render tiles/items to PNG
Diffstat (limited to 'client')
-rw-r--r--client/game.gd2
-rw-r--r--client/gui/components/message/item/item_render.gd1
-rw-r--r--client/gui/menus/entry.gd2
-rw-r--r--client/map/items/item.gd8
-rw-r--r--client/system/cli.gd4
-rw-r--r--client/system/render_tool.gd67
-rw-r--r--client/system/render_tool.gd.uid1
-rw-r--r--client/system/render_tool.tscn48
8 files changed, 130 insertions, 3 deletions
diff --git a/client/game.gd b/client/game.gd
index 1a5e8ff6..9117be18 100644
--- a/client/game.gd
+++ b/client/game.gd
@@ -183,6 +183,7 @@ func handle_packet(p):
if "tile" in p.location:
var t: Tile = map.get_tile_instance(p.location.tile)
var i = ItemFactory.produce(item_names[p.item], t.item_base)
+ i.animate_spawn()
i.position = t.item_base.global_position
add_child(i)
i.name = item_names[p.item]
@@ -191,6 +192,7 @@ func handle_packet(p):
var pl: Player = players[p.location.player[0]]
var h = p.location.player[1]
var i = ItemFactory.produce(item_names[p.item], pl.hand_base[h])
+ i.animate_spawn()
i.position = pl.hand_base[h].global_position
add_child(i)
i.name = item_names[p.item]
diff --git a/client/gui/components/message/item/item_render.gd b/client/gui/components/message/item/item_render.gd
index 71a5eb7c..374644c3 100644
--- a/client/gui/components/message/item/item_render.gd
+++ b/client/gui/components/message/item/item_render.gd
@@ -29,6 +29,7 @@ func set_item(item_name: String, enable_rotation := true):
remove_item()
item = ItemFactory.produce(item_name, base)
+ item.animate_spawn()
do_rotate = enable_rotation
base.add_child(item)
diff --git a/client/gui/menus/entry.gd b/client/gui/menus/entry.gd
index 738b3113..4006f00b 100644
--- a/client/gui/menus/entry.gd
+++ b/client/gui/menus/entry.gd
@@ -24,6 +24,8 @@ func _ready():
get_tree().quit()
return
+ if Cli.opts.has("render-items") or Cli.opts.has("render-tiles"):
+ await submenu("res://system/render_tool.tscn")
if Cli.opts.has("connect_address"):
await submenu("res://gui/menus/game.tscn", Cli.opts["connect_address"])
elif not Settings.read("gameplay.setup_completed"):
diff --git a/client/map/items/item.gd b/client/map/items/item.gd
index 92681df0..bf61966f 100644
--- a/client/map/items/item.gd
+++ b/client/map/items/item.gd
@@ -32,7 +32,7 @@ var progress_position := 0.
var progress_warn := false
var destroy_timeout = null
-var creation_timer = 0.0
+var creation_timer = null
var item_owned = false
var player_owned_timer = 0.0
@@ -52,8 +52,10 @@ func _init(owned_by_: Node3D):
base.name = "Base"
add_child(base)
owned_by = owned_by_
- if not owned_by.get_parent() is Item and not owned_by is Item:
- scale = Vector3.ONE * 0.001 # setting to zero breaks assertions somewhere in the engine
+
+func animate_spawn():
+ creation_timer = 0.0
+ scale = Vector3.ONE * 0.001 # setting to zero breaks assertions somewhere in the engine
func _process(delta):
if not is_instance_valid(owned_by): return
diff --git a/client/system/cli.gd b/client/system/cli.gd
index 7a312127..d503d536 100644
--- a/client/system/cli.gd
+++ b/client/system/cli.gd
@@ -29,6 +29,10 @@ static var OPTIONS := [
Option.new("h", "help", Mode.FLAG, "Show help"),
Option.new("s", "setting", Mode.MULTI_OPTION, "Per-launch setting override"),
Option.new("c", "join-command", Mode.OPTION, "Message to send right after initial joining"),
+ Option.new(null, "render-items", Mode.OPTION, "Render items from text file to images"),
+ Option.new(null, "render-tiles", Mode.OPTION, "Render tiles from text file to images"),
+ Option.new(null, "render-resolution", Mode.OPTION, "Resolution for rendering items or tiles"),
+ Option.new(null, "render-output", Mode.OPTION, "Output directory for rendering items or tiles"),
Option.new(null, "connect_address", Mode.POSITIONAL, "Connect to a server directly without menu interaction")
]
diff --git a/client/system/render_tool.gd b/client/system/render_tool.gd
new file mode 100644
index 00000000..3037f9bb
--- /dev/null
+++ b/client/system/render_tool.gd
@@ -0,0 +1,67 @@
+# 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/>.
+#
+extends Menu
+
+enum Mode {
+ ITEMS,
+ TILES
+}
+
+@onready var camera = $SubViewportContainer/SubViewport/Node3D/Camera3D
+@onready var base = $SubViewportContainer/SubViewport/Node3D
+
+var current_object: Node3D = null
+var mode: Mode
+
+func _ready():
+ super()
+
+ var input_file: String
+ if Cli.opts.has("render-items"):
+ mode = Mode.ITEMS
+ input_file = Cli.opts["render-items"]
+ elif Cli.opts.has("render-tiles"):
+ mode = Mode.TILES
+ input_file = Cli.opts["render-tiles"]
+ else:
+ push_error("cannot open render_tool menu without corresponding cli options")
+ return
+
+ var file = FileAccess.open(input_file, FileAccess.READ)
+ var object_name_list = file.get_as_text().strip_edges().split("\n")
+ var resolution = Vector2i.ONE * int(Cli.opts.get("render-resolution", "256"))
+ $SubViewportContainer/SubViewport.size = resolution
+
+ for object_name in object_name_list:
+ setup_object(object_name)
+ await RenderingServer.frame_post_draw
+ var path = Cli.opts.get("render-output", ".").path_join(object_name + ".png")
+ $SubViewportContainer/SubViewport.get_texture().get_image().save_png(path)
+
+ exit()
+
+func setup_object(object_name: String):
+ if current_object: base.remove_child(current_object)
+ match mode:
+ Mode.ITEMS:
+ current_object = ItemFactory.produce(object_name, base)
+ Mode.TILES:
+ var tf = TileFactory.new()
+ current_object = tf.produce(object_name, Vector2i(0, 0), [null, null, null, null])
+ current_object.rotation_degrees.y = 45.
+ current_object.translate(Vector3(-0.5, 0.0, -0.5))
+ camera.size = 2.
+ base.add_child(current_object)
diff --git a/client/system/render_tool.gd.uid b/client/system/render_tool.gd.uid
new file mode 100644
index 00000000..daf5d5b8
--- /dev/null
+++ b/client/system/render_tool.gd.uid
@@ -0,0 +1 @@
+uid://byw3ney1w3bww
diff --git a/client/system/render_tool.tscn b/client/system/render_tool.tscn
new file mode 100644
index 00000000..5a1a208f
--- /dev/null
+++ b/client/system/render_tool.tscn
@@ -0,0 +1,48 @@
+[gd_scene load_steps=4 format=3 uid="uid://xppn2tnr0hcx"]
+
+[ext_resource type="Script" uid="uid://byw3ney1w3bww" path="res://system/render_tool.gd" id="1_gmn7h"]
+
+[sub_resource type="BoxMesh" id="BoxMesh_pcjn7"]
+
+[sub_resource type="Environment" id="Environment_vdkpo"]
+background_mode = 1
+background_color = Color(0, 0, 0, 0)
+ambient_light_source = 2
+ambient_light_color = Color(1, 1, 1, 1)
+
+[node name="ItemExport" type="Control"]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+script = ExtResource("1_gmn7h")
+
+[node name="SubViewportContainer" type="SubViewportContainer" parent="."]
+layout_mode = 0
+offset_right = 512.0
+offset_bottom = 512.0
+
+[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"]
+transparent_bg = true
+handle_input_locally = false
+render_target_update_mode = 4
+
+[node name="Node3D" type="Node3D" parent="SubViewportContainer/SubViewport"]
+
+[node name="DebugPlaceholder" type="MeshInstance3D" parent="SubViewportContainer/SubViewport/Node3D"]
+visible = false
+mesh = SubResource("BoxMesh_pcjn7")
+skeleton = NodePath("../../../..")
+
+[node name="WorldEnvironment" type="WorldEnvironment" parent="SubViewportContainer/SubViewport/Node3D"]
+environment = SubResource("Environment_vdkpo")
+
+[node name="Camera3D" type="Camera3D" parent="SubViewportContainer/SubViewport/Node3D"]
+transform = Transform3D(1, 0, 0, 0, 0.8660254, 0.5, 0, -0.5, 0.8660254, 0, 2, 3)
+projection = 1
+far = 30.0
+
+[node name="DirectionalLight3D" type="DirectionalLight3D" parent="SubViewportContainer/SubViewport/Node3D"]
+transform = Transform3D(0.7071067, 0.49999997, -0.4999999, 0, 0.70710677, 0.7071067, 0.7071067, -0.49999997, 0.4999999, 0, 0, 0)