From 645b252da9151a14d4a893c5107b6117df650b39 Mon Sep 17 00:00:00 2001 From: Jonathan Herrewijnen Date: Thu, 13 Oct 2022 17:09:42 +0200 Subject: [PATCH] Adding global variables --- Global.gd | 8 ++++++++ Global_InGame.gd | 10 ++++------ MiscCodes/KinematicBody2D.gd | 6 +----- MiscCodes/Menu.gd | 9 --------- MiscScenes/GameVariables.tscn | 9 +++++++++ MiscScenes/Sound.tscn | 1 - Other/base_tilemap/init.gd | 11 ++--------- default_bus_layout.tres | 10 ++++++++++ 8 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 MiscScenes/GameVariables.tscn create mode 100644 default_bus_layout.tres diff --git a/Global.gd b/Global.gd index 66ef303..ac2586a 100644 --- a/Global.gd +++ b/Global.gd @@ -11,6 +11,14 @@ var dev_stats = true var dbname = "storage.db" var mainscene = "" var base_tilemap = preload("res://Other/base_tilemap/base_tilemap.tscn") +var map_name + +func load_scene(map_data): + map_name = map_data + var scene = load(map_data+".tscn") + print("MAP NAME ",map_data+".tscn") + var map = scene.instance() + return map func AddInventoryItem(itemid, amount): for x in range(40): diff --git a/Global_InGame.gd b/Global_InGame.gd index dc4a4a9..74f1521 100644 --- a/Global_InGame.gd +++ b/Global_InGame.gd @@ -1,5 +1,5 @@ extends Node2D -#Global functions for the game, like speech bubbles and sounds +const gamevariables = "res://MiscScenes/GameVariables.tscn" func RenderSpeech(load_on, text): var speech = preload("res://MiscScenes/Speech.tscn").instance() @@ -8,9 +8,7 @@ func RenderSpeech(load_on, text): load_on.add_child(speech) func SoundOnInteraction(load_on, sound_name): - var audio = preload("res://MiscScenes/Sound.tscn").instance() - var format_string = "res://Sounds/%s.wav" - var actual_string = format_string % sound_name - var Sound = load(actual_string) - audio.stream = Sound + var audio = preload(gamevariables).instance().get_node("Sound") + audio.stream = load("res://Sounds/%s.wav" % sound_name) load_on.add_child(audio) + Global.Log("Sound playing "+sound_name, 1) diff --git a/MiscCodes/KinematicBody2D.gd b/MiscCodes/KinematicBody2D.gd index c169754..bddf64e 100644 --- a/MiscCodes/KinematicBody2D.gd +++ b/MiscCodes/KinematicBody2D.gd @@ -55,11 +55,6 @@ func InteractWithCell(): print("plant cell mouse line 1: ", interaction_map.get_cell(12, 36)) print('plant_cell_mouse=',plant_cell_mouse,' | plant_cell_character=', plant_cell_character,' | background_cell=', background_cell,' | interaction_cell=',interaction_cell) GlobalGameFunctions.SoundOnInteraction(self, "standard") - for i in 150: - for j in 150: - if interaction_map.get_cell(int(i),int(j)) != -1: - print(interaction_map.get_cell(int(i),int(j))) - print(i, j) if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0: Global.AddInventoryItem(plant_cell_mouse/2, 1) @@ -84,3 +79,4 @@ func AnimationOnInteraction(Item): func _ready(): Global.player_inventory_items = Database.GetInventoryItems().duplicate() + print("Map = ", Global.map_name) diff --git a/MiscCodes/Menu.gd b/MiscCodes/Menu.gd index d3f002e..00d16d9 100644 --- a/MiscCodes/Menu.gd +++ b/MiscCodes/Menu.gd @@ -6,15 +6,6 @@ func _ready(): func _on_Btn_PlayGame_pressed(): Global.LoadSave() Global.GoToScene("res://Other/base_tilemap/base_tilemap.tscn") #Hier kan eventueel de mapnaam van de database ingevoerd worden! -# -# -# #save this scene to global scenes -# Global.AddScene(self, "menu", false) -# -# #set this scene as main -# Global.mainscene = "startmap1" -# Global.AddScene(game, "startmap1", true) -## get_tree().get_root().add_child(game) func _on_Btn_LoadGame_pressed(): Global.GoToScene("loadgame_screen") diff --git a/MiscScenes/GameVariables.tscn b/MiscScenes/GameVariables.tscn new file mode 100644 index 0000000..a4f3b25 --- /dev/null +++ b/MiscScenes/GameVariables.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Sounds/standard.wav" type="AudioStream" id=1] + +[node name="GameVariables" type="Node"] + +[node name="Sound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 1 ) +autoplay = true diff --git a/MiscScenes/Sound.tscn b/MiscScenes/Sound.tscn index be9290b..82dedc0 100644 --- a/MiscScenes/Sound.tscn +++ b/MiscScenes/Sound.tscn @@ -1,4 +1,3 @@ [gd_scene format=2] [node name="Sound" type="AudioStreamPlayer"] -autoplay = true diff --git a/Other/base_tilemap/init.gd b/Other/base_tilemap/init.gd index e27bdd8..3f6903a 100644 --- a/Other/base_tilemap/init.gd +++ b/Other/base_tilemap/init.gd @@ -1,12 +1,5 @@ extends Node2D - -func load_scene(map_data): - var scene = load(map_data+".tscn") - print("MAP NAME ",map_data+".tscn") - var map = scene.instance() - return map func _ready(): - var map = "res://Maps/river_intersection" - self.add_child(load_scene(map)) - + var map_name = "res://Maps/river_intersection" + self.add_child(Global.load_scene(map_name)) diff --git a/default_bus_layout.tres b/default_bus_layout.tres new file mode 100644 index 0000000..bb52f57 --- /dev/null +++ b/default_bus_layout.tres @@ -0,0 +1,10 @@ +[gd_resource type="AudioBusLayout" format=2] + +[resource] +bus/0/solo = true +bus/1/name = "New Bus" +bus/1/solo = false +bus/1/mute = false +bus/1/bypass_fx = false +bus/1/volume_db = 6.02 +bus/1/send = "Master"