mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Change DrawDepth to int, add content constant hook (#1090)
This allows DrawDepth to be defined in the content layer.
This commit is contained in:
@@ -65,7 +65,7 @@ namespace Robust.Client.GameObjects
|
||||
}
|
||||
|
||||
var component = Owner.GetComponent<IClickTargetComponent>();
|
||||
drawdepth = (int)component.DrawDepth;
|
||||
drawdepth = component.DrawDepth;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
using Robust.Shared.GameObjects.Components.Renderable;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -38,13 +39,13 @@ namespace Robust.Client.GameObjects
|
||||
set => _visible = value;
|
||||
}
|
||||
|
||||
private DrawDepth drawDepth = DrawDepth.Objects;
|
||||
private int drawDepth = DrawDepthTag.Default;
|
||||
|
||||
/// <summary>
|
||||
/// Z-index for drawing.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public DrawDepth DrawDepth
|
||||
public int DrawDepth
|
||||
{
|
||||
get => drawDepth;
|
||||
set => drawDepth = value;
|
||||
@@ -1106,7 +1107,7 @@ namespace Robust.Client.GameObjects
|
||||
serializer.DataFieldCached(ref scale, "scale", Vector2.One);
|
||||
serializer.DataFieldCached(ref rotation, "rotation", Angle.Zero);
|
||||
serializer.DataFieldCached(ref offset, "offset", Vector2.Zero);
|
||||
serializer.DataFieldCached(ref drawDepth, "drawdepth", DrawDepth.Objects);
|
||||
serializer.DataFieldCached(ref drawDepth, "drawdepth", DrawDepthTag.Default, WithFormat.Constants<DrawDepthTag>());
|
||||
serializer.DataFieldCached(ref color, "color", Color.White);
|
||||
serializer.DataFieldCached(ref _directional, "directional", true);
|
||||
serializer.DataFieldCached(ref _visible, "visible", true);
|
||||
|
||||
@@ -993,7 +993,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var a = _drawList[x].Item1;
|
||||
var b = _drawList[y].Item1;
|
||||
|
||||
var cmp = ((int) a.DrawDepth).CompareTo((int) b.DrawDepth);
|
||||
var cmp = (a.DrawDepth).CompareTo(b.DrawDepth);
|
||||
if (cmp != 0)
|
||||
{
|
||||
return cmp;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Robust.Client.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// Z-index for drawing.
|
||||
/// </summary>
|
||||
DrawDepth DrawDepth { get; set; }
|
||||
int DrawDepth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A scale applied to all layers.
|
||||
|
||||
@@ -10,6 +10,6 @@ namespace Robust.Client.Interfaces.GameObjects
|
||||
/// </summary>
|
||||
public interface IClickTargetComponent : IComponent
|
||||
{
|
||||
DrawDepth DrawDepth { get; }
|
||||
int DrawDepth { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Robust.Client.Interfaces.GameObjects
|
||||
{
|
||||
public interface IRenderableComponent : IComponent
|
||||
{
|
||||
DrawDepth DrawDepth { get; set; }
|
||||
int DrawDepth { get; set; }
|
||||
float Bottom { get; }
|
||||
Box2 LocalAABB { get; }
|
||||
Box2 AverageAABB { get; }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
using Robust.Shared.GameObjects.Components.Renderable;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -17,7 +18,7 @@ namespace Robust.Server.GameObjects
|
||||
private List<PrototypeLayerData> Layers = new List<PrototypeLayerData>();
|
||||
|
||||
private bool _visible;
|
||||
private DrawDepth _drawDepth = DrawDepth.Objects;
|
||||
private int _drawDepth = DrawDepthTag.Default;
|
||||
private Vector2 _scale;
|
||||
private Vector2 _offset;
|
||||
private Color _color;
|
||||
@@ -26,7 +27,7 @@ namespace Robust.Server.GameObjects
|
||||
private Angle _rotation;
|
||||
|
||||
[ViewVariables]
|
||||
public DrawDepth DrawDepth
|
||||
public int DrawDepth
|
||||
{
|
||||
get => _drawDepth;
|
||||
set
|
||||
@@ -390,7 +391,7 @@ namespace Robust.Server.GameObjects
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataFieldCached(ref _visible, "visible", true);
|
||||
serializer.DataFieldCached(ref _drawDepth, "drawdepth", DrawDepth.Objects);
|
||||
serializer.DataFieldCached(ref _drawDepth, "drawdepth", DrawDepthTag.Default, WithFormat.Constants<DrawDepthTag>());
|
||||
serializer.DataFieldCached(ref _offset, "offset", Vector2.Zero);
|
||||
serializer.DataFieldCached(ref _scale, "scale", Vector2.One);
|
||||
serializer.DataFieldCached(ref _color, "color", Color.White);
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public enum DrawDepth
|
||||
{
|
||||
|
||||
LowFloors = 0,
|
||||
/// <summary>
|
||||
/// Things that are beneath regular floors, such as wires.
|
||||
/// </summary>
|
||||
BelowFloor = 1,
|
||||
FloorTiles = 2,
|
||||
/// <summary>
|
||||
/// Things that are actually right on the floor, like vents.
|
||||
/// </summary>
|
||||
FloorObjects = 3,
|
||||
|
||||
Walls = 4,
|
||||
WallTops = 5,
|
||||
WallMountedItems = 6,
|
||||
Objects = 7,
|
||||
Items = 8,
|
||||
Mobs = 9,
|
||||
Overlays = 10,
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace Robust.Shared.GameObjects.Components.Renderable
|
||||
protected class SpriteComponentState : ComponentState
|
||||
{
|
||||
public readonly bool Visible;
|
||||
public readonly DrawDepth DrawDepth;
|
||||
public readonly int DrawDepth;
|
||||
public readonly Vector2 Scale;
|
||||
public readonly Angle Rotation;
|
||||
public readonly Vector2 Offset;
|
||||
@@ -33,7 +33,7 @@ namespace Robust.Shared.GameObjects.Components.Renderable
|
||||
|
||||
public SpriteComponentState(
|
||||
bool visible,
|
||||
DrawDepth drawDepth,
|
||||
int drawDepth,
|
||||
Vector2 scale,
|
||||
Angle rotation,
|
||||
Vector2 offset,
|
||||
|
||||
18
Robust.Shared/GameObjects/DrawDepth.cs
Normal file
18
Robust.Shared/GameObjects/DrawDepth.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Tag type for defining the representation of rendering draw depth in
|
||||
/// terms of named constants in the content. To understand more about the
|
||||
/// point of this type, see the <see cref="ConstantsForAttribute"/>.
|
||||
/// </summary>
|
||||
public sealed class DrawDepth
|
||||
{
|
||||
/// <summary>
|
||||
/// The default draw depth. The content enum which represents draw depth
|
||||
/// should respect this value, since it is used in the engine.
|
||||
/// </summary>
|
||||
public const int Default = 0;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,24 @@ namespace Robust.Shared.Serialization
|
||||
/// <typeparam name="T">The type of the field that will be read/written.</typeparam>
|
||||
public virtual void DataFieldCached<T>(ref T value, string name, T defaultValue, bool alwaysWrite = false)
|
||||
{
|
||||
DataField(ref value, name, defaultValue, alwaysWrite);
|
||||
DataField(ref value, name, defaultValue, WithFormat<T>.NoFormat, alwaysWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes or reads a simple field by reference.
|
||||
/// This method can cache results and share them with other objects.
|
||||
/// As such, when reading, your value may NOT be private. Do not modify it as if it's purely your own.
|
||||
/// This can cut out parsing steps and memory cost for commonly used objects such as walls.
|
||||
/// </summary>
|
||||
/// <param name="value">The reference to the field that will be read/written into.</param>
|
||||
/// <param name="name">The name of the field in the serialization medium. Most likely the name in YAML.</param>
|
||||
/// <param name="defaultValue">A default value. Used if the field does not exist while reading or to know if writing would be redundant.</param>
|
||||
/// <param name="withFormat">The formatter to use for representing this particular value in the medium.</param>
|
||||
/// <param name="alwaysWrite">If true, always write this field to map saving, even if it matches the default.</param>
|
||||
/// <typeparam name="T">The type of the field that will be read/written.</typeparam>
|
||||
public virtual void DataFieldCached<T>(ref T value, string name, T defaultValue, WithFormat<T> withFormat, bool alwaysWrite = false)
|
||||
{
|
||||
DataField(ref value, name, defaultValue, withFormat, alwaysWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Robust.Shared.Serialization
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DataFieldCached<T>(ref T value, string name, T defaultValue, bool alwaysWrite = false)
|
||||
public override void DataFieldCached<T>(ref T value, string name, T defaultValue, WithFormat<T> format, bool alwaysWrite = false)
|
||||
{
|
||||
if (Reading) // read
|
||||
{
|
||||
@@ -202,7 +202,8 @@ namespace Robust.Shared.Serialization
|
||||
{
|
||||
if (map.TryGetNode(name, out var node))
|
||||
{
|
||||
value = (T)NodeToType(typeof(T), node);
|
||||
var customFormatter = format.GetYamlSerializer();
|
||||
value = (T)customFormatter.NodeToType(typeof(T), node, this);
|
||||
_context?.SetCachedField(name, value);
|
||||
return;
|
||||
}
|
||||
@@ -213,7 +214,7 @@ namespace Robust.Shared.Serialization
|
||||
}
|
||||
else // write
|
||||
{
|
||||
DataField(ref value, name, defaultValue, alwaysWrite);
|
||||
DataField(ref value, name, defaultValue, format, alwaysWrite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user