decal system & crayons (#5183)
Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
This commit is contained in:
118
Content.Server/Decals/Commands/AddDecalCommand.cs
Normal file
118
Content.Server/Decals/Commands/AddDecalCommand.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Decals;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Decals.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class AddDecalCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "adddecal";
|
||||
public string Description => "Creates a decal on the map";
|
||||
public string Help => $"{Command} <id> <x position> <y position> <gridId> [angle=<angle> zIndex=<zIndex> color=<color>]";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 4 || args.Length > 7)
|
||||
{
|
||||
shell.WriteError($"Received invalid amount of arguments arguments. Expected 4 to 7, got {args.Length}.\nUsage: {Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IPrototypeManager>().HasIndex<DecalPrototype>(args[0]))
|
||||
{
|
||||
shell.WriteError($"Cannot find decalprototype '{args[0]}'.");
|
||||
}
|
||||
|
||||
if (!float.TryParse(args[1], out var x))
|
||||
{
|
||||
shell.WriteError($"Failed parsing x-coordinate '{args[1]}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!float.TryParse(args[2], out var y))
|
||||
{
|
||||
shell.WriteError($"Failed parsing y-coordinate'{args[2]}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
if (!int.TryParse(args[3], out var gridIdRaw) || !mapManager.TryGetGrid(new GridId(gridIdRaw), out var grid))
|
||||
{
|
||||
shell.WriteError($"Failed parsing gridId '{args[3]}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
var coordinates = new EntityCoordinates(grid.GridEntityId, new Vector2(x, y));
|
||||
if (grid.GetTileRef(coordinates).IsSpace())
|
||||
{
|
||||
shell.WriteError($"Cannot create decal on space tile at {coordinates}.");
|
||||
return;
|
||||
}
|
||||
|
||||
Color? color = null;
|
||||
var zIndex = 0;
|
||||
Angle? rotation = null;
|
||||
if (args.Length > 4)
|
||||
{
|
||||
for (int i = 4; i < args.Length; i++)
|
||||
{
|
||||
var rawValue = args[i].Split('=');
|
||||
if (rawValue.Length != 2)
|
||||
{
|
||||
shell.WriteError($"Failed parsing parameter: '{args[i]}'");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rawValue[0])
|
||||
{
|
||||
case "angle":
|
||||
if (!double.TryParse(rawValue[1], out var degrees))
|
||||
{
|
||||
shell.WriteError($"Failed parsing angle '{rawValue[1]}'.");
|
||||
return;
|
||||
}
|
||||
rotation = Angle.FromDegrees(degrees);
|
||||
break;
|
||||
case "zIndex":
|
||||
if (!int.TryParse(rawValue[1], out zIndex))
|
||||
{
|
||||
shell.WriteError($"Failed parsing zIndex '{rawValue[1]}'.");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "color":
|
||||
if (!Color.TryFromName(rawValue[1], out var colorRaw))
|
||||
{
|
||||
shell.WriteError($"Failed parsing color '{rawValue[1]}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
color = colorRaw;
|
||||
break;
|
||||
default:
|
||||
shell.WriteError($"Unknown parameter key '{rawValue[0]}'.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(EntitySystem.Get<DecalSystem>().TryAddDecal(args[0], coordinates, out var uid, color, rotation, zIndex))
|
||||
{
|
||||
shell.WriteLine($"Successfully created decal {uid}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
shell.WriteError($"Failed adding decal.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
162
Content.Server/Decals/Commands/EditDecalCommand.cs
Normal file
162
Content.Server/Decals/Commands/EditDecalCommand.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.Decals;
|
||||
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public class EditDecalCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "editdecal";
|
||||
public string Description => "Edits a decal.";
|
||||
public string Help => $@"{Command} <gridId> <uid> <mode>\n
|
||||
Possible modes are:\n
|
||||
- position <x position> <y position>\n
|
||||
- color <color>\n
|
||||
- id <id>\n
|
||||
- rotation <degrees>\n
|
||||
- zindex <zIndex>\n
|
||||
- clean <cleanable>
|
||||
";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 4)
|
||||
{
|
||||
shell.WriteError("Expected at least 5 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var gridIdRaw))
|
||||
{
|
||||
shell.WriteError($"Failed parsing gridId '{args[3]}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uint.TryParse(args[1], out var uid))
|
||||
{
|
||||
shell.WriteError($"Failed parsing uid '{args[1]}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
var gridId = new GridId(gridIdRaw);
|
||||
if (!IoCManager.Resolve<IMapManager>().GridExists(gridId))
|
||||
{
|
||||
shell.WriteError($"No grid with gridId {gridId} exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
var decalSystem = EntitySystem.Get<DecalSystem>();
|
||||
switch (args[2].ToLower())
|
||||
{
|
||||
case "position":
|
||||
if(args.Length != 5)
|
||||
{
|
||||
shell.WriteError("Expected 6 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!float.TryParse(args[3], out var x) || !float.TryParse(args[4], out var y))
|
||||
{
|
||||
shell.WriteError("Failed parsing position.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalPosition(gridId, uid, gridId, new Vector2(x, y)))
|
||||
{
|
||||
shell.WriteError("Failed changing decalposition.");
|
||||
}
|
||||
break;
|
||||
case "color":
|
||||
if(args.Length != 4)
|
||||
{
|
||||
shell.WriteError("Expected 5 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Color.TryFromName(args[3], out var color))
|
||||
{
|
||||
shell.WriteError("Failed parsing color.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalColor(gridId, uid, color))
|
||||
{
|
||||
shell.WriteError("Failed changing decal color.");
|
||||
}
|
||||
break;
|
||||
case "id":
|
||||
if(args.Length != 4)
|
||||
{
|
||||
shell.WriteError("Expected 5 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalId(gridId, uid, args[3]))
|
||||
{
|
||||
shell.WriteError("Failed changing decal id.");
|
||||
}
|
||||
break;
|
||||
case "rotation":
|
||||
if(args.Length != 4)
|
||||
{
|
||||
shell.WriteError("Expected 5 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!double.TryParse(args[3], out var degrees))
|
||||
{
|
||||
shell.WriteError("Failed parsing degrees.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalRotation(gridId, uid, Angle.FromDegrees(degrees)))
|
||||
{
|
||||
shell.WriteError("Failed changing decal rotation.");
|
||||
}
|
||||
break;
|
||||
case "zindex":
|
||||
if(args.Length != 4)
|
||||
{
|
||||
shell.WriteError("Expected 5 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[3], out var zIndex))
|
||||
{
|
||||
shell.WriteError("Failed parsing zIndex.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalZIndex(gridId, uid, zIndex))
|
||||
{
|
||||
shell.WriteError("Failed changing decal zIndex.");
|
||||
}
|
||||
break;
|
||||
case "clean":
|
||||
if(args.Length != 4)
|
||||
{
|
||||
shell.WriteError("Expected 5 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bool.TryParse(args[3], out var cleanable))
|
||||
{
|
||||
shell.WriteError("Failed parsing cleanable.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!decalSystem.SetDecalCleanable(gridId, uid, cleanable))
|
||||
{
|
||||
shell.WriteError("Failed changing decal cleanable flag.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
shell.WriteError("Invalid mode.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Content.Server/Decals/Commands/RemoveDecalCommand.cs
Normal file
46
Content.Server/Decals/Commands/RemoveDecalCommand.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Decals.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Mapping)]
|
||||
public class RemoveDecalCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "rmdecal";
|
||||
public string Description => "removes a decal";
|
||||
public string Help => $"{Command} <uid> <gridId>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.WriteError($"Unexpected number of arguments.\nExpected two: {Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uint.TryParse(args[0], out var uid))
|
||||
{
|
||||
shell.WriteError($"Failed parsing uid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[1], out var rawGridId) ||
|
||||
!IoCManager.Resolve<IMapManager>().GridExists(new GridId(rawGridId)))
|
||||
{
|
||||
shell.WriteError("Failed parsing gridId.");
|
||||
}
|
||||
|
||||
var decalSystem = EntitySystem.Get<DecalSystem>();
|
||||
if (decalSystem.RemoveDecal(new GridId(rawGridId), uid))
|
||||
{
|
||||
shell.WriteLine($"Successfully removed decal {uid}.");
|
||||
return;
|
||||
}
|
||||
|
||||
shell.WriteError($"Failed trying to remove decal {uid}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user