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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
.idea/.idea.Funk Engine/.idea/

*.DotSettings.user
export_presets.cfg
export_presets.cfg
*.translation
2 changes: 1 addition & 1 deletion Funk Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RootNamespace>FunkEngine</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="SaveData\SaveData.json" />
<Content Include="Globals\translations.csv" />
<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
2 changes: 1 addition & 1 deletion Globals/FunkEngineNameSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum Stages
Quit,
Map,
Controls,
Options,
}

public class MapGrid
Expand Down Expand Up @@ -166,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
10 changes: 5 additions & 5 deletions Globals/Scribe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class Scribe : Node
),
new Note(
"PlayerBase",
"Basic player note, deals damage to enemy",
"Basic player note, deals damage to enemy.",
GD.Load<Texture2D>("res://Classes/Notes/assets/single_note.png"),
null,
1,
Expand All @@ -35,7 +35,7 @@ public partial class Scribe : Node
),
new Note(
"PlayerDouble",
"Basic player note, deals double damage to enemy",
"Basic player note, deals double damage to enemy.",
GD.Load<Texture2D>("res://Classes/Notes/assets/double_note.png"),
null,
1,
Expand All @@ -48,7 +48,7 @@ public partial class Scribe : Node
),
new Note(
"PlayerHeal",
"Basic player note, heals player",
"Basic player note, heals player.",
GD.Load<Texture2D>("res://Classes/Notes/assets/heal_note.png"),
null,
1,
Expand All @@ -59,7 +59,7 @@ public partial class Scribe : Node
),
new Note(
"PlayerVampire",
"Steals health from enemy",
"Steals health from enemy.",
GD.Load<Texture2D>("res://Classes/Notes/assets/vampire_note.png"),
null,
1,
Expand All @@ -71,7 +71,7 @@ public partial class Scribe : Node
),
new Note(
"PlayerQuarter",
"Basic note at a quarter of the cost",
"Basic note at a quarter of the cost.",
GD.Load<Texture2D>("res://Classes/Notes/assets/quarter_note.png"),
null,
1,
Expand Down
18 changes: 15 additions & 3 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,9 +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.Chest:
Config = MakeConfig(nextStage, nextRoomIdx);
GetTree().ChangeSceneToFile("res://scenes/ChestScene/ChestScene.tscn");
Expand Down
54 changes: 54 additions & 0 deletions Globals/translations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
keys,en,cn
TITLE,Midnight Riff,中夜现场
TITLE_START,Start Game,开始游戏
TITLE_QUIT,Quit Game,退出游戏
TITLE_OPTIONS,Options,选项
TITLE_CONTROLS,Change Controls,更改操控
CONTROLS_TITLE_TYPE_WASD,WASD,WASD
CONTROLS_TITLE_TYPE_QWER,QWERT,QWERT
CONTROLS_TITLE_TYPE_ARROW,Arrow,箭头键
CONTROLS_TITLE_SELECTED,Selected,已选择
CONTROLS_WASD_BUTTON,WASD,WASD
CONTROLS_QWER_BUTTON,QWER,QWER
CONTROLS_ARROW_BUTTON,Arrow Keys,箭头键
CONTROLS_RETURN_BUTTON,Return,返回
ESCAPE_MENU_RESUME,Resume,继续
ESCAPE_MENU_QUIT,Quit,退出
ESCAPE_MENU_TITLE,Quit to Title,返回标题
CHEST_ROOM_REWARDS,Rewards!,奖励!
CHEST_ROOM_SKIP,Skip,跳过
CHEST_ROOM_ACCEPT,Accept,接受
BATTLE_ROOM_BEGIN_BUTTON,"Begin Battle [Enter]","开始战斗 [Enter]"
BATTLE_ROOM_PERFECT,Perfect,精准
BATTLE_ROOM_GOOD,Good,良好
BATTLE_ROOM_OK,OK,可以
BATTLE_ROOM_MISS,Miss,错误
BATTLE_ROOM_WIN,"You win!","你获胜了!"
BATTLE_ROOM_LOSE,"Game Over!","游戏结束!"
END_SCREEN_RESTART,Restart,重新开始
BATTLE_ROOM_SKIP_BUTTON,Skip,跳过
BATTLE_ROOM_ACCEPT_BUTTON,Accept,接受
NOTE_ENEMYBASE_NAME,EnemyBase,敌人基地
NOTE_ENEMYBASE_TOOLTIP,"Basic enemy note, deals damage to player.","基础敌人音符,对玩家造成伤害"
NOTE_PLAYERBASE_NAME,PlayerBase,玩家基地
NOTE_PLAYERBASE_TOOLTIP,"Basic player note, deals damage to enemy.","基础玩家音符,对敌人造成伤害"
NOTE_PLAYERDOUBLE_NAME,PlayerDouble,玩家双击
NOTE_PLAYERDOUBLE_TOOLTIP,"Basic player note, deals double damage to enemy.","基础玩家音符,对敌人造成双倍伤害"
NOTE_PLAYERHEAL_NAME,PlayerHeal,玩家治愈
NOTE_PLAYERHEAL_TOOLTIP,"Basic player note, heals player.","基础玩家音符,治愈玩家"
NOTE_PLAYERVAMPIRE_NAME,PlayerVampire,玩家吸血
NOTE_PLAYERVAMPIRE_TOOLTIP,"Steals health from enemy.","从敌人吸取生命值"
NOTE_PLAYERQUARTER_NAME,PlayerQuarter,玩家一分之一
NOTE_PLAYERQUARTER_TOOLTIP,"Basic note at a quarter of the cost.","以四分之一的耗费时间量发出基础音符"
RELIC_BREAKFAST_NAME,Breakfast,早餐
RELIC_BREAKFAST_TOOLTIP,"Increases max hp.",提高最大生命值
RELIC_GOODVIBES_NAME,Good Vibes,良好消息
RELIC_GOODVIBES_TOOLTIP,"Heals the player whenever they place a note.","每开始一个音符时治愈玩家"
RELIC_AUROBOROS_NAME,Auroboros,无尾蛇
RELIC_AUROBOROS_TOOLTIP,"Bigger number, better person. Increases combo multiplier every riff.","进一步增加综合倍数,每次现场提升"
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,高对比度模式
17 changes: 17 additions & 0 deletions Globals/translations.csv.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[remap]

importer="csv_translation"
type="Translation"
uid="uid://drjnsd6mqpxqh"

[deps]

files=["res://Globals/translations.en.translation", "res://Globals/translations.cn.translation"]

source_file="res://Globals/translations.csv"
dest_files=["res://Globals/translations.en.translation", "res://Globals/translations.cn.translation"]

[params]

compress=true
delimiter=0
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;
}
}
}
Loading