diff --git a/export_presets.cfg b/export_presets.cfg index e9cb98d..261ecb8 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -7,7 +7,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="build/ld48-gravity_limbo.html" +export_path="build/html/ld48-gravity_limbo.html" patch_list=PoolStringArray( ) script_export_mode=1 script_encryption_key="" diff --git a/src/GameState.gd b/src/GameState.gd index 5b5c24e..e80ec3a 100644 --- a/src/GameState.gd +++ b/src/GameState.gd @@ -566,7 +566,7 @@ func goto_scene(scene, current = null, free = true): call_deferred("_deferred_goto_scene", scene, current, free) func _deferred_goto_scene(scene, current = null, free = true): - get_tree().get_root().print_tree_pretty() + #get_tree().get_root().print_tree_pretty() if current: if free: current.free() diff --git a/src/ui/Encounter.gd b/src/ui/Encounter.gd index c73aa1a..f885744 100644 --- a/src/ui/Encounter.gd +++ b/src/ui/Encounter.gd @@ -48,7 +48,7 @@ func _on_choice_made(index): var result_indices = self.data["choices"][index]["results"].keys() var result = null var chance = GameState.rng.randi_range(0, 100) - print(chance) + #print(chance) var i = len(result_indices) - 1 while i >= 0: if chance >= result_indices[i]: @@ -56,7 +56,7 @@ func _on_choice_made(index): break else: i -= 1 - print(result) + #print(result) #print(self.data["choices"][index]["results"][result]) var action = self.data["choices"][index]["results"][result] if action.has("stat_changes"): @@ -65,24 +65,23 @@ func _on_choice_made(index): GameState.update_orbit(action["orbit_changes"]) if action.has("crew_changes"): GameState.update_crew(action["crew_changes"]) - print(action) + #print(action) var t = RichTextLabel.new() t.set_use_bbcode(true) var text = self.data["choices"][index]["then"] if action.has("text"): text += "\n\n" + action['text'] if action.has("stat_changes") and action["stat_changes"]: - print("yes") text += "\n\n[center]Effects:[/center]\n" for k in action["stat_changes"].keys(): - print(k) + #print(k) var value = action["stat_changes"][k] var color = "green" if value < 0: color = "red" - print(color) + #print(color) var addition = k + ": [color=" + color + "]" + str(value) + "[/color]\n" - print(addition) + #print(addition) text += addition t.set_bbcode(text) t.set_fit_content_height(true) diff --git a/src/ui/EncounterChoice.gd b/src/ui/EncounterChoice.gd index 2aca674..03d3163 100644 --- a/src/ui/EncounterChoice.gd +++ b/src/ui/EncounterChoice.gd @@ -9,33 +9,44 @@ signal encounter_choice_changed var choices = 3 var level = 0 -var buttonNames = [ - "Option0", - "Option1", - "Option2", -] + # Called when the node enters the scene tree for the first time. func _ready(): # Bind button callbacks - for n in buttonNames: - var button = self.find_node(n) - if button: - button.connect("toggled", self, "_on_option_button_pressed", [n]) + #for n in buttonNames: + # var button = self.find_node(n) + # if button: + # button.connect("toggled", self, "_on_option_button_pressed", [n]) + pass func initialize(l = null, nOptions = null): self.level = l - if nOptions != null: - self.choices = nOptions - var x = 0 - while x < 3: - self.find_node("Option" + str(x)).visible = x < nOptions - x += 1 + print("Intializing choices for level " + str(l) + " with " + str(nOptions) + " options") + if nOptions == null: + nOptions = 3 + self.choices = nOptions + var x = 0 + while x < nOptions: + var s = get_node("Spot" + str(x)) + var n = TextureButton.new() + if s: + n.set_position(s.get_position()) + n.set_name("Option" + str(x)) + n.add_to_group("EncounterOptions") + n.set_toggle_mode(true) + #print("Adding option with name: " + n.get_name()) + n.connect("toggled", self, "_on_option_button_pressed", [n.get_name()]) + n.set_normal_texture(ResourceLoader.load("res://assets/encounterPlaceholder0.png")) + n.set_pressed_texture(ResourceLoader.load("res://assets/encounterIconPlaceholder0_pressed.png")) + add_child(n, true) + print("Adding texture button: Option" + str(x)) + #self.find_node("Option" + str(x)).visible = x < nOptions + x += 1 func activate_options(): - if self.choices > 1: - for c in self.get_children(): - if c.visible: - c.set_disabled(false) + for c in get_my_options(): + if c.visible: + c.set_disabled(false) func active_visited(): var i = self.get_active_option_index() @@ -49,19 +60,28 @@ func active_visited(): return GameState.encounters[self.level][i]['visited'] func disable_options(): - for c in self.get_children(): + for c in get_my_options(): if c.visible: c.set_disabled(true) func get_active_option_index(): var x = 0 - for c in self.get_children(): - if not c.is_visible(): + print("Checking for active index of level " + str(level)) + for c in get_my_options(): + var i = int(c.get_name()[-1]) + if GameState.encounters[self.level][i]['visited']: + print(c.get_name() + " is visited, skipping") x += 1 continue - if c.is_pressed(): + if not c.is_visible(): + print(c.get_name() + " is not visible, skipping") + x += 1 + continue + if c.is_pressed() or GameState.encounters[self.level][i]['selected']: + print(c.get_name() + " is pressed") return x else: + print(c.get_name() + " is not pressed, skipping") x += 1 return null @@ -77,16 +97,28 @@ func get_active_position(): func has_active(): var active = false - for n in buttonNames: - if get_node(n): - active = active or (self.get_node(n).is_pressed() and self.get_node(n).is_visible()) + for n in get_my_options(): + active = active or (n.is_pressed() and n.is_visible()) return active +func get_my_options(): + var n = [] + if not get_tree(): + return n + for o in get_tree().get_nodes_in_group("EncounterOptions"): + if o.get_parent() != self: + continue + n.append(o) + return n + func _on_option_button_pressed(state, buttonName): - for n in buttonNames: - if n != buttonName: - if state and get_node(n): - self.get_node(n).set_pressed(false) + # Map calls this before we have buttons. Or before we exist? + #print(buttonName + " has state: " + str(state)) + for n in get_my_options(): + #print(n.get_name()) + if n.get_name() != buttonName: + if state : + n.set_pressed(false) emit_signal("encounter_choice_changed") #for n in buttonNames: # if self.find_node(n).is_pressed(): diff --git a/src/ui/EncounterChoice.tscn b/src/ui/EncounterChoice.tscn index 602bbdc..a9b2e44 100644 --- a/src/ui/EncounterChoice.tscn +++ b/src/ui/EncounterChoice.tscn @@ -1,52 +1,16 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://src/ui/EncounterChoice.gd" type="Script" id=1] -[ext_resource path="res://assets/encounterPlaceholder2.png" type="Texture" id=2] -[ext_resource path="res://assets/encounterPlaceholder0.png" type="Texture" id=3] -[ext_resource path="res://assets/encounterPlaceholder1.png" type="Texture" id=4] -[ext_resource path="res://assets/encounterIconPlaceholder0_pressed.png" type="Texture" id=5] -[ext_resource path="res://assets/encounterIconPlaceholder1_pressed.png" type="Texture" id=6] -[ext_resource path="res://assets/encounterIconPlaceholder2_pressed.png" type="Texture" id=7] [node name="EncounterChoice" type="Node2D"] position = Vector2( -0.5, 0.5 ) script = ExtResource( 1 ) -[node name="Option0" type="TextureButton" parent="."] -margin_left = -28.8286 -margin_top = 14.3104 -margin_right = 11.1714 -margin_bottom = 54.3104 -hint_tooltip = "Option 0" -toggle_mode = true -texture_normal = ExtResource( 3 ) -texture_pressed = ExtResource( 5 ) -__meta__ = { -"_edit_use_anchors_": false -} +[node name="Spot0" type="Node2D" parent="."] +position = Vector2( 37.0812, -38.6704 ) -[node name="Option1" type="TextureButton" parent="."] -margin_left = 24.2782 -margin_top = 16.5904 -margin_right = 64.2782 -margin_bottom = 56.5904 -hint_tooltip = "Option 1" -toggle_mode = true -texture_normal = ExtResource( 4 ) -texture_pressed = ExtResource( 6 ) -__meta__ = { -"_edit_use_anchors_": false -} +[node name="Spot1" type="Node2D" parent="."] +position = Vector2( 31.7839, 10.5946 ) -[node name="Option2" type="TextureButton" parent="."] -margin_left = 17.7514 -margin_top = -36.9294 -margin_right = 57.7514 -margin_bottom = 3.07064 -hint_tooltip = "Option 2" -toggle_mode = true -texture_normal = ExtResource( 2 ) -texture_pressed = ExtResource( 7 ) -__meta__ = { -"_edit_use_anchors_": false -} +[node name="Spot2" type="Node2D" parent="."] +position = Vector2( -15.3622, 38.1406 ) diff --git a/src/ui/Encounters.gd b/src/ui/Encounters.gd index 5dc3304..a93ec56 100644 --- a/src/ui/Encounters.gd +++ b/src/ui/Encounters.gd @@ -30,11 +30,17 @@ func _on_ship_arrived(): # if GameState.current_state != 5 and GameState.current_state != 8: return + # Work around a duplicate event bug + if GameState.current_state == 8 and self.direction == 1: + return var index = get_node("Map/Level" + str(GameState.current_depth)).get_active_option_index() + if index == null: + var n = get_node("Map/Level" + str(GameState.current_depth)) + print(GameState.encounters[GameState.current_depth]) + print("Got index for level " + str(GameState.current_depth) + ": " + str(index)) GameState.encounters[GameState.current_depth][index]['visited'] = true get_node("Map").draw_course() var e = GameState.encounters[GameState.current_depth] - print(e[index]) var instance = GameState.generate_encounter_instance(e, GameState.current_depth, index) instance.add_to_group("Encounters") self.add_child(instance) diff --git a/src/ui/Map.gd b/src/ui/Map.gd index fdb800b..410ef37 100644 --- a/src/ui/Map.gd +++ b/src/ui/Map.gd @@ -22,7 +22,7 @@ func _ready(): self.get_node("Planet").set_texture(ResourceLoader.load(GameState.get_difficulty_data("planet"))) var encounterChoice = ResourceLoader.load("res://src/ui/EncounterChoice.tscn") for level in GameState.encounters.keys(): - print(level) + #print(level) var name = "Level" + str(level) var choice = encounterChoice.instance() choice.set_name(name) @@ -33,14 +33,15 @@ func _ready(): var x = 0 while x < len(GameState.encounters[level]): # Fixes the rotation of the individual buttons - var n = choice.find_node("Option" + str(x)) + var n = choice.get_node("Option" + str(x)) if not n: + x += 1 continue n.set_rotation( -(find_node("Level" + str(level) + "Location").get_global_rotation()) ) # Set icon and tooltip - print("Checking for icons related to '" + GameState.encounters[level][x]["type"] + "'") + #print("Checking for icons related to '" + GameState.encounters[level][x]["type"] + "'") var texture = ResourceLoader.load("res://assets/encounterIcon" + GameState.encounters[level][x]["type"] + ".png") var texture_pressed = ResourceLoader.load("res://assets/encounterIcon" + GameState.encounters[level][x]["type"] + "_pressed.png") if texture: @@ -52,7 +53,7 @@ func _ready(): if GameState.encounters[level][x]["selected"] or (x == 0 and started_ourselves): # The texture change is used since when disabled the normal_texture is shown regardless of press state. n.set_pressed(true) - choice._on_option_button_pressed(true, "Option" + str(x)) + #choice._on_option_button_pressed(true, "Option" + str(x)) #n.set_normal_texture(n.get_pressed_texture()) if GameState.encounters[level][x]["visited"]: n.set_visible(false) @@ -88,7 +89,7 @@ func _on_encounter_choice_changed(): func draw_course(): # A bit brutal for p in get_tree().get_nodes_in_group("Course"): - print(p.get_name()) + #print(p.get_name()) p.set_visible(false) p.call_deferred("free") @@ -97,18 +98,21 @@ func draw_course(): while x < (len(GameState.encounters) - 1): pairs.append([x, x+1]) x += 1 - print(pairs) + #print(pairs) for p in pairs: var first = get_node("Level" + str(p[0])) var second = get_node("Level" + str(p[1])) if not first or not second: - print("One is null: " + str(p)) + #print("One is null: " + str(p)) continue - if not first.has_active() or not second.has_active(): - print("One has no active: " + str(p)) - continue - if second.active_visited(): - print("Second has a visited active choice: " + str(p)) + #if not first.has_active() or not second.has_active(): + # print("One has no active: " + str(p)) + # continue + #if second.active_visited(): + # print("Second has a visited active choice: " + str(p)) + # continue + if not first.get_active_position() or not second.get_active_position(): + #print("One has no posiion: " + str(p)) continue var l = Line2D.new() l.add_point(first.get_active_position()) diff --git a/src/ui/Map.tscn b/src/ui/Map.tscn index e5ecace..301a6f9 100644 --- a/src/ui/Map.tscn +++ b/src/ui/Map.tscn @@ -42,7 +42,7 @@ rotation = 2.79253 scale = Vector2( 1.05, 1.05 ) [node name="Level5Location" type="Node2D" parent="."] -position = Vector2( 506.488, 220.486 ) +position = Vector2( 462.041, 252.234 ) [node name="Ship" type="Sprite" parent="."] position = Vector2( 1.5874, 3.96851 )