Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Funk Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>
<ItemGroup>
<Content Include="Globals\translations.csv" />
<Content Include="SaveData\SaveData.json" />
<PackageReference Include="Melanchall.DryWetMidi" Version="7.2.0" />
</ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
Expand Down
1 change: 1 addition & 0 deletions Globals/BgAudioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public partial class BgAudioPlayer : AudioStreamPlayer

private void PlayMusic(AudioStream music, float volume)
{
ProcessMode = ProcessModeEnum.Always;
if (Playing && music.Equals(Stream))
{
return;
Expand Down
1 change: 0 additions & 1 deletion Globals/FunkEngineNameSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ private void CreateCommonChildren(int width, int height)
continue;
if (_map[curPos.X, curPos.Y + 1] == 0)
continue;
GD.Print("Added child on same X.");
room.AddChild(_map[curPos.X, curPos.Y + 1]);
}
}
Expand Down
21 changes: 15 additions & 6 deletions Globals/StageProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ public partial class StageProducer : Node
//TODO: Allow for permanent changes and battle temporary stat changes.
public static PlayerStats PlayerStats;

public override void _EnterTree()
{
InitFromCfg();
}

private void InitFromCfg()
{
OptionsMenu.ChangeVolume(
SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.Volume).As<float>()
);
TranslationServer.SetLocale(
SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.LanguageKey).As<string>()
);
}

public void StartGame()
{
Map.InitMapGrid(MapSize.X, MapSize.Y, 3);
Expand Down Expand Up @@ -63,12 +78,6 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
Config = MakeConfig(nextStage, nextRoomIdx);
GetTree().ChangeSceneToFile("res://scenes/BattleDirector/test_battle_scene.tscn");
break;
case Stages.Controls:
GetTree().ChangeSceneToFile("res://scenes/Remapping/Remap.tscn");
break;
case Stages.Options:
GetTree().ChangeSceneToFile("res://scenes/Options/OptionsMenu.tscn");
break;
case Stages.Chest:
Config = MakeConfig(nextStage, nextRoomIdx);
GetTree().ChangeSceneToFile("res://scenes/ChestScene/ChestScene.tscn");
Expand Down
Binary file modified Globals/translations.cn.translation
Binary file not shown.
4 changes: 3 additions & 1 deletion Globals/translations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CONTROLS_TITLE_SELECTED,Selected,已选择
CONTROLS_WASD_BUTTON,WASD,WASD
CONTROLS_QWER_BUTTON,QWER,QWER
CONTROLS_ARROW_BUTTON,Arrow Keys,箭头键
CONTROLS_RETURN_BUTTON,Return to Title Screen,返回主菜单
CONTROLS_RETURN_BUTTON,Return,返回
ESCAPE_MENU_RESUME,Resume,继续
ESCAPE_MENU_QUIT,Quit,退出
ESCAPE_MENU_TITLE,Quit to Title,返回标题
Expand Down Expand Up @@ -50,3 +50,5 @@ RELIC_COLORBOROS_NAME,Colorboros,彩蛇轮回
RELIC_COLORBOROS_TOOLTIP,"Taste the rainbow. Charges the freestyle bar every riff.","品尝临岛,每次现场充值自由格条"
INVENTORY_TAB_NOTES,Notes,乐谱
INVENTORY_TAB_RELICS,Relics,遗物
OPTIONS_VOLUME_LABEL,Master Volume,最终音量设置
OPTIONS_CONTRAST_LABEL,High Contrast,高对比度模式
Binary file modified Globals/translations.en.translation
Binary file not shown.
9 changes: 0 additions & 9 deletions SaveData/SaveData.json

This file was deleted.

129 changes: 104 additions & 25 deletions SaveData/SaveSystem.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,127 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using Godot;
using FileAccess = Godot.FileAccess;

// TODO: implement saving

public static class SaveSystem
{
private static string SavePath => "res://SaveData/SaveData.json"; // Update if needed
public static string UserConfigPath = "user://Options.cfg";
private static ConfigFile _curConfigData;

// Loads only the notes section
public static Dictionary<string, int> LoadNotes()
private const float DefaultVolume = 80f;
private const string DefaultInput = "WASD";
private const string DefaultLanguage = "en";
private const bool DefaultHighCon = false;

public enum ConfigSettings
{
Volume,
InputKey,
LanguageKey,
HighContrast,
}

private static void InitConfig()
{
_curConfigData = new ConfigFile();
UpdateConfig(ConfigSettings.Volume, DefaultVolume);
UpdateConfig(ConfigSettings.InputKey, DefaultInput);
UpdateConfig(ConfigSettings.LanguageKey, DefaultLanguage);
UpdateConfig(ConfigSettings.HighContrast, DefaultHighCon);
}

private static void SaveConfig()
{
AssertConfigFile();
_curConfigData.Save(UserConfigPath);
}

public static void UpdateConfig(ConfigSettings setting, Variant value)
{
var saveData = LoadSaveData();
if (saveData != null && saveData.Notes != null)
AssertConfigFile();
switch (setting)
{
return saveData.Notes;
case ConfigSettings.Volume:
_curConfigData.SetValue("Options", "Volume", value);
break;
case ConfigSettings.InputKey:
_curConfigData.SetValue("Options", "InputKey", value);
break;
case ConfigSettings.LanguageKey:
_curConfigData.SetValue("Options", "LanguageKey", value);
break;
case ConfigSettings.HighContrast:
_curConfigData.SetValue("Options", "HighContrast", value);
break;
}
else
SaveConfig();
}

public static void AssertConfigFile()
{
if (_curConfigData == null)
{
return new Dictionary<string, int>();
LoadConfigData();
}
}

// This method loads the entire save data
public static SaveData LoadSaveData()
private static void LoadConfigData()
{
string path = ProjectSettings.GlobalizePath(SavePath);
if (!File.Exists(path))
{
GD.PrintErr("Can't load save game");
return null;
}
_curConfigData = new ConfigFile();
VerifyConfig();
if (_curConfigData.Load(UserConfigPath) == Error.Ok)
return;
GD.Print("No config could be found, creating a new one.");
InitConfig();
SaveConfig();
}

string json = File.ReadAllText(path);
SaveData data = JsonSerializer.Deserialize<SaveData>(json);
return data;
//Really naive approach to verifying config integrity, could I have just changed back to JSON? yes. But I'm a real programmer.
//In theory ConfigFiles should be more stable across any version changes.
private static void VerifyConfig()
{
if (!FileAccess.FileExists(UserConfigPath))
return;
string[] sus = new[]
{
"init",
"object",
"script",
"source",
"extends",
"RefCounted",
"sus",
};
FileAccess file = FileAccess.Open(UserConfigPath, FileAccess.ModeFlags.Read);
if (!sus.Any(s => file.GetAsText().Contains(s)))
return;
file.Close();
InitConfig();
}
}

public class SaveData
{
public string AccountName { get; set; }
public Dictionary<string, int> Notes { get; set; } = new Dictionary<string, int>();
public Dictionary<string, object> Relics { get; set; } = new Dictionary<string, object>();
public Dictionary<string, float> Settings { get; set; } = new Dictionary<string, float>();
public static Variant GetConfigValue(ConfigSettings setting)
{
AssertConfigFile();
switch (setting)
{
case ConfigSettings.Volume:
return _curConfigData.GetValue("Options", "Volume", DefaultVolume);
case ConfigSettings.InputKey:
return _curConfigData.GetValue("Options", "InputKey", DefaultInput);
case ConfigSettings.LanguageKey:
return _curConfigData.GetValue("Options", "LanguageKey", DefaultLanguage);
case ConfigSettings.HighContrast:
return _curConfigData.GetValue("Options", "HighContrast", DefaultHighCon);
default:
GD.PushError(
"SaveSystem.GetConfigValue: Invalid config setting passed. " + setting
);
return float.MinValue;
}
}
}
42 changes: 41 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ run/main_scene="res://scenes/SceneTransitions/TitleScreen.tscn"
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
config/icon="res://scenes/BattleDirector/assets/Character1.png"

[audio]

buses/default_bus_layout=""

[autoload]

StageProducer="*res://Globals/StageProducer.cs"
TimeKeeper="*res://Globals/TimeKeeper.cs"
Scribe="*res://Globals/Scribe.cs"
StageProducer="*res://Globals/StageProducer.cs"
BgAudioPlayer="*res://Globals/BGAudioPlayer.tscn"

[display]
Expand All @@ -39,12 +43,45 @@ input_scheme="ARROWS"

[input]

ui_left={
"deadzone": 0.5,
"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)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
, 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)
]
}
ui_right={
"deadzone": 0.5,
"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)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
, 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)
]
}
ui_up={
"deadzone": 0.5,
"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)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
, 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)
]
}
ui_down={
"deadzone": 0.5,
"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)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
, 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)
]
}
arrowUp={
"deadzone": 0.5,
"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)
, 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)
, 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)
, 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)
, 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)
]
}
arrowDown={
Expand All @@ -53,6 +90,7 @@ arrowDown={
, 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)
, 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)
, 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)
, 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)
]
}
arrowLeft={
Expand All @@ -61,6 +99,7 @@ arrowLeft={
, 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)
, 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)
, 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)
, 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)
]
}
arrowRight={
Expand All @@ -69,6 +108,7 @@ arrowRight={
, 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)
, 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)
, 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)
, 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)
]
}
Pause={
Expand Down
4 changes: 1 addition & 3 deletions scenes/NoteManager/scripts/InputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public override void _Ready()

private void LoadControlScheme()
{
string scheme = ProjectSettings.HasSetting("game/input_scheme")
? (string)ProjectSettings.GetSetting("game/input_scheme")
: "ARROWS";
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputKey).As<string>();
foreach (var arrow in Arrows)
{
var events = InputMap.ActionGetEvents(arrow.Key);
Expand Down
Loading