Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal78900 committed Jan 21, 2024
2 parents dd5d98c + 6216353 commit 454bfb5
Show file tree
Hide file tree
Showing 37 changed files with 287 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: MapEditorReborn
patreon: # MapEditorReborn
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
Expand Down
80 changes: 76 additions & 4 deletions MapEditorReborn/API/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ namespace MapEditorReborn.API
using Enums;
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.API.Features.Toys;
using Extensions;
using Features;
using Features.Objects;
using Features.Serializable;
using MapGeneration;
using Mirror;
using UnityEngine;

/// <summary>
Expand All @@ -39,8 +42,6 @@ public static class API
/// </summary>
internal static MapSchematic? MapSchematic;

internal static ReadOnlyCollection<RoomType>? RoomTypes;

/// <summary>
/// Gets or sets currently loaded <see cref="MapSchematic"/>.
/// </summary>
Expand All @@ -50,18 +51,50 @@ public static MapSchematic? CurrentLoadedMap
set => MapUtils.LoadMap(value);
}

private static ReadOnlyCollection<RoomType>? _spawnedRoomTypes;
private static ReadOnlyCollection<RoomType>? _nonDistinctRoomTypes;

/// <summary>
/// Gets the readonly list of <see cref="RoomType"/> that spawned this round.
/// </summary>
public static ReadOnlyCollection<RoomType> SpawnedRoomTypes =>
RoomTypes ??= new List<RoomType>(Room.List.Select(x => x.Type).Distinct()).AsReadOnly();
_spawnedRoomTypes; // ??= Room.List.Select(x => x.Type).Distinct().ToList().AsReadOnly();

/// <summary>
/// Gets the readonly list of <see cref="RoomType"/> that spawned this round AND are not distinct (there are multiple rooms of the same type).
/// </summary>
public static ReadOnlyCollection<RoomType> NonDistinctRoomTypes =>
_nonDistinctRoomTypes; // ??= SpawnedRoomTypes.Where(roomType => Room.List.Count(x => x.Type == roomType) > 1).ToList().AsReadOnly();

internal static void PopulateRoomTypeLists()
{
List<RoomType> spawnedRoomTypes = new();
List<RoomType> nonDistinctRoomTypes = new();

foreach (Room room in Room.List)
{
RoomType type = room.Type;
if (!spawnedRoomTypes.Contains(type))
spawnedRoomTypes.Add(type);
}

foreach (RoomType spawnedRoomType in spawnedRoomTypes)
{
if (Room.List.Count(x => x.Type == spawnedRoomType) > 1)
nonDistinctRoomTypes.Add(spawnedRoomType);
}

_spawnedRoomTypes = spawnedRoomTypes.AsReadOnly();
_nonDistinctRoomTypes = nonDistinctRoomTypes.AsReadOnly();
}

/// <summary>
/// Gets the dictionary that stores currently selected <see cref="ObjectType"/> by <see cref="InventorySystem.Items.ItemBase.ItemSerial"/>.
/// </summary>
internal static Dictionary<ushort, ObjectType> ToolGuns { get; private set; } = new();

internal static Dictionary<ushort, GravityGunMode> GravityGuns { get; private set; } = new();

internal static HashSet<ushort> PickupsLocked { get; private set; } = new();

internal static Dictionary<ushort, int> PickupsUsesLeft { get; private set; } = new();
Expand All @@ -76,8 +109,47 @@ public static MapSchematic? CurrentLoadedMap
/// </summary>
public static ReadOnlyDictionary<ObjectType, GameObject> ObjectPrefabs { get; internal set; }

internal static void GetObjectPrefabs()
{
Dictionary<ObjectType, GameObject> objectList = new(21);
DoorSpawnpoint[] doorList = Object.FindObjectsOfType<DoorSpawnpoint>();

objectList.Add(ObjectType.LczDoor, doorList.First(x => x.TargetPrefab.name.Contains("LCZ")).TargetPrefab.gameObject);
objectList.Add(ObjectType.HczDoor, doorList.First(x => x.TargetPrefab.name.Contains("HCZ")).TargetPrefab.gameObject);
objectList.Add(ObjectType.EzDoor, doorList.First(x => x.TargetPrefab.name.Contains("EZ")).TargetPrefab.gameObject);

objectList.Add(ObjectType.WorkStation, NetworkClient.prefabs.Values.First(x => x.name.Contains("Work Station")));

objectList.Add(ObjectType.ItemSpawnPoint, new GameObject("ItemSpawnPointObject"));
objectList.Add(ObjectType.PlayerSpawnPoint, new GameObject("PlayerSpawnPointObject"));
objectList.Add(ObjectType.RagdollSpawnPoint, new GameObject("RagdollSpawnPointObject"));
objectList.Add(ObjectType.DummySpawnPoint, new GameObject("DummySpawnPointObject"));

objectList.Add(ObjectType.SportShootingTarget, ToysHelper.SportShootingTargetObject.gameObject);
objectList.Add(ObjectType.DboyShootingTarget, ToysHelper.DboyShootingTargetObject.gameObject);
objectList.Add(ObjectType.BinaryShootingTarget, ToysHelper.BinaryShootingTargetObject.gameObject);

objectList.Add(ObjectType.Primitive, ToysHelper.PrimitiveBaseObject.gameObject);
objectList.Add(ObjectType.LightSource, ToysHelper.LightBaseObject.gameObject);

objectList.Add(ObjectType.RoomLight, new GameObject("LightControllerObject"));

GameObject teleportPrefab = GameObject.CreatePrimitive(PrimitiveType.Cube);
teleportPrefab.name = "TeleportObject";
objectList.Add(ObjectType.Teleporter, teleportPrefab);

objectList.Add(ObjectType.PedestalLocker, NetworkClient.prefabs.Values.First(x => x.name == "Scp500PedestalStructure Variant"));
objectList.Add(ObjectType.LargeGunLocker, NetworkClient.prefabs.Values.First(x => x.name == "LargeGunLockerStructure"));
objectList.Add(ObjectType.RifleRackLocker, NetworkClient.prefabs.Values.First(x => x.name == "RifleRackStructure"));
objectList.Add(ObjectType.MiscLocker, NetworkClient.prefabs.Values.First(x => x.name == "MiscLocker"));
objectList.Add(ObjectType.MedkitLocker, NetworkClient.prefabs.Values.First(x => x.name == "RegularMedkitStructure"));
objectList.Add(ObjectType.AdrenalineLocker, NetworkClient.prefabs.Values.First(x => x.name == "AdrenalineMedkitStructure"));

ObjectPrefabs = new ReadOnlyDictionary<ObjectType, GameObject>(objectList);
}

/// <summary>
/// Gets or sets a random <see cref="Room"/> from the <see cref="RoomType"/>.
/// Gets a random <see cref="Room"/> from the <see cref="RoomType"/>.
/// </summary>
/// <param name="type">The <see cref="RoomType"/> from which the room should be chosen.</param>
/// <returns>A random <see cref="Room"/> that has <see cref="Room.Type"/> of the argument.</returns>
Expand Down
2 changes: 1 addition & 1 deletion MapEditorReborn/API/Features/MapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static void LoadMap(MapSchematic? map)
foreach (SchematicSerializable schematicObject in map.Schematics)
{
Log.Debug($"Trying to spawn a schematic named \"{schematicObject.SchematicName}\" at {schematicObject.RoomType}... ({schematicObject.Position.x}, {schematicObject.Position.y}, {schematicObject.Position.z})");
MapEditorObject schematic = ObjectSpawner.SpawnSchematic(schematicObject);
MapEditorObject schematic = ObjectSpawner.SpawnSchematic(schematicObject, null, null, null, null, true);

if (schematic == null)
{
Expand Down
26 changes: 21 additions & 5 deletions MapEditorReborn/API/Features/ObjectSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public static T SpawnObject<T>(params object[] args)
return null;
}

return SpawnSchematic(schematicObject, forcedPosition, forcedRotation, forcedScale, data) as T;
bool isStatic = ParseArgument<bool>(5, args);

return SpawnSchematic(schematicObject, forcedPosition, forcedRotation, forcedScale, data, isStatic) as T;
}

case nameof(LockerObject):
Expand Down Expand Up @@ -285,9 +287,21 @@ public static LockerObject SpawnLocker(LockerSerializable locker, Vector3? force
/// <param name="scale">The schematic' scale.</param>
/// <param name="data">The schematic data.</param>
/// <returns>The spawned <see cref="SchematicObject"/>.</returns>
[Obsolete]
public static SchematicObject SpawnSchematic(string schematicName, Vector3 position, Quaternion? rotation = null, Vector3? scale = null, SchematicObjectDataList data = null)
{
return SpawnSchematic(new SchematicSerializable(schematicName), position, rotation, scale, data);
return SpawnSchematic(new SchematicSerializable(schematicName), position, rotation, scale, data, false);
}

public static SchematicObject SpawnSchematic(string schematicName, Vector3 position, Quaternion? rotation = null, Vector3? scale = null, SchematicObjectDataList data = null, bool isStatic = false)
{
return SpawnSchematic(new SchematicSerializable(schematicName), position, rotation, scale, data, isStatic);
}

[Obsolete]
public static SchematicObject SpawnSchematic(SchematicSerializable schematicObject, Vector3? forcedPosition = null, Quaternion? forcedRotation = null, Vector3? forcedScale = null, SchematicObjectDataList data = null)
{
return SpawnSchematic(schematicObject, forcedPosition, forcedRotation, forcedScale, data, false);
}

/// <summary>
Expand All @@ -299,7 +313,7 @@ public static SchematicObject SpawnSchematic(string schematicName, Vector3 posit
/// <param name="forcedScale">Used to force exact object scale.</param>
/// <param name="data">The schematic data.</param>
/// <returns>The spawned <see cref="SchematicObject"/>.</returns>
public static SchematicObject SpawnSchematic(SchematicSerializable schematicObject, Vector3? forcedPosition = null, Quaternion? forcedRotation = null, Vector3? forcedScale = null, SchematicObjectDataList data = null)
public static SchematicObject SpawnSchematic(SchematicSerializable schematicObject, Vector3? forcedPosition = null, Quaternion? forcedRotation = null, Vector3? forcedScale = null, SchematicObjectDataList data = null, bool isStatic = false)
{
if (data == null)
{
Expand All @@ -325,8 +339,10 @@ public static SchematicObject SpawnSchematic(SchematicSerializable schematicObje
},
};

SchematicObject schematicObjectComponent = gameObject.AddComponent<SchematicObject>().Init(schematicObject, data);
SchematicObject schematicObjectComponent = gameObject.AddComponent<SchematicObject>().Init(schematicObject, data, isStatic);
gameObject.transform.localScale = forcedScale ?? schematicObject.Scale;
if (schematicObjectComponent.IsStatic)
schematicObjectComponent.UpdateObject();

SchematicSpawnedEventArgs ev = new SchematicSpawnedEventArgs(schematicObjectComponent, schematicObject.SchematicName);
Schematic.OnSchematicSpawned(ev);
Expand Down Expand Up @@ -357,7 +373,7 @@ public static MapEditorObject SpawnPropertyObject(Vector3 position, MapEditorObj
ShootingTargetObject shootingTarget => SpawnShootingTarget(new ShootingTargetSerializable().CopyProperties(shootingTarget.Base), position, rotation, scale),
PrimitiveObject primitive => SpawnPrimitive(new PrimitiveSerializable().CopyProperties(primitive.Base), position + (Vector3.up * 0.5f), rotation, scale),
LockerObject locker => SpawnLocker(new LockerSerializable().CopyProperties(locker.Base), position, rotation, scale),
SchematicObject schematic => SpawnSchematic(new SchematicSerializable().CopyProperties(schematic.Base), position, rotation, scale),
SchematicObject schematic => SpawnSchematic(new SchematicSerializable().CopyProperties(schematic.Base), position, rotation, scale, isStatic: true),
_ => null,
};
}
Expand Down
21 changes: 18 additions & 3 deletions MapEditorReborn/API/Features/Objects/LightSourceObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ private void Awake()
public LightSourceObject Init(LightSourceSerializable lightSourceSerializable, bool spawn = true)
{
Base = lightSourceSerializable;
Light.MovementSmoothing = 60;
// Light.MovementSmoothing = 60;

ForcedRoomType = lightSourceSerializable.RoomType != RoomType.Unknown ? lightSourceSerializable.RoomType : FindRoom().Type;
UpdateObject();

if (spawn)
NetworkServer.Spawn(gameObject);

_lightSourceToy.enabled = false;
IsStatic = false;

return this;
}
Expand All @@ -56,9 +56,11 @@ public override MapEditorObject Init(SchematicBlockData block)
base.Init(block);

Base = new(block);
Light.MovementSmoothing = 60;
// Light.MovementSmoothing = 60;

UpdateObject();
IsStatic = true;
// _lightSourceToy.enabled = false;

return this;
}
Expand All @@ -82,6 +84,17 @@ public Light Light
}
}

public bool IsStatic
{
get => _isStatic;
set
{
_lightSourceToy.enabled = !value;
Light.MovementSmoothing = (byte)(value ? 0 : 60);
_isStatic = value;
}
}

/// <inheritdoc cref="MapEditorObject.IsRotatable"/>
public override bool IsRotatable => false;

Expand Down Expand Up @@ -122,5 +135,7 @@ private void UpdateTransformProperties()
{
_lightSourceToy.NetworkPosition = _transform.position;
}

private bool _isStatic;
}
}
25 changes: 19 additions & 6 deletions MapEditorReborn/API/Features/Objects/PrimitiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace MapEditorReborn.API.Features.Objects
public class PrimitiveObject : MapEditorObject
{
private Transform _transform;
private Rigidbody _rigidbody;
private Rigidbody? _rigidbody;
private PrimitiveObjectToy _primitiveObjectToy;
private Primitive _exiledPrimitive;
private Primitive? _exiledPrimitive;

private void Awake()
{
Expand All @@ -37,13 +37,13 @@ private void Awake()
public PrimitiveObject Init(PrimitiveSerializable primitiveSerializable)
{
Base = primitiveSerializable;
Primitive.MovementSmoothing = 60;
// Primitive.MovementSmoothing = 60;
_prevScale = transform.localScale;

ForcedRoomType = primitiveSerializable.RoomType == RoomType.Unknown ? FindRoom().Type : primitiveSerializable.RoomType;

UpdateObject();
_primitiveObjectToy.enabled = false;
IsStatic = false;

return this;
}
Expand All @@ -53,9 +53,10 @@ public override MapEditorObject Init(SchematicBlockData block)
base.Init(block);

Base = new(block);
Primitive.MovementSmoothing = 60;
// Primitive.MovementSmoothing = 60;

UpdateObject();
IsStatic = true;

return this;
}
Expand All @@ -78,12 +79,23 @@ public Rigidbody Rigidbody
return _rigidbody;

if (TryGetComponent(out _rigidbody))
return _rigidbody;
return _rigidbody!;

return _rigidbody = gameObject.AddComponent<Rigidbody>();
}
}

public bool IsStatic
{
get => _isStatic;
set
{
_primitiveObjectToy.enabled = !value;
Primitive.MovementSmoothing = (byte)(value ? 0 : 60);
_isStatic = value;
}
}

/// <inheritdoc cref="MapEditorObject.UpdateObject()"/>
public override void UpdateObject()
{
Expand Down Expand Up @@ -113,6 +125,7 @@ private void UpdateTransformProperties()
_primitiveObjectToy.NetworkScale = _transform.root != _transform ? Vector3.Scale(_transform.localScale, _transform.root.localScale) : _transform.localScale;
}

private bool _isStatic;
private Vector3 _prevScale;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="RagdollSpawnPointObject.cs" company="MapEditorReborn">
// Copyright (c) MapEditorReborn. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
Expand All @@ -10,6 +10,7 @@ namespace MapEditorReborn.API.Features.Objects
using System.Collections.Generic;
using Exiled.API.Enums;
using Exiled.API.Features;
using PlayerRoles.Ragdolls;
using PlayerStatsSystem;
using Serializable;
using UnityEngine;
Expand Down Expand Up @@ -84,4 +85,4 @@ private void OnDestroy()
/// </summary>
public Ragdoll AttachedRagdoll;
}
}
}
Loading

0 comments on commit 454bfb5

Please sign in to comment.