Skip to content

Commit

Permalink
tested
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCorby committed Aug 15, 2021
1 parent e6c8b3a commit ec2322a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Distance.LevelMods/CustomObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public static void Register(SerialComponent entryComp, byte[] data) {
BinaryDeserializer.idToSerializableTypeMap_[entryComp.ID_] = entryComp.GetType();

var root = man.LevelPrefabFileInfosRoot_;
root.AddChildInfo(new LevelPrefabFileInfo(entryComp.name, entryComp.gameObject, root));
var info = new LevelPrefabFileInfo(entryComp.name, entryComp.gameObject, root);
if (root.childInfos_.RemoveAll(info1 => info1.Name_ == info.Name_) > 0)
G.Sys.LevelEditor_.DoFramesLater(2, () => G.Sys.LevelEditor_.SetToolText(
$"Updated prefab for custom object {entryComp.name}"));
root.AddChildInfo(info);
}
}
}
6 changes: 4 additions & 2 deletions Distance.LevelMods/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public void Initialize(IManager manager) {
G.Sys.LevelEditor_.AddEventToRegisteredHotKeys(InputEvent.Create("ctrl+shift+o"),
LoadCustomObjectTool.info.Name_));

PostLoad.Subscribe(data =>
PostLoad.Subscribe(data => {
// remove custom object manager when a level loads
data.level_.TryDeleteLayer(data.level_.GetLayer(nameof(CustomObjectManager)), true));
var layer = data.level_.GetLayer(nameof(CustomObjectManager));
if (layer != null) data.level_.TryDeleteLayer(layer, true);
});

RuntimePatcher.AutoPatch();
}
Expand Down
2 changes: 2 additions & 0 deletions Distance.LevelMods/Harmony.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace Level_ {
internal static class SaveToPath {
[UsedImplicitly]
private static void Prefix(Level __instance) {
if (__instance.FindComponentsOfType<CustomObject>().IsNullOrEmpty()) return;

var le = G.Sys.levelEditor_!;

var prefab = G.Sys.ResourceManager_.levelPrefabs_[nameof(CustomObjectManager)];
Expand Down

0 comments on commit ec2322a

Please sign in to comment.