/vendor/nlohmann/

om/lingo-randomizer/atom/randomizer/settings_screen.gd?h=rewrite' type='application/atom+xml'/>
summary refs log tree commit diff stats
path: root/randomizer/settings_screen.gd
blob: 708b4ef14f4a13053f2de5c798fb7d720ca6223a (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
extends Spatial


func _ready():
	# Undo the load screen removing our cursor
	get_tree().get_root().set_disable_input(false)
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

	# Create the global Randomizer node, if it doesn't already exist.
	if not global.has_node("Randomizer"):
		var randomizer_script = ResourceLoader.load("user://maps/randomizer/randomizer.gd")
		var randomizer_instance = randomizer_script.new()
		randomizer_instance.name = "Randomizer"
		global.add_child(randomizer_instance)

		randomizer_instance.SCRIPT_generator = load("user://maps/randomizer/generator.gd")

		var generated_puzzles = ResourceLoader.load("user://maps/randomizer/generated_puzzles.gd")
		var generated_puzzles_instance = generated_puzzles.new()
		generated_puzzles_instance.name = "GeneratedPuzzles"
		randomizer_instance.add_child(generated_puzzles_instance)

		# Let's also inject any scripts we need to inject now.
		installScriptExtension(ResourceLoader.load("user://maps/randomizer/load.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelEnd.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelInput.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelLevelSwitch.gd"))
		installScriptExtension(ResourceLoader.load("user://maps/randomizer/worldTransporter.gd"))

	var randomizer = global.get_node("Randomizer")
	randomizer.connect("finished_randomizing", self, "randomizationSuccessful")
	randomizer.connect("randomizer_status", self, "randomizationStatus")

	# Show client version.
	self.get_node("Panel/title").text = "RANDOMIZER (%s)" % randomizer.my_version

	# Increase font size in text boxes.
	var field_font = DynamicFont.new()
	field_font.font_data = load("res://fonts/CutiveMono_Regular.ttf")
	field_font.size = 36

	self.get_node("Panel/seed_box").add_font_override("font", field_font)


# Adapted from https://gitlab.com/Delta-V-Modding/Mods/-/blob/main/game/ModLoader.gd
func installScriptExtension(childScript: Resource):
	# Force Godot to compile the script now.
	# We need to do this here to ensure that the inheritance chain is
	# properly set up, and multiple mods can chain-extend the same
	# class multiple times.
	# This is also needed to make Godot instantiate the extended class
	# when creating singletons.
	# The actual instance is thrown away.
	childScript.new()

	var parentScript = childScript.get_base_script()
	var parentScriptPath = parentScript.resource_path
	global._print("ModLoader: Installing script extension over %s" % parentScriptPath)
	childScript.take_over_path(parentScriptPath)


func randomizationStatus(message):
	var popup = self.get_node("Panel/AcceptDialog")
	popup.window_title = "Randomizing..."
	popup.dialog_text = message
	popup.popup_exclusive = true
	popup.get_ok().visible = false
	popup.popup_centered()


func randomizationSuccessful():
	var randomizer = global.get_node("Randomizer")

	# Switch to LL1
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	global.map = "level1"
	global.save_file = randomizer.getSaveFileName()
	var _discard = get_tree().change_scene("res://scenes/load_screen.tscn")