Skip to content

Commit

Permalink
bugfix setting file doesn't get read AND memory leak fix
Browse files Browse the repository at this point in the history
- actually an important patch since the first release the setting file doesn't work at all
- script/unused now getting gitignored
- found memory leak (`push_input` error), fixed with new method of switching scene (very fast timer)
- new option to set volume of audioplayer
- `test_save_feature_on_editor` typo fix
- automatically update config file if a new category (key) is added
- `OS.has_feature("standalone")` changed to `OS.has_feature("template")` (the correct working one)
- main window is minimized now on `no_ending_screen`
- updated export presets with exclusion
- new editorscript `toggleaddons`. This script modifies project.godot, used to disable addons i used locally (discord rpc and script ide) before push the repo. running the script again will enable the addon back. disabled addons are saved in `disabledaddons.cfg`
  • Loading branch information
etherealxx committed Apr 16, 2024
1 parent 990cfc4 commit bcc40be
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 212 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
.godot/
addons/discord-sdk-gd/
scripts/autoloads/discordrpc.gd
test/bsod_by ether.png
addons/script-ide/
shaders/test/
discord_game_sdk_binding.dll
discord_game_sdk.dll
exports/
test/
test/
scripts/unused
8 changes: 8 additions & 0 deletions disabledaddons.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[autoload]

DiscordSDKLoader="*res://addons/discord-sdk-gd/nodes/discord_autoload.gd"
MyDiscordRPC="*res://scripts/autoloads/discordrpc.gd"

[editor_plugins]

enabled=PackedStringArray("res://addons/discord-sdk-gd/plugin.cfg", "res://addons/script-ide/plugin.cfg")
6 changes: 3 additions & 3 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ runnable=true
dedicated_server=false
custom_features=""
export_filter="exclude"
export_files=PackedStringArray("res://addons/discord-sdk-gd/bin/discord-rpc-gd.gdextension", "res://addons/discord-sdk-gd/nodes/assets/Checked.svg", "res://addons/discord-sdk-gd/nodes/assets/circle.svg", "res://addons/discord-sdk-gd/nodes/assets/Unchecked.svg", "res://addons/discord-sdk-gd/nodes/debug.gd", "res://addons/discord-sdk-gd/nodes/Debug.tscn", "res://addons/discord-sdk-gd/nodes/discord_autoload.gd", "res://addons/discord-sdk-gd/Debug.svg", "res://addons/discord-sdk-gd/example.gd", "res://addons/discord-sdk-gd/logo.png", "res://addons/discord-sdk-gd/Logo_V2_No_Bg.png", "res://addons/discord-sdk-gd/plugin.gd", "res://addons/discord-sdk-gd/restart_window.tscn", "res://addons/script-ide/icon/class.svg", "res://addons/script-ide/icon/constant.svg", "res://addons/script-ide/icon/export.svg", "res://addons/script-ide/icon/func.svg", "res://addons/script-ide/icon/func_get.svg", "res://addons/script-ide/icon/func_set.svg", "res://addons/script-ide/icon/keyword.svg", "res://addons/script-ide/icon/property.svg", "res://addons/script-ide/icon/signal.svg", "res://addons/script-ide/plugin.gd", "res://addons/script-ide/Popup.gd", "res://scripts/autoloads/discordrpc.gd", "res://scripts/unused/main_unused.gd", "res://shaders/test/Blur.gdshader", "res://shaders/test/blurtest.gdshader", "res://shaders/test/change2color_backup.gdshader", "res://shaders/test/change2color_greenexample.gdshader", "res://shaders/test/gaussianblur.gdshader", "res://shaders/test/simpleblur.gdshader", "res://test/bsod_by ether.png", "res://test/maintest2.gd", "res://test/maintest3.gd", "res://test/maintest3.tscn", "res://test/node2.gd", "res://test/node2.tscn", "res://test/node.tscn", "res://test/orbitingwindow.gd", "res://test/Sprite2D2.gd", "res://test/Sprite2D.gd", "res://test/testbackground.tscn", "res://test/test_2.tscn")
export_files=PackedStringArray("res://addons/discord-sdk-gd/bin/discord-rpc-gd.gdextension", "res://addons/discord-sdk-gd/nodes/assets/Checked.svg", "res://addons/discord-sdk-gd/nodes/assets/circle.svg", "res://addons/discord-sdk-gd/nodes/assets/Unchecked.svg", "res://addons/discord-sdk-gd/nodes/debug.gd", "res://addons/discord-sdk-gd/nodes/Debug.tscn", "res://addons/discord-sdk-gd/nodes/discord_autoload.gd", "res://addons/discord-sdk-gd/Debug.svg", "res://addons/discord-sdk-gd/example.gd", "res://addons/discord-sdk-gd/logo.png", "res://addons/discord-sdk-gd/Logo_V2_No_Bg.png", "res://addons/discord-sdk-gd/plugin.gd", "res://addons/discord-sdk-gd/restart_window.tscn", "res://addons/script-ide/icon/class.svg", "res://addons/script-ide/icon/constant.svg", "res://addons/script-ide/icon/export.svg", "res://addons/script-ide/icon/func.svg", "res://addons/script-ide/icon/func_get.svg", "res://addons/script-ide/icon/func_set.svg", "res://addons/script-ide/icon/keyword.svg", "res://addons/script-ide/icon/property.svg", "res://addons/script-ide/icon/signal.svg", "res://addons/script-ide/plugin.gd", "res://addons/script-ide/Popup.gd", "res://scripts/autoloads/discordrpc.gd", "res://shaders/test/Blur.gdshader", "res://shaders/test/blurtest.gdshader", "res://shaders/test/change2color_backup.gdshader", "res://shaders/test/change2color_greenexample.gdshader", "res://shaders/test/gaussianblur.gdshader", "res://shaders/test/simpleblur.gdshader", "res://test/bsod_by ether.png", "res://test/maintest2.gd", "res://test/maintest3.gd", "res://test/maintest3.tscn", "res://test/node2.gd", "res://test/node2.tscn", "res://test/node.tscn", "res://test/orbitingwindow.gd", "res://test/Sprite2D2.gd", "res://test/Sprite2D.gd", "res://test/testbackground.tscn", "res://test/test_2.tscn", "res://scripts/editorscript/toggleaddons.gd", "res://exports/unused/main_unused.gd", "res://exports/unused/toggleaddons_old.gd")
include_filter=""
exclude_filter="*.dll"
exclude_filter="*.dll, *.exe, *.zip, *.rar, *.7z, *.pck"
export_path="exports/limbo_keygen.exe"
encryption_include_filters="shaders/*, scripts/*, scenes/*"
encryption_exclude_filters="shaders/test/*, scripts/unused/*, addons/*"
Expand Down Expand Up @@ -40,7 +40,7 @@ application/file_version=""
application/product_version=""
application/company_name="etherealxx"
application/product_name="limbogodot"
application/file_description=""
application/file_description="FOCUS"
application/copyright=""
application/trademarks=""
application/export_angle=0
Expand Down
13 changes: 6 additions & 7 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ config_version=5
[application]

config/name="Keygen"
config/version="1.0.0"
config/description="focus"
config/version="1.1.0"
run/main_scene="res://scenes/main.tscn"
config/use_custom_user_dir=true
config/custom_user_dir_name="limbo-godot"
Expand All @@ -24,11 +25,13 @@ config/icon="res://key.png"
[autoload]

KeyManager="*res://scripts/autoloads/keymanager.gd"
; DiscordSDKLoader="*res://addons/discord-sdk-gd/nodes/discord_autoload.gd"
; MyDiscordRPC="*res://scripts/autoloads/discordrpc.gd"
LimboAudio="*res://scenes/audioplayer.tscn"
VariableKeeper="*res://scripts/autoloads/variablekeeper.gd"

[debug]

file_logging/log_path="user://logs/limbo.log"

[display]

window/size/viewport_width=150
Expand All @@ -37,10 +40,6 @@ window/size/mode=1
window/subwindows/embed_subwindows=false
window/per_pixel_transparency/allowed=true

[editor_plugins]

; enabled=PackedStringArray("res://addons/discord-sdk-gd/plugin.cfg", "res://addons/script-ide/plugin.cfg")

[filesystem]

import/blender/enabled=false
Expand Down
1 change: 1 addition & 0 deletions scenes/audioplayer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
[ext_resource type="Script" path="res://scripts/audioplayer.gd" id="1_iblth"]

[node name="Audioplayer" type="AudioStreamPlayer"]
volume_db = -20.0
script = ExtResource("1_iblth")
5 changes: 5 additions & 0 deletions scenes/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ unresizable = true
always_on_top = true
dialog_text = "You picked the WRONG key!"

[node name="ChangeSceneTimer" type="Timer" parent="."]
wait_time = 0.05
one_shot = true

[connection signal="timeout" from="DebugTimer" to="." method="_on_debug_timer_timeout"]
[connection signal="canceled" from="WinLoseDialog" to="." method="_on_win_lose_dialog_canceled"]
[connection signal="confirmed" from="WinLoseDialog" to="." method="_on_win_lose_dialog_confirmed"]
[connection signal="timeout" from="ChangeSceneTimer" to="." method="_on_change_scene_timer_timeout"]
3 changes: 3 additions & 0 deletions scripts/audioplayer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const limbomusic = preload("res://assets/musics/isolation_keypart_cut.mp3")
const deathsfx = preload("res://assets/sfx/geometry-dash-death-sound-effect.mp3")
const winsfx = preload("res://assets/sfx/level-complete-geometry-dash.mp3")

func set_volume(volume): # volume is between 0 and 20. default is 20
set_volume_db(volume - 20)

func play_music():
if stream == limbomusic:
return
Expand Down
59 changes: 59 additions & 0 deletions scripts/editorscript/toggleaddons.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@tool
extends EditorScript

var mode_disableplugin = false
var projectsettingfile_path = "res://project.godot"
var disabledaddonsfile_path = "res://disabledaddons.cfg"
func config_check_and_remove(config : ConfigFile, disabledconfig : ConfigFile, section, key):
if config.has_section_key(section, key):
disabledconfig.set_value(section, key, config.get_value(section, key))
config.set_value(section, key, null)
mode_disableplugin = true

func get_array_of_comments(projectsettingtext : String) -> Array:
var settingtextarray = projectsettingtext.split("\n")
var projectsettingcomment : Array
for line in settingtextarray:
if line.begins_with(";"):
projectsettingcomment.append(line)
return projectsettingcomment

func open_file_and_get_text(filepath : String) -> String:
var file = FileAccess.open(filepath, FileAccess.READ)
var textfromfile : String = file.get_as_text()
file.close()
return textfromfile

# Called when the script is executed (using File -> Run in Script Editor).
func _run():
var projectsettingtext = open_file_and_get_text(projectsettingfile_path) # res://project.godot # res://project.godot_test.cfg
var projectsettingcomment = get_array_of_comments(projectsettingtext)

var projectconfig = ConfigFile.new()
var disabledconfig = ConfigFile.new()
projectconfig.parse(projectsettingtext)
config_check_and_remove(projectconfig, disabledconfig, "autoload", "DiscordSDKLoader")
config_check_and_remove(projectconfig, disabledconfig, "autoload", "MyDiscordRPC")
config_check_and_remove(projectconfig, disabledconfig, "editor_plugins", "enabled")

var configtext
if mode_disableplugin:
disabledconfig.save(disabledaddonsfile_path)
print("Active addons now deactivated. Please reload the project on Project > Reload Current Project")
else:
projectconfig.load(projectsettingfile_path)
disabledconfig.load(disabledaddonsfile_path)
for section in disabledconfig.get_sections():
for key in disabledconfig.get_section_keys(section):
projectconfig.set_value(section, key, disabledconfig.get_value(section, key))
disabledconfig.set_value(section, key, null)
disabledconfig.save(disabledaddonsfile_path)
print("Inactive addons now reactivated. Please reload the project on Project > Reload Current Project")

configtext = projectconfig.encode_to_text()
var projectsettingfile = FileAccess.open(projectsettingfile_path, FileAccess.WRITE)
for line in projectsettingcomment:
projectsettingfile.store_line(line)
projectsettingfile.store_line("") # extra empty line
projectsettingfile.store_string(configtext)
projectsettingfile.close()
10 changes: 6 additions & 4 deletions scripts/keywindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ func _input(event): # debug
#elif event.is_action_pressed("debugrotate"): # R key
#key.tween_rotate()
if event.is_action_pressed("left_click"):
if clickable:
KeyManager.set_correctkey(correctkey)
mainscene.switch_scene_to_ending()
if clickable:
KeyManager.set_correctkey(correctkey)
#mainscene.switch_scene_to_ending()
mainscene.start_change_scene("ending")
elif event is InputEventMouseButton:
if event.is_double_click() and event.button_index == MOUSE_BUTTON_RIGHT:
mainscene.open_setting_window()
#mainscene.open_setting_window()
mainscene.start_change_scene("setting")

func _on_move_ends():
initialposition = Vector2(-1,-1)
Expand Down
73 changes: 50 additions & 23 deletions scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ extends Node
@export var winning_wait_time := 3.0
## Instantly goes straight to the orbiting key without shuffling
@export var bluescreen_wait_time := 7.0
## Control the volume of the music and sfx. 20 is 0 dB. Decreasing this value will decrease the volume by 1 dB.
@export var music_volume := 20.0
## Instead of going to the ending screen, just bring a popup to determine if you won the game or not
@export var no_ending_screen := false
## Loads settings. Turning this off on the exported build will load the game with default settings
## This does nothing when you run the game from the editor, unless ypu turn on tast_save_feature_on_editor
@export var load_save := true
## This makes the game, when being run on the editor, to loads the save file instead of following the exported variables.
## Turn this on if you want to test the save/load feature, and turn it off if you want to test features from the exported variables.
@export var tast_save_feature_on_editor := false
@export var test_save_feature_on_editor := false

@onready var dialog = $WinLoseDialog

var saved_values = [
"sixteen_by_nine_reso", "fullscreen_ending", "debugdontmove",
"debug_key_mover_window", "instant_finish", "transparent_background",
"winning_wait_time", "bluescreen_wait_time", "no_ending_screen",
"load_save"
"music_volume", "load_save"
]

const windowsize := 150
Expand All @@ -47,6 +49,7 @@ var setting_window_opened := false
var disable_opening_settings := false

var limboendingscene
var nextscene : String

var step_map_x = [ # from markhermy3100's Shuffler.ts -> https://github.com/MarkHermy3100/LimboKeys/blob/main/assets/scripts/Shuffler.ts
[2, 4, 1, 3, 6, 8, 5, 7], # 0: on each 4 block (top and bottom) spin clockwise
Expand Down Expand Up @@ -117,24 +120,29 @@ func config_set_value_from_variable_name(configfile, varname):
configfile.set_value("settings", varname, self.get(varname))

func handle_load_and_save():
var config = ConfigFile.new()

var err = config.load("user://limbosave.cfg")
if err == ERR_FILE_NOT_FOUND:
# make new config file
for varname in saved_values:
var config = ConfigFile.new()

var err = config.load("user://limbosave.cfg")
if err == ERR_FILE_NOT_FOUND:
# make new config file
for varname in saved_values:
config_set_value_from_variable_name(config, varname)
config.save("user://limbosave.cfg")
print("New config file is made.")
elif err == OK:
# still check if there any new values that hasn't been written yet
for varname in saved_values:
if not config.has_section_key("settings", varname):
config_set_value_from_variable_name(config, varname)
config.save("user://limbosave.cfg")
print("New config file is made.")
elif err == OK:
# standalone: exported build. always load save except load_save is off
# OR : testing the save feature via the editor
if OS.has_feature("standalone") or tast_save_feature_on_editor:
if config.get_value("settings", "load_save"):
# load config file
for varname in saved_values:
self.set(varname, config.get_value("settings", varname))
print("Config file loaded.")
config.save("user://limbosave.cfg")
# template: exported build. always load save except load_save is off. used to be "standalone"
# OR : testing the save feature via the editor
if OS.has_feature("template") or test_save_feature_on_editor:
if config.get_value("settings", "load_save"):
# load config file
for varname in saved_values:
self.set(varname, config.get_value("settings", varname))
print("Config file loaded.")

func _ready():
$LimboScenehelp.hide()
Expand All @@ -145,10 +153,11 @@ func _ready():
mainwindow.set_flag(Window.FLAG_BORDERLESS, true)
mainwindow.set_flag(Window.FLAG_TRANSPARENT, true)
KeyManager.get_main()
LimboAudio.play_music()


handle_load_and_save()

LimboAudio.set_volume(music_volume)
LimboAudio.play_music()
if not no_ending_screen:
limboendingscene = load("res://scenes/limbobackground.tscn")

Expand Down Expand Up @@ -265,6 +274,7 @@ func switch_scene_to_ending():
if not no_ending_screen:
get_tree().change_scene_to_packed(limboendingscene)
else:
mainwindow.set_mode(Window.MODE_MINIMIZED)
if KeyManager.correctkeychosen:
dialog.set_text("You picked the CORRECT key!")
LimboAudio.play_sfx(true) # winsfx
Expand Down Expand Up @@ -293,8 +303,16 @@ func open_setting_window():
for varname in saved_values:
config_set_value_from_variable_name(config, varname)
config.save("user://limbosave.cfg")
get_tree().change_scene_to_file("res://scenes/settings_menu.tscn")

if debugmessage: print("insidetree: " + str(is_inside_tree()))
var current_scenetree = get_tree()
if current_scenetree != null:
if debugmessage:
print("current scene: " + str(current_scenetree.get_current_scene().get_name()))
print("moving scene to settingsmenu now")
current_scenetree.change_scene_to_file("res://scenes/settings_menu.tscn")
else:
push_error("current scenetree is null")

func _on_debug_timer_timeout():
if debugmessage: print(KeyManager.movelist_checksize())

Expand All @@ -307,3 +325,12 @@ func _on_win_lose_dialog_confirmed():

func _on_win_lose_dialog_canceled():
get_tree().quit()

func start_change_scene(nextscenestring):
nextscene = nextscenestring
$ChangeSceneTimer.start()

func _on_change_scene_timer_timeout():
match nextscene:
"setting": open_setting_window()
"ending": switch_scene_to_ending()
Loading

0 comments on commit bcc40be

Please sign in to comment.