Skip to content

Commit 222dbac

Browse files
committed
Resolves #142
1 parent 2709126 commit 222dbac

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

Dat/FileParsing/SawyerStreamWriter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public static void ExportMusicAsWave(string filename, RiffWavHeader header, byte
9898
}
9999
}
100100

101-
public static void Save(string filename, string objName, SourceGame sourceGame, ILocoObject locoObject, ILogger logger)
101+
public static void Save(string filename, string objName, SourceGame sourceGame, ILocoObject locoObject, ILogger logger, bool allowWritingAsVanilla)
102102
{
103103
ArgumentNullException.ThrowIfNull(locoObject);
104104

105105
logger.Info($"Writing \"{objName}\" to {filename}");
106106

107-
var objBytes = WriteLocoObject(objName, sourceGame, logger, locoObject);
107+
var objBytes = WriteLocoObject(objName, sourceGame, logger, locoObject, allowWritingAsVanilla);
108108

109109
try
110110
{
@@ -123,10 +123,10 @@ public static void Save(string filename, string objName, SourceGame sourceGame,
123123
logger.Info($"{objName} successfully saved to {filename}");
124124
}
125125

126-
public static ReadOnlySpan<byte> WriteLocoObject(string objName, SourceGame sourceGame, ILogger logger, ILocoObject obj)
127-
=> WriteLocoObjectStream(objName, sourceGame, logger, obj).ToArray();
126+
public static ReadOnlySpan<byte> WriteLocoObject(string objName, SourceGame sourceGame, ILogger logger, ILocoObject obj, bool allowWritingAsVanilla)
127+
=> WriteLocoObjectStream(objName, sourceGame, logger, obj, allowWritingAsVanilla).ToArray();
128128

129-
public static MemoryStream WriteLocoObjectStream(string objName, SourceGame sourceGame, ILogger logger, ILocoObject obj)
129+
public static MemoryStream WriteLocoObjectStream(string objName, SourceGame sourceGame, ILogger logger, ILocoObject obj, bool allowWritingAsVanilla)
130130
{
131131
using var objStream = new MemoryStream();
132132

@@ -173,7 +173,7 @@ public static MemoryStream WriteLocoObjectStream(string objName, SourceGame sour
173173

174174
var s5Header = new S5Header(objName, 0)
175175
{
176-
SourceGame = sourceGame == SourceGame.Vanilla ? SourceGame.Custom : sourceGame, // do not allow users to write "Vanilla" to objects
176+
SourceGame = sourceGame == SourceGame.Vanilla ? (allowWritingAsVanilla ? SourceGame.Vanilla : SourceGame.Custom) : sourceGame,
177177
ObjectType = attr!.ObjectType
178178
};
179179

Gui/EditorSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public HashSet<string> ObjDataDirectories
2828
set => objDataDirectories = value;
2929
}
3030
HashSet<string> objDataDirectories;
31-
31+
public bool AllowSavingAsVanillaObject { get; set; }
3232
public bool AutoObjectDiscoveryAndUpload { get; set; }
3333

3434
public bool UseHttps { get; set; }

Gui/ViewModels/DatTypes/DatObjectEditorViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ void SaveCore(string filename)
185185
S5HeaderViewModel?.Name ?? CurrentObject.DatFileInfo.S5Header.Name,
186186
S5HeaderViewModel?.SourceGame ?? CurrentObject.DatFileInfo.S5Header.SourceGame,
187187
CurrentObject.LocoObject,
188-
Logger);
188+
Logger,
189+
Model.Settings.AllowSavingAsVanillaObject);
189190
}
190191

191192
(IList<TreeNode> treeView, Dictionary<string, (int, int)> annotationIdentifiers) AnnotateFile(string path, ILogger logger, bool isG1 = false)

Gui/ViewModels/EditorSettingsWindowViewModel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public EditorSettingsWindowViewModel(EditorSettings settings)
1717
{
1818
_Settings = settings;
1919

20+
AllowSavingAsVanillaObject = settings.AllowSavingAsVanillaObject;
2021
AutoObjectDiscoveryAndUpload = settings.AutoObjectDiscoveryAndUpload;
2122
UseHttps = settings.UseHttps;
2223
ServerAddressHttp = settings.ServerAddressHttp;
@@ -28,6 +29,7 @@ public EditorSettingsWindowViewModel(EditorSettings settings)
2829

2930
public void Commit()
3031
{
32+
_Settings.AllowSavingAsVanillaObject = AllowSavingAsVanillaObject;
3133
_Settings.AutoObjectDiscoveryAndUpload = AutoObjectDiscoveryAndUpload;
3234
_Settings.UseHttps = UseHttps;
3335
_Settings.ServerAddressHttp = ServerAddressHttp;
@@ -37,6 +39,9 @@ public void Commit()
3739
_Settings.ObjDataDirectories = ObjDataDirectories.ToHashSet();
3840
}
3941

42+
[Reactive, Category("Misc"), DisplayName("Allow saving as vanilla object"), Description("If enabled, the editor will allow saving objects with \"Vanilla\" flag set. If disabled, the object will be forcefully saved as \"Custom\" instead.")]
43+
public bool AllowSavingAsVanillaObject { get; set; }
44+
4045
#region Object Folders
4146

4247
[Reactive, PathBrowsable(PathBrowsableType.Directory), Category("Object Folders"), DisplayName("Downloads"), Description("The folder to store downloaded objects")]
@@ -48,13 +53,13 @@ public void Commit()
4853
[Reactive, Category("Object Folders"), DisplayName("ObjectData folders"), Description("The list of all ObjectData folders.")]
4954
public BindingList<string> ObjDataDirectories { get; set; }
5055

51-
[Reactive, Category("Object Service"), DisplayName("Automatic object discovery and upload"), Description("If enabled, the editor will scan the current object directory for objects and check if there are any that are not known to the object service. If any new objects are discovered they will be automatically uploaded to the service.")]
52-
public bool AutoObjectDiscoveryAndUpload { get; set; }
53-
5456
#endregion
5557

5658
#region Object Service
5759

60+
[Reactive, Category("Object Service"), DisplayName("Automatic object discovery and upload"), Description("If enabled, the editor will scan the current object directory for objects and check if there are any that are not known to the object service. If any new objects are discovered they will be automatically uploaded to the service.")]
61+
public bool AutoObjectDiscoveryAndUpload { get; set; }
62+
5863
[Reactive, ConditionTarget, Category("Object Service"), DisplayName("Use HTTPS"), Description("Will use the HTTPS address instead of the HTTP address for Object Service connections.")]
5964
public bool UseHttps { get; set; }
6065

Tests/LoadSaveTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ static void LoadSaveGenericTest<T>(string filename, Action<ILocoObject, T> asser
5959

6060
var logger = new Logger();
6161
var objectName = filename.Split('.')[0];
62-
var bytes1 = SawyerStreamWriter.WriteLocoObject(objectName, SourceGame.Vanilla, logger, obj1);
62+
var bytes1 = SawyerStreamWriter.WriteLocoObject(objectName, SourceGame.Vanilla, logger, obj1, false);
6363

6464
var (obj2, struc2) = LoadObject<T>(bytes1);
6565
assertFunc(obj2, struc2);
6666

67-
var bytes2 = SawyerStreamWriter.WriteLocoObject(objectName, SourceGame.Vanilla, logger, obj2);
67+
var bytes2 = SawyerStreamWriter.WriteLocoObject(objectName, SourceGame.Vanilla, logger, obj2, false);
6868

6969
// we could just simply compare byte arrays and be done, but i wanted something that makes it easier to diagnose problems
7070

0 commit comments

Comments
 (0)