Skip to content

Commit 0823415

Browse files
authored
Merge pull request #92 from Project-Funk-Engine/Refine_Menus
Refine menus
2 parents c6537e3 + 0209cbb commit 0823415

20 files changed

+472
-92
lines changed

Funk Engine.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</PropertyGroup>
99
<ItemGroup>
1010
<Content Include="Globals\translations.csv" />
11-
<Content Include="SaveData\SaveData.json" />
1211
<PackageReference Include="Melanchall.DryWetMidi" Version="7.2.0" />
1312
</ItemGroup>
1413
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">

Globals/BgAudioPlayer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public partial class BgAudioPlayer : AudioStreamPlayer
77

88
private void PlayMusic(AudioStream music, float volume)
99
{
10+
ProcessMode = ProcessModeEnum.Always;
1011
if (Playing && music.Equals(Stream))
1112
{
1213
return;

Globals/FunkEngineNameSpace.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ private void CreateCommonChildren(int width, int height)
167167
continue;
168168
if (_map[curPos.X, curPos.Y + 1] == 0)
169169
continue;
170-
GD.Print("Added child on same X.");
171170
room.AddChild(_map[curPos.X, curPos.Y + 1]);
172171
}
173172
}

Globals/StageProducer.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ public partial class StageProducer : Node
2525
//TODO: Allow for permanent changes and battle temporary stat changes.
2626
public static PlayerStats PlayerStats;
2727

28+
public override void _EnterTree()
29+
{
30+
InitFromCfg();
31+
}
32+
33+
private void InitFromCfg()
34+
{
35+
OptionsMenu.ChangeVolume(
36+
SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.Volume).As<float>()
37+
);
38+
TranslationServer.SetLocale(
39+
SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.LanguageKey).As<string>()
40+
);
41+
}
42+
2843
public void StartGame()
2944
{
3045
Map.InitMapGrid(MapSize.X, MapSize.Y, 3);
@@ -63,12 +78,6 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
6378
Config = MakeConfig(nextStage, nextRoomIdx);
6479
GetTree().ChangeSceneToFile("res://scenes/BattleDirector/test_battle_scene.tscn");
6580
break;
66-
case Stages.Controls:
67-
GetTree().ChangeSceneToFile("res://scenes/Remapping/Remap.tscn");
68-
break;
69-
case Stages.Options:
70-
GetTree().ChangeSceneToFile("res://scenes/Options/OptionsMenu.tscn");
71-
break;
7281
case Stages.Chest:
7382
Config = MakeConfig(nextStage, nextRoomIdx);
7483
GetTree().ChangeSceneToFile("res://scenes/ChestScene/ChestScene.tscn");
68 Bytes
Binary file not shown.

Globals/translations.csv

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CONTROLS_TITLE_SELECTED,Selected,已选择
1111
CONTROLS_WASD_BUTTON,WASD,WASD
1212
CONTROLS_QWER_BUTTON,QWER,QWER
1313
CONTROLS_ARROW_BUTTON,Arrow Keys,箭头键
14-
CONTROLS_RETURN_BUTTON,Return to Title Screen,返回主菜单
14+
CONTROLS_RETURN_BUTTON,Return,返回
1515
ESCAPE_MENU_RESUME,Resume,继续
1616
ESCAPE_MENU_QUIT,Quit,退出
1717
ESCAPE_MENU_TITLE,Quit to Title,返回标题
@@ -50,3 +50,5 @@ RELIC_COLORBOROS_NAME,Colorboros,彩蛇轮回
5050
RELIC_COLORBOROS_TOOLTIP,"Taste the rainbow. Charges the freestyle bar every riff.","品尝临岛,每次现场充值自由格条"
5151
INVENTORY_TAB_NOTES,Notes,乐谱
5252
INVENTORY_TAB_RELICS,Relics,遗物
53+
OPTIONS_VOLUME_LABEL,Master Volume,最终音量设置
54+
OPTIONS_CONTRAST_LABEL,High Contrast,高对比度模式
52 Bytes
Binary file not shown.

SaveData/SaveData.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

SaveData/SaveSystem.cs

Lines changed: 104 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,127 @@
11
using System.Collections.Generic;
22
using System.IO;
3+
using System.Linq;
34
using System.Text.Json;
45
using Godot;
6+
using FileAccess = Godot.FileAccess;
57

68
// TODO: implement saving
79

810
public static class SaveSystem
911
{
10-
private static string SavePath => "res://SaveData/SaveData.json"; // Update if needed
12+
public static string UserConfigPath = "user://Options.cfg";
13+
private static ConfigFile _curConfigData;
1114

12-
// Loads only the notes section
13-
public static Dictionary<string, int> LoadNotes()
15+
private const float DefaultVolume = 80f;
16+
private const string DefaultInput = "WASD";
17+
private const string DefaultLanguage = "en";
18+
private const bool DefaultHighCon = false;
19+
20+
public enum ConfigSettings
21+
{
22+
Volume,
23+
InputKey,
24+
LanguageKey,
25+
HighContrast,
26+
}
27+
28+
private static void InitConfig()
29+
{
30+
_curConfigData = new ConfigFile();
31+
UpdateConfig(ConfigSettings.Volume, DefaultVolume);
32+
UpdateConfig(ConfigSettings.InputKey, DefaultInput);
33+
UpdateConfig(ConfigSettings.LanguageKey, DefaultLanguage);
34+
UpdateConfig(ConfigSettings.HighContrast, DefaultHighCon);
35+
}
36+
37+
private static void SaveConfig()
38+
{
39+
AssertConfigFile();
40+
_curConfigData.Save(UserConfigPath);
41+
}
42+
43+
public static void UpdateConfig(ConfigSettings setting, Variant value)
1444
{
15-
var saveData = LoadSaveData();
16-
if (saveData != null && saveData.Notes != null)
45+
AssertConfigFile();
46+
switch (setting)
1747
{
18-
return saveData.Notes;
48+
case ConfigSettings.Volume:
49+
_curConfigData.SetValue("Options", "Volume", value);
50+
break;
51+
case ConfigSettings.InputKey:
52+
_curConfigData.SetValue("Options", "InputKey", value);
53+
break;
54+
case ConfigSettings.LanguageKey:
55+
_curConfigData.SetValue("Options", "LanguageKey", value);
56+
break;
57+
case ConfigSettings.HighContrast:
58+
_curConfigData.SetValue("Options", "HighContrast", value);
59+
break;
1960
}
20-
else
61+
SaveConfig();
62+
}
63+
64+
public static void AssertConfigFile()
65+
{
66+
if (_curConfigData == null)
2167
{
22-
return new Dictionary<string, int>();
68+
LoadConfigData();
2369
}
2470
}
2571

2672
// This method loads the entire save data
27-
public static SaveData LoadSaveData()
73+
private static void LoadConfigData()
2874
{
29-
string path = ProjectSettings.GlobalizePath(SavePath);
30-
if (!File.Exists(path))
31-
{
32-
GD.PrintErr("Can't load save game");
33-
return null;
34-
}
75+
_curConfigData = new ConfigFile();
76+
VerifyConfig();
77+
if (_curConfigData.Load(UserConfigPath) == Error.Ok)
78+
return;
79+
GD.Print("No config could be found, creating a new one.");
80+
InitConfig();
81+
SaveConfig();
82+
}
3583

36-
string json = File.ReadAllText(path);
37-
SaveData data = JsonSerializer.Deserialize<SaveData>(json);
38-
return data;
84+
//Really naive approach to verifying config integrity, could I have just changed back to JSON? yes. But I'm a real programmer.
85+
//In theory ConfigFiles should be more stable across any version changes.
86+
private static void VerifyConfig()
87+
{
88+
if (!FileAccess.FileExists(UserConfigPath))
89+
return;
90+
string[] sus = new[]
91+
{
92+
"init",
93+
"object",
94+
"script",
95+
"source",
96+
"extends",
97+
"RefCounted",
98+
"sus",
99+
};
100+
FileAccess file = FileAccess.Open(UserConfigPath, FileAccess.ModeFlags.Read);
101+
if (!sus.Any(s => file.GetAsText().Contains(s)))
102+
return;
103+
file.Close();
104+
InitConfig();
39105
}
40-
}
41106

42-
public class SaveData
43-
{
44-
public string AccountName { get; set; }
45-
public Dictionary<string, int> Notes { get; set; } = new Dictionary<string, int>();
46-
public Dictionary<string, object> Relics { get; set; } = new Dictionary<string, object>();
47-
public Dictionary<string, float> Settings { get; set; } = new Dictionary<string, float>();
107+
public static Variant GetConfigValue(ConfigSettings setting)
108+
{
109+
AssertConfigFile();
110+
switch (setting)
111+
{
112+
case ConfigSettings.Volume:
113+
return _curConfigData.GetValue("Options", "Volume", DefaultVolume);
114+
case ConfigSettings.InputKey:
115+
return _curConfigData.GetValue("Options", "InputKey", DefaultInput);
116+
case ConfigSettings.LanguageKey:
117+
return _curConfigData.GetValue("Options", "LanguageKey", DefaultLanguage);
118+
case ConfigSettings.HighContrast:
119+
return _curConfigData.GetValue("Options", "HighContrast", DefaultHighCon);
120+
default:
121+
GD.PushError(
122+
"SaveSystem.GetConfigValue: Invalid config setting passed. " + setting
123+
);
124+
return float.MinValue;
125+
}
126+
}
48127
}

project.godot

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ run/main_scene="res://scenes/SceneTransitions/TitleScreen.tscn"
1515
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
1616
config/icon="res://scenes/BattleDirector/assets/Character1.png"
1717

18+
[audio]
19+
20+
buses/default_bus_layout=""
21+
1822
[autoload]
1923

24+
StageProducer="*res://Globals/StageProducer.cs"
2025
TimeKeeper="*res://Globals/TimeKeeper.cs"
2126
Scribe="*res://Globals/Scribe.cs"
22-
StageProducer="*res://Globals/StageProducer.cs"
2327
BgAudioPlayer="*res://Globals/BGAudioPlayer.tscn"
2428

2529
[display]
@@ -39,12 +43,45 @@ input_scheme="ARROWS"
3943

4044
[input]
4145

46+
ui_left={
47+
"deadzone": 0.5,
48+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
49+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
50+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
51+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
52+
]
53+
}
54+
ui_right={
55+
"deadzone": 0.5,
56+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
57+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
58+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
59+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
60+
]
61+
}
62+
ui_up={
63+
"deadzone": 0.5,
64+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
65+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
66+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
67+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
68+
]
69+
}
70+
ui_down={
71+
"deadzone": 0.5,
72+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
73+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
74+
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
75+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
76+
]
77+
}
4278
arrowUp={
4379
"deadzone": 0.5,
4480
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
4581
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
4682
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
4783
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
84+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
4885
]
4986
}
5087
arrowDown={
@@ -53,6 +90,7 @@ arrowDown={
5390
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
5491
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
5592
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
93+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
5694
]
5795
}
5896
arrowLeft={
@@ -61,6 +99,7 @@ arrowLeft={
6199
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
62100
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
63101
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
102+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null)
64103
]
65104
}
66105
arrowRight={
@@ -69,6 +108,7 @@ arrowRight={
69108
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
70109
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null)
71110
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
111+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null)
72112
]
73113
}
74114
Pause={

0 commit comments

Comments
 (0)