Skip to content

Commit c67bc2c

Browse files
committed
saveas bugfix
1 parent b0e6280 commit c67bc2c

File tree

8 files changed

+36
-18
lines changed

8 files changed

+36
-18
lines changed

FFR/FileManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ public override void WriteFile(Stream file, WriteFormat format)
6161
{
6262
using var stream = new BinaryWriter(file);
6363
stream.Write(MapData.DecodeMap());
64+
stream.Close();
6465
}
6566
else
6667
{
6768
string serializedOwData = JsonSerializer.Serialize<OwMapExchangeData>(MapData, new JsonSerializerOptions { WriteIndented = true });
6869
using var stream = new StreamWriter(file);
6970
stream.Write(serializedOwData);
71+
stream.Close();
7072
}
7173
}
7274
public override void ReadFile(Stream file, WriteFormat format)
@@ -75,6 +77,7 @@ public override void ReadFile(Stream file, WriteFormat format)
7577
{
7678
using var stream = new BinaryReader(file);
7779
var dataarray = stream.ReadBytes(0x10000);
80+
stream.Close();
7881

7982
MapData = new();
8083
MapData.EncodeMapFromBytes(dataarray);
@@ -83,6 +86,7 @@ public override void ReadFile(Stream file, WriteFormat format)
8386
{
8487
using var stream = new StreamReader(file);
8588
var jsonstring = stream.ReadToEnd();
89+
stream.Close();
8690

8791
MapData = JsonSerializer.Deserialize<OwMapExchangeData>(jsonstring);
8892
}

FileManager.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public class FileManager
125125
public bool FilenameUpdated { get; set; }
126126
//public virtual object MapData { get; set; }
127127
public SettingsManager Settings { get; set; }
128+
public SavingMode SaveMode { get; set; }
128129
public FileManager(GameMode _mode)
129130
{
130131
LoadedMapPath = "";
@@ -134,6 +135,7 @@ public FileManager(GameMode _mode)
134135
ManagerMode = _mode;
135136
MapDataMQ = new();
136137
MapDataFF = new();
138+
SaveMode = SavingMode.SaveAs;
137139

138140
if (ManagerMode == GameMode.FFR)
139141
{
@@ -233,19 +235,22 @@ public virtual void WriteFile(Stream file, WriteFormat format)
233235
{
234236
using var stream = new BinaryWriter(file);
235237
stream.Write(MapDataFF.DecodeMap());
238+
stream.Close();
236239
}
237240
else
238241
{
239242
string serializedOwData = JsonSerializer.Serialize<OwMapExchangeData>(MapDataFF, new JsonSerializerOptions { WriteIndented = true });
240243
using var stream = new StreamWriter(file);
241244
stream.Write(serializedOwData);
245+
stream.Close();
242246
}
243247
}
244248
else if (ManagerMode == GameMode.FFMQ)
245249
{
246250
string serializedOwData = GetJsonString();
247251
using var stream = new StreamWriter(file);
248252
stream.Write(serializedOwData);
253+
stream.Close();
249254
}
250255
}
251256
public virtual void ReadFile(Stream file, WriteFormat format)
@@ -256,6 +261,7 @@ public virtual void ReadFile(Stream file, WriteFormat format)
256261
{
257262
using var stream = new BinaryReader(file);
258263
var dataarray = stream.ReadBytes(0x10000);
264+
stream.Close();
259265

260266
MapDataFF = new();
261267
MapDataFF.EncodeMapFromBytes(dataarray);
@@ -264,6 +270,7 @@ public virtual void ReadFile(Stream file, WriteFormat format)
264270
{
265271
using var stream = new StreamReader(file);
266272
var jsonstring = stream.ReadToEnd();
273+
stream.Close();
267274

268275
MapDataFF = JsonSerializer.Deserialize<OwMapExchangeData>(jsonstring);
269276
}
@@ -272,6 +279,7 @@ public virtual void ReadFile(Stream file, WriteFormat format)
272279
{
273280
using var stream = new StreamReader(file);
274281
var jsonstring = stream.ReadToEnd();
282+
stream.Close();
275283
LoadMapData(jsonstring);
276284
}
277285
}
@@ -301,11 +309,13 @@ private void ProcessTasksFF(CanvasFFR map, TaskManager tasks)
301309
if (map.MissingMapObjects.Any() || !map.DefaultDockPlaced || map.MissingRequiredTiles.Any())
302310
{
303311
tasks.Add(new EditorTask(EditorTasks.SaveWarningOpen));
304-
tasks.Add(new EditorTask(EditorTasks.SaveWarningUpdate, task.Value));
312+
tasks.Add(new EditorTask(EditorTasks.SaveWarningUpdate));
313+
SaveMode = (SavingMode)task.Value;
305314
}
306315
else
307316
{
308317
tasks.Add(new EditorTask(EditorTasks.SaveNoWarning, task.Value));
318+
SaveMode = (SavingMode)task.Value;
309319
}
310320
}
311321

@@ -328,7 +338,7 @@ private void ProcessTasksFF(CanvasFFR map, TaskManager tasks)
328338

329339
if (tasks.Pop(EditorTasks.SaveNoWarning, out task))
330340
{
331-
if (task.Value == (int)SavingMode.Save)
341+
if (SaveMode == SavingMode.Save)
332342
{
333343
if (FileSelected())
334344
{
@@ -341,7 +351,7 @@ private void ProcessTasksFF(CanvasFFR map, TaskManager tasks)
341351
filesaved = SaveFileAs();
342352
}
343353
}
344-
else if (task.Value == (int)SavingMode.SaveAs)
354+
else if (SaveMode == SavingMode.SaveAs)
345355
{
346356
LoadMapData(map);
347357
filesaved = SaveFileAs();
@@ -405,7 +415,7 @@ private void ProcessTasksMQ(CanvasMQ map, TaskManager tasks)
405415

406416
if (tasks.Pop(EditorTasks.SaveNoWarning, out task))
407417
{
408-
if (task.Value == (int)SavingMode.Save)
418+
if (SaveMode == SavingMode.Save)
409419
{
410420
if (FileSelected())
411421
{
@@ -418,7 +428,7 @@ private void ProcessTasksMQ(CanvasMQ map, TaskManager tasks)
418428
filesaved = SaveFileAs();
419429
}
420430
}
421-
else if (task.Value == (int)SavingMode.SaveAs)
431+
else if (SaveMode == SavingMode.SaveAs)
422432
{
423433
LoadMapData(map);
424434
filesaved = SaveFileAs();
@@ -533,6 +543,7 @@ public bool SaveBackup()
533543
string serializedOwData = GetJsonString();
534544
using var stream = new StreamWriter("backupowmap.json");
535545
stream.Write(serializedOwData);
546+
stream.Close();
536547

537548
return true;
538549
}
@@ -545,6 +556,7 @@ public void SaveSettings()
545556
string serializedData = JsonSerializer.Serialize<SettingsManager>(Settings, new JsonSerializerOptions { WriteIndented = true });
546557
using var stream = new StreamWriter("settings.json");
547558
stream.Write(serializedData);
559+
stream.Close();
548560
}
549561
public void LoadSettings()
550562
{
@@ -555,6 +567,8 @@ public void LoadSettings()
555567

556568
using var stream = new StreamReader("settings.json");
557569
var jsonstring = stream.ReadToEnd();
570+
stream.Close();
571+
558572

559573
Settings = JsonSerializer.Deserialize<SettingsManager>(jsonstring);
560574

InfoBox.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class InfoBox
2525
protected float zoom;
2626
protected Button okButton;
2727
protected Button cancelButton;
28-
protected SavingMode saveMode;
2928
protected string warningText;
3029
protected Vector2 windowDimensions;
3130
protected int windowWidth;

InfoWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public InfoWindow(Texture2D _window, SpriteFont _font, Texture2D _buttonTexture,
3232
windowWidth = 28 * 8;
3333
okButton = new(_font, "OK", _buttonTexture, new() { new EditorTask(EditorTasks.ToggleInfoWindow, 10) });
3434

35-
windowText = "FFR Map Editor v1.06\n\n" +
35+
windowText = "FFR Map Editor v1.07\n\n" +
3636
"Main Developer\n wildham\n\n" +
3737
"Icons Designer\n DarkmoonEX\n\n" +
3838
"Based on the work of\n" +
3939
" tetron (Overworld Map Format)\n" +
4040
" madmartin (Enabling Logic)\n\n" +
41+
"Beta Tester\n shoombabi\n\n" +
4142
"Source code at\n" +
4243
" https://github.com/wildham0/FFRMapEditorMono\n\n" +
4344
"Randomizer\n" +

MysticQuest/FileManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ public override void WriteFile(Stream file, WriteFormat format)
3737
string serializedOwData = GetJsonString();
3838
using var stream = new StreamWriter(file);
3939
stream.Write(serializedOwData);
40+
stream.Close();
4041
}
4142
public override void ReadFile(Stream file, WriteFormat format)
4243
{
4344
using var stream = new StreamReader(file);
4445
var jsonstring = stream.ReadToEnd();
46+
stream.Close();
4547
LoadMapData(jsonstring);
4648
}
4749
}

WarningWindow.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class WarningWindow
2626
protected float zoom;
2727
protected Button okButton;
2828
protected Button cancelButton;
29-
protected SavingMode saveMode;
3029
protected string warningText;
3130
protected Vector2 windowDimensions;
3231
protected int windowWidth;

WarningWindowSave.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,16 @@ public SaveWarningWindow(Texture2D _windowtexture, SpriteFont _font, Texture2D _
2323
UpdatePosition(resolution);
2424
buttons = new()
2525
{
26-
new(font, "Save map file anyway", _buttonTexture, new() { new EditorTask(EditorTasks.SaveNoWarning, (int)saveMode), new EditorTask(EditorTasks.SaveWarningClose, 10) }),
26+
new(font, "Save map file anyway", _buttonTexture, new() { new EditorTask(EditorTasks.SaveNoWarning), new EditorTask(EditorTasks.SaveWarningClose, 10) }),
2727
new(font, "Return to editor", _buttonTexture, new() { new EditorTask(EditorTasks.SaveWarningClose, 10)})
2828
};
2929
}
3030
public void ProcessTasks(CanvasFFR overworld, Point resolution, TaskManager tasks)
3131
{
3232
EditorTask task;
3333

34-
if (tasks.Pop(EditorTasks.SetSavingMode, out task))
35-
{
36-
saveMode = (SavingMode)task.Value;
37-
}
38-
3934
if (tasks.Pop(EditorTasks.SaveWarningUpdate, out task))
4035
{
41-
saveMode = (SavingMode)task.Value;
42-
43-
4436
var validationresult = overworld.ValidateObjects();
4537

4638
warningText = "*** Warning *** \n\n";

readme.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FFR Map Editor v1.05
1+
FFR Map Editor v1.07
22

33
Credits ........... [S01]
44
Version Changes ... [S02]
@@ -16,10 +16,17 @@ Based on the work of
1616
tetron (Overworld Map Format)
1717
madmartin (Enabling Logic)
1818

19+
Beta Tester
20+
shoombabi
21+
1922
Source code at
2023
https://github.com/wildham0/FFRMapEditorMono
2124

2225
*** Version Change *** [S02]
26+
1.07: - Fix Save As bug.
27+
- Fix file corruption bug.
28+
1.06: - Fix Undo/Redo options.
29+
- Fix crash on saving.
2330
1.05: - Add Selection and Copy/Paste.
2431
1.04: - Add Gridlines and Coordinates options.
2532
1.03: - Fixed FFR locations error at import.

0 commit comments

Comments
 (0)