Implement the file export. Now the Variable Export fully works.

rabi_display
wcko87 8 years ago
parent bf552d9a28
commit 382bf61271
  1. 13
      rabi_splitter_WPF/RabiRibiDisplay.cs
  2. 3
      rabi_splitter_WPF/VariableExportContext.cs
  3. 25
      rabi_splitter_WPF/VariableExportSetting.cs

@ -117,7 +117,6 @@ namespace rabi_splitter_WPF
if (InGame()) if (InGame())
{ {
inGameState.nRestarts++; inGameState.nRestarts++;
UpdateTextFile();
} }
DebugLog("Reload Game! " + snapshot.playtime + " <- " + inGameState.lastNonZeroPlayTime); DebugLog("Reload Game! " + snapshot.playtime + " <- " + inGameState.lastNonZeroPlayTime);
} }
@ -197,7 +196,6 @@ namespace rabi_splitter_WPF
if (InGame()) if (InGame())
{ {
inGameState.nDeaths++; inGameState.nDeaths++;
UpdateTextFile();
} }
DebugLog("Death!"); DebugLog("Death!");
} }
@ -296,16 +294,7 @@ namespace rabi_splitter_WPF
mainContext.Text20 = bosstext; mainContext.Text20 = bosstext;
} }
} }
private void UpdateTextFile()
{
//return;
string text = $"Deaths: {inGameState.nDeaths}\nResets: {inGameState.nRestarts}";
System.IO.StreamWriter file = new System.IO.StreamWriter("deaths_restarts.txt");
file.WriteLine(text);
file.Close();
}
private void StartNewGame() private void StartNewGame()
{ {
inGameState = new InGameState(); inGameState = new InGameState();

@ -36,7 +36,8 @@ namespace rabi_splitter_WPF
foreach (var ves in _variableExportSettings) foreach (var ves in _variableExportSettings)
{ {
ves.OutputUpdate(variableValues, updateFile); ves.UpdateText(variableValues);
if (updateFile) ves.MaybeUpdateFile();
} }
} }

@ -82,6 +82,7 @@ namespace rabi_splitter_WPF
private string _formatPreview; private string _formatPreview;
private bool _isExporting; private bool _isExporting;
private bool _isPreviewingFormat; private bool _isPreviewingFormat;
private bool _hasChangedSinceLastFileOutput;
public VariableExportSetting() public VariableExportSetting()
{ {
@ -90,6 +91,7 @@ namespace rabi_splitter_WPF
_outputFormat = ""; _outputFormat = "";
_isExporting = false; _isExporting = false;
_isPreviewingFormat = false; _isPreviewingFormat = false;
_hasChangedSinceLastFileOutput = true;
} }
#region Logic #region Logic
@ -105,17 +107,27 @@ namespace rabi_splitter_WPF
} }
} }
internal void OutputUpdate(Dictionary<string, object> variableValues, bool updateFile) internal void UpdateText(Dictionary<string, object> variableValues)
{ {
var formattedOutput = FormatOutput(variableValues); var formattedOutput = FormatOutput(variableValues);
if (formattedOutput == FormatPreview) return; if (formattedOutput != FormatPreview)
FormatPreview = formattedOutput;
if (updateFile)
{ {
// TODO: Write to file FormatPreview = formattedOutput;
_hasChangedSinceLastFileOutput = true;
} }
} }
internal void MaybeUpdateFile()
{
if (!_hasChangedSinceLastFileOutput || !IsExporting) return;
System.IO.StreamWriter file = new System.IO.StreamWriter(OutputFileName);
file.WriteLine(FormatPreview);
file.Close();
_hasChangedSinceLastFileOutput = false;
}
#endregion #endregion
#region Parameters #region Parameters
@ -128,6 +140,7 @@ namespace rabi_splitter_WPF
if (value.Equals(_outputFileName)) return; if (value.Equals(_outputFileName)) return;
_outputFileName = value; _outputFileName = value;
OnPropertyChanged(nameof(OutputFileName)); OnPropertyChanged(nameof(OutputFileName));
_hasChangedSinceLastFileOutput = true;
} }
} }

Loading…
Cancel
Save