aboutsummaryrefslogtreecommitdiff
path: root/client/system/render_tool.gd
blob: 825f25bb5084f2742950451b90f9fb15c17e7efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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), ["counter", "floor", "counter", 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)