Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Features/Enums/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public enum BlockType
/// Represents a locker.
/// </summary>
Locker = 7,

Text = 8,
Interactable = 9,
Waypoint = 10,
Door = 30, // when merging replace with normal serial number
}
6 changes: 6 additions & 0 deletions Features/Objects/SchematicObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ private void CreateRecursiveFromID(int id, List<SchematicBlockData> blocks, Tran

GameObject gameObject = block.Create(this, parentTransform);
NetworkServer.Spawn(gameObject);

// We return the parent for the door so that when deleting the schematic, the door is deleted
if (block.BlockType == BlockType.Door)
{
gameObject.transform.SetParent(parentTransform);
}

ObjectFromId.Add(block.ObjectId, gameObject.transform);

Expand Down
31 changes: 31 additions & 0 deletions Features/Serializable/Schematics/SchematicBlockData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using AdminToys;
using GameCore;
using Interactables.Interobjects.DoorUtils;
using InventorySystem.Items.Firearms.Attachments;
using LabApi.Features.Wrappers;
using ProjectMER.Events.Handlers.Internal;
Expand Down Expand Up @@ -44,6 +46,7 @@ public GameObject Create(SchematicObject schematicObject, Transform parentTransf
BlockType.Workstation => CreateWorkstation(),
BlockType.Text => CreateText(),
BlockType.Interactable => CreateInteractable(),
BlockType.Door => CreateDoor(),
BlockType.Waypoint => CreateWaypoint(),
_ => CreateEmpty(true)
};
Expand All @@ -61,6 +64,13 @@ public GameObject Create(SchematicObject schematicObject, Transform parentTransf
_ => Scale,
};

// if you don't remove the parent before NetworkServer.Spawn then there won't be a door
if (BlockType == BlockType.Door)
{
transform.SetParent(null);
}


if (gameObject.TryGetComponent(out AdminToyBase adminToyBase))
{
if (Properties != null && Properties.TryGetValue("Static", out object isStatic) && Convert.ToBoolean(isStatic))
Expand Down Expand Up @@ -158,6 +168,27 @@ private GameObject CreateWorkstation()
return workstation.gameObject;
}

private GameObject CreateDoor()
{
DoorVariant prefab = (DoorType)Convert.ToInt32(Properties["DoorType"]) switch
{
DoorType.Hcz or DoorType.HeavyContainmentDoor => PrefabManager.DoorHcz,
DoorType.Bulkdoor or DoorType.HeavyBulkDoor => PrefabManager.DoorHeavyBulk,
DoorType.Lcz or DoorType.LightContainmentDoor => PrefabManager.DoorLcz,
DoorType.Ez or DoorType.EntranceDoor => PrefabManager.DoorEz,
DoorType.Gate => PrefabManager.DoorGate,
_ => PrefabManager.DoorEz
};

DoorVariant doorVariant = GameObject.Instantiate(prefab);
doorVariant.NetworkTargetState = Convert.ToBoolean(Properties["IsOpen"]);
doorVariant.ServerChangeLock(DoorLockReason.SpecialDoorFeature, Convert.ToBoolean(Properties["IsLocked"]));
doorVariant.RequiredPermissions = new DoorPermissionsPolicy(
(DoorPermissionFlags)Convert.ToUInt16(Properties["RequiredPermissions"]),
Convert.ToBoolean(Properties["RequireAll"]));
return doorVariant.gameObject;
}

private GameObject CreateText()
{
TextToy text = GameObject.Instantiate(PrefabManager.Text);
Expand Down