Skip to content

Commit

Permalink
Setting up new fuji option that writes out the games log data to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasminegamedev committed Feb 18, 2024
1 parent 37fadb4 commit 57f9c92
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Content/Text/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"ID": "english",
"Label": "English",
"Font": "Renogare",
"Strings":
{
"Strings": {
"Confirm": "Confirm",
"Cancel": "Cancel",
"Back": "Back",
Expand All @@ -26,7 +25,7 @@
"OptionsInvertCamera": "Inverted Camera",

"FujiOptions": "Fuji Options...",

"FujiWriteLog": "Write Log File",
"PauseMods": "Mods",
"PauseModEnabled": "Enabled",
"PauseModsConfirmDisable": "Continue & Disable Mod",
Expand Down
22 changes: 16 additions & 6 deletions Source/Data/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ public bool SetBool(string name, bool value = false)
/// </summary>
public int SfxVolume { get; set; } = 10;

/// <summary>
/// SkinName
/// </summary>
public string SkinName { get; set; } = "Madeline";

/// <summary>
/// Invert the camera in given directions
/// </summary>
Expand All @@ -135,7 +130,17 @@ public bool SetBool(string name, bool value = false)
public List<LevelRecord> Records { get; set; } = [];

/// <summary>
/// Records for each level
/// Fuji Custom - Currently equipped skin name
/// </summary>
public string SkinName { get; set; } = "Madeline";

/// <summary>
/// Fuji Custom - Whether we should write to the log file or not.
/// </summary>
public bool WriteLog { get; set; } = true;

/// <summary>
/// Fuji Custom - Records for each mod
/// </summary>
public List<ModRecord> ModRecords { get; set; } = [];

Expand Down Expand Up @@ -223,6 +228,11 @@ public void ToggleFullscreen()
SyncSettings();
}

public void ToggleWriteLog()
{
WriteLog = !WriteLog;
}

public void ToggleZGuide()
{
ZGuide = !ZGuide;
Expand Down
54 changes: 51 additions & 3 deletions Source/Game.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Text;
using Celeste64.Mod;
using Celeste64.Mod.Patches;

Expand Down Expand Up @@ -115,6 +116,9 @@ public override void Shutdown()

scenes.Clear();
instance = null;

Log.Info("Shutting down...");
WriteToLog();
}

public bool IsMidTransition => transitionStep != TransitionStep.None;
Expand Down Expand Up @@ -240,7 +244,10 @@ public override void Update()
if (lastWav != nextWav)
{
MusicWav?.Stop();
MusicWav = Audio.PlayMusic(nextWav);
if (string.IsNullOrEmpty(nextWav))
{
MusicWav = Audio.PlayMusic(nextWav);
}
}
}

Expand All @@ -251,21 +258,29 @@ public override void Update()
if (next != last)
{
Ambience.Stop();
Ambience = Audio.Play(next);
if (string.IsNullOrEmpty(next))
{
Ambience = Audio.Play(next);
}
}

string lastWav = AmbienceWav != null && AmbienceWav.Value.IsPlaying && lastScene != null ? lastScene.AmbienceWav : string.Empty;
string nextWav = nextScene?.AmbienceWav ?? string.Empty;
if (lastWav != nextWav)
{
AmbienceWav?.Stop();
AmbienceWav = Audio.PlayMusic(nextWav);
if (string.IsNullOrEmpty(nextWav))
{
AmbienceWav = Audio.PlayMusic(nextWav);
}
}
}

// in case new music was played
Save.Instance.SyncSettings();
transitionStep = TransitionStep.FadeIn;

WriteToLog();
}
else if (transitionStep == TransitionStep.FadeIn)
{
Expand Down Expand Up @@ -375,6 +390,39 @@ public override void Render()
}
}

// Fuji Custom
public static void WriteToLog()
{
if (!Save.Instance.WriteLog)
{
return;
}

// construct a log message
const string LogFileName = "Log.txt";
StringBuilder log = new();
lock (Log.Logs)
log.AppendLine(Log.Logs.ToString());

// write to file
string path = LogFileName;
{
if (App.Running)
{
try
{
path = Path.Join(App.UserPath, LogFileName);
}
catch
{
path = LogFileName;
}
}

File.WriteAllText(path, log.ToString());
}
}

private FMOD.RESULT MusicTimelineCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr _event, IntPtr parameters)
{
// notify that an audio event happened (but handle it on the main thread)
Expand Down
3 changes: 2 additions & 1 deletion Source/Helpers/GameOptionsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public GameOptionsMenu()
FujiOptionsMenu = new Menu();

FujiOptionsMenu.Title = Loc.Str("FujiOptions");
FujiOptionsMenu.Add(new Menu.Option(Loc.Str("Exit"), () => {
FujiOptionsMenu.Add(new Menu.Toggle(Loc.Str("FujiWriteLog"), Save.Instance.ToggleWriteLog, () => Save.Instance.WriteLog));
FujiOptionsMenu.Add(new Menu.Option(Loc.Str("Exit"), () => {
this.PopSubMenu();
}));

Expand Down

0 comments on commit 57f9c92

Please sign in to comment.