1
0

EditDecalCommand.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Numerics;
  2. using Content.Server.Administration;
  3. using Content.Shared.Administration;
  4. using Robust.Shared.Console;
  5. using Robust.Shared.Map.Components;
  6. namespace Content.Server.Decals;
  7. [AdminCommand(AdminFlags.Mapping)]
  8. public sealed class EditDecalCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _entManager = default!;
  11. public string Command => "editdecal";
  12. public string Description => "Edits a decal.";
  13. public string Help => $@"{Command} <gridId> <uid> <mode>\n
  14. Possible modes are:\n
  15. - position <x position> <y position>\n
  16. - color <color>\n
  17. - id <id>\n
  18. - rotation <degrees>\n
  19. - zindex <zIndex>\n
  20. - clean <cleanable>
  21. ";
  22. public void Execute(IConsoleShell shell, string argStr, string[] args)
  23. {
  24. if (args.Length < 4)
  25. {
  26. shell.WriteError("Expected at least 5 arguments.");
  27. return;
  28. }
  29. if (!NetEntity.TryParse(args[0], out var gridIdNet) || !_entManager.TryGetEntity(gridIdNet, out var gridId))
  30. {
  31. shell.WriteError($"Failed parsing gridId '{args[3]}'.");
  32. return;
  33. }
  34. if (!uint.TryParse(args[1], out var uid))
  35. {
  36. shell.WriteError($"Failed parsing uid '{args[1]}'.");
  37. return;
  38. }
  39. if (!_entManager.HasComponent<MapGridComponent>(gridId))
  40. {
  41. shell.WriteError($"No grid with gridId {gridId} exists.");
  42. return;
  43. }
  44. var decalSystem = _entManager.System<DecalSystem>();
  45. switch (args[2].ToLower())
  46. {
  47. case "position":
  48. if(args.Length != 5)
  49. {
  50. shell.WriteError("Expected 6 arguments.");
  51. return;
  52. }
  53. if (!float.TryParse(args[3], out var x) || !float.TryParse(args[4], out var y))
  54. {
  55. shell.WriteError("Failed parsing position.");
  56. return;
  57. }
  58. if (!decalSystem.SetDecalPosition(gridId.Value, uid, new(gridId.Value, new Vector2(x, y))))
  59. {
  60. shell.WriteError("Failed changing decalposition.");
  61. }
  62. break;
  63. case "color":
  64. if(args.Length != 4)
  65. {
  66. shell.WriteError("Expected 5 arguments.");
  67. return;
  68. }
  69. if (!Color.TryFromName(args[3], out var color))
  70. {
  71. shell.WriteError("Failed parsing color.");
  72. return;
  73. }
  74. if (!decalSystem.SetDecalColor(gridId.Value, uid, color))
  75. {
  76. shell.WriteError("Failed changing decal color.");
  77. }
  78. break;
  79. case "id":
  80. if(args.Length != 4)
  81. {
  82. shell.WriteError("Expected 5 arguments.");
  83. return;
  84. }
  85. if (!decalSystem.SetDecalId(gridId.Value, uid, args[3]))
  86. {
  87. shell.WriteError("Failed changing decal id.");
  88. }
  89. break;
  90. case "rotation":
  91. if(args.Length != 4)
  92. {
  93. shell.WriteError("Expected 5 arguments.");
  94. return;
  95. }
  96. if (!double.TryParse(args[3], out var degrees))
  97. {
  98. shell.WriteError("Failed parsing degrees.");
  99. return;
  100. }
  101. if (!decalSystem.SetDecalRotation(gridId.Value, uid, Angle.FromDegrees(degrees)))
  102. {
  103. shell.WriteError("Failed changing decal rotation.");
  104. }
  105. break;
  106. case "zindex":
  107. if(args.Length != 4)
  108. {
  109. shell.WriteError("Expected 5 arguments.");
  110. return;
  111. }
  112. if (!int.TryParse(args[3], out var zIndex))
  113. {
  114. shell.WriteError("Failed parsing zIndex.");
  115. return;
  116. }
  117. if (!decalSystem.SetDecalZIndex(gridId.Value, uid, zIndex))
  118. {
  119. shell.WriteError("Failed changing decal zIndex.");
  120. }
  121. break;
  122. case "clean":
  123. if(args.Length != 4)
  124. {
  125. shell.WriteError("Expected 5 arguments.");
  126. return;
  127. }
  128. if (!bool.TryParse(args[3], out var cleanable))
  129. {
  130. shell.WriteError("Failed parsing cleanable.");
  131. return;
  132. }
  133. if (!decalSystem.SetDecalCleanable(gridId.Value, uid, cleanable))
  134. {
  135. shell.WriteError("Failed changing decal cleanable flag.");
  136. }
  137. break;
  138. default:
  139. shell.WriteError("Invalid mode.");
  140. return;
  141. }
  142. }
  143. }