Implement the file export. Now the Variable Export fully works.
This commit is contained in:
parent
bf552d9a28
commit
382bf61271
@ -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!");
|
||||||
}
|
}
|
||||||
@ -297,15 +295,6 @@ namespace rabi_splitter_WPF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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…
x
Reference in New Issue
Block a user