Skip to content

Commit

Permalink
Merge branch 'master' into fast_world_contents
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle authored Sep 21, 2023
2 parents 7887b15 + 90fce27 commit 5aa7584
Show file tree
Hide file tree
Showing 31 changed files with 373 additions and 117 deletions.
7 changes: 7 additions & 0 deletions Content.Tests/DMProject/Tests/Math/trig.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/proc/RunTest()
ASSERT(arctan(0) == 0)
ASSERT(arctan(1) == 45)
ASSERT(arctan(sqrt(3)) == 60)
ASSERT(round(arctan(3, 4)) == round(53.1301)) //that float precision tho
ASSERT(arctan(-1, 1) == 135)
ASSERT(arctan(0, -5) == -90)
39 changes: 39 additions & 0 deletions Content.Tests/DMProject/Tests/Text/StringInterpolation9.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/datum/thing
var/name = "thing"

/datum/Thing
var/name = "Thing"

/datum/proper_thing
var/name = "\proper thing"

/datum/plural_things
var/name = "things"
var/gender = PLURAL

/proc/RunTest()
// Lowercase \a on datums
ASSERT("\a [new /datum/thing]" == "a thing")
ASSERT("\a [new /datum/Thing]" == "Thing")
ASSERT("\a [new /datum/proper_thing]" == "thing")
ASSERT("\a [new /datum/plural_things]" == "some things")

// Uppercase \A on datums
ASSERT("\A [new /datum/thing]" == "A thing")
ASSERT("\A [new /datum/Thing]" == "Thing")
ASSERT("\A [new /datum/proper_thing]" == "thing")
ASSERT("\A [new /datum/plural_things]" == "Some things")

// Lowercase \a on strings
ASSERT("\a ["thing"]" == "a thing")
ASSERT("\a ["Thing"]" == "Thing")
ASSERT("\a ["\proper thing"]" == "thing")

// Uppercase \A on strings
ASSERT("\A ["thing"]" == "A thing")
ASSERT("\A ["Thing"]" == "Thing")
ASSERT("\A ["\proper thing"]" == "thing")

// Invalid \a
ASSERT("\a [123]" == "")
ASSERT("\A [123]" == "")
20 changes: 20 additions & 0 deletions Content.Tests/DMProject/Tests/Text/findlasttext.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/proc/RunTest()
ASSERT(findlasttext("abcdefg", "f", 0, -1) == 0)
ASSERT(findlasttext("abcdefg", "f", 0, -2) == 6)
ASSERT(findlasttext("abcdefg", "f", 6) == 6)
ASSERT(findlasttext("abcdefg", "f", 5) == 0)
ASSERT(findlasttext("abcdefg", "bc", 2) == 2)
ASSERT(findlasttext("abcdefg", "ab", 10) == 1)
ASSERT(findlasttext("abcdefg", "f", 5) == 0)
ASSERT(findlasttext("Banana", "na", -3) == 3)
ASSERT(findlasttext("Banana", "na", -5) == 0)
ASSERT(findlasttext("Banana", "na", 0) == 5)
ASSERT(findlasttext("Banana", "na", 3) == 3)
ASSERT(findlasttext("Banana", "na", 2) == 0)
ASSERT(findlasttext("Banana", "na", 5) == 5)
ASSERT(findlasttext("Banana", "na", 50) == 5)
ASSERT(findlasttext("Banana", "na", -50) == 0)
ASSERT(findlasttext("abcdefg", "f", 6, -50) == 6)
ASSERT(findlasttext("abcdefg", "f", 6, 50) == 0)


15 changes: 14 additions & 1 deletion DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,20 @@ public DMASTFile File() {
if (expression != null) {
switch (expression) {
case DMASTIdentifier identifier:
Check(TokenType.DM_Colon);
// This could be a sleep without parentheses
if (!Check(TokenType.DM_Colon) && !leadingColon && identifier.Identifier == "sleep") {
var procIdentifier = new DMASTCallableProcIdentifier(expression.Location, "sleep");
var sleepTime = Expression();
if (sleepTime == null) // The argument is optional
sleepTime = new DMASTConstantNull(Location.Internal);

// TODO: Make sleep an opcode
expression = new DMASTProcCall(expression.Location, procIdentifier,
new[] { new DMASTCallParameter(sleepTime.Location, sleepTime) });
break;
}

// But it was a label
return Label(identifier);
case DMASTRightShift rightShift:
// A right shift on its own becomes a special "input" statement
Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DMStandard/Types/Atoms/Mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
var/sight = 0
var/see_in_dark = 2 as opendream_unimplemented

density = TRUE
layer = MOB_LAYER

proc/Login()
Expand Down
4 changes: 3 additions & 1 deletion OpenDreamClient/Input/MouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal sealed class MouseInputSystem : SharedMouseInputSystem {
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
[Dependency] private IEntityManager _entityManager = default!;

private DreamViewOverlay? _dreamViewOverlay;
private ContextMenuPopup _contextMenu = default!;
Expand Down Expand Up @@ -87,7 +88,8 @@ public bool HandleViewportClick(ScalingViewport viewport, GUIBoundKeyEventArgs a

// TODO: Take icon transformations into account
Vector2i iconPosition = (Vector2i) ((mapCoords.Position - entity.Position) * EyeManager.PixelsPerMeter);
RaiseNetworkEvent(new EntityClickedEvent(entity.ClickUid, screenLoc, middle, shift, ctrl, alt, iconPosition));
NetEntity ent = _entityManager.GetNetEntity(entity.ClickUid);
RaiseNetworkEvent(new EntityClickedEvent(ent, screenLoc, middle, shift, ctrl, alt, iconPosition));
return true;
}

Expand Down
1 change: 1 addition & 0 deletions OpenDreamClient/Interface/Controls/ScalingViewport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Utility;
using SixLabors.ImageSharp.PixelFormats;
Expand Down
96 changes: 96 additions & 0 deletions OpenDreamClient/Interface/DebugWindows/MacrosWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using OpenDreamClient.Input;
using OpenDreamClient.Interface.Prompts;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Console;

namespace OpenDreamClient.Interface.DebugWindows;

/// <summary>
/// A debug window that displays all the current macro sets and allows you to execute them
/// </summary>
public sealed class MacrosWindow : OSWindow {
[Dependency] private readonly IDreamInterfaceManager _interfaceManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
private readonly DreamCommandSystem _commandSystem;

public MacrosWindow() {
IoCManager.InjectDependencies(this);
_commandSystem = _entitySystemManager.GetEntitySystem<DreamCommandSystem>();

Title = "Macros";
SizeToContent = WindowSizeToContent.WidthAndHeight;

var tabs = new TabContainer();

foreach (var macroSet in _interfaceManager.MacroSets.Values) {
var isCurrent = (macroSet == _interfaceManager.DefaultWindow?.Macro);
var tabName = macroSet.Id;
if (isCurrent)
tabName += " (Current)";

var macroTable = CreateMacroTable(macroSet);
TabContainer.SetTabTitle(macroTable, tabName);
tabs.AddChild(macroTable);

if (isCurrent)
tabs.CurrentTab = tabs.ChildCount - 1;
}

AddChild(tabs);
}

private GridContainer CreateMacroTable(InterfaceMacroSet macroSet) {
var macroTable = new GridContainer {
Columns = 3,
Margin = new(5)
};

foreach (var macro in macroSet.Macros.Values) {
var idText = macro.Id;
if (macro.ElementDescriptor.Name != idText)
idText += $" ({macro.ElementDescriptor.Name})";

var idLabel = new Label { Text = idText };
var commandLabel = new Label { Text = macro.Command };
var executeButton = new Button { Text = "Execute" };

executeButton.OnPressed += _ => {
if (macro.Command.Contains("[[*]]")) {
var prompt = new TextPrompt("Key", "What key?", string.Empty, true, (_, value) => {
if (value == null)
return; // Cancelled

_commandSystem.RunCommand(macro.Command.Replace("[[*]]", (string)value));
});

prompt.Owner = ClydeWindow;
prompt.Show();
} else {
_commandSystem.RunCommand(macro.Command);
}
};

macroTable.AddChild(idLabel);
macroTable.AddChild(commandLabel);
macroTable.AddChild(executeButton);
}

return macroTable;
}
}

public sealed class ShowMacrosCommand : IConsoleCommand {
// ReSharper disable once StringLiteralTypo
public string Command => "showmacros";
public string Description => "Display the current macro sets";
public string Help => "";

public void Execute(IConsoleShell shell, string argStr, string[] args) {
if (args.Length != 0) {
shell.WriteError("This command does not take any arguments!");
return;
}

new MacrosWindow().Show();
}
}
14 changes: 14 additions & 0 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using SixLabors.ImageSharp;
using System.Linq;

namespace OpenDreamClient.Interface;

Expand Down Expand Up @@ -374,6 +375,9 @@ public void FrameUpdate(FrameEventArgs frameEventArgs) {
window = Windows[windowId];
} else if (_popupWindows.TryGetValue(windowId, out var popup)) {
window = popup.WindowElement;
} else if (Menus.TryGetValue(windowId, out var menu)) {
if(menu.MenuElements.TryGetValue(elementId, out var menuElement))
return menuElement;
}

if (window != null) {
Expand Down Expand Up @@ -535,6 +539,16 @@ string GetProperty(string elementId) {
// But also have it here in case a local winget ever wants it
case "hwmode":
return "true";
case "windows":
return string.Join(';',
Windows.Where(pair => !((WindowDescriptor)pair.Value.ElementDescriptor).IsPane).Select(pair => pair.Key));
case "panes":
return string.Join(';',
Windows.Where(pair => ((WindowDescriptor)pair.Value.ElementDescriptor).IsPane).Select(pair => pair.Key));
case "menus":
return string.Join(';', Menus.Keys);
case "macros":
return string.Join(';', MacroSets.Keys);
default:
_sawmill.Error($"Special winget \"{queryValue}\" is not implemented");
return string.Empty;
Expand Down
3 changes: 2 additions & 1 deletion OpenDreamClient/Interface/InterfaceMacro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ public static ParsedKeybind Parse(string keybind) {
}

public sealed class InterfaceMacro : InterfaceElement {
public string Command => MacroDescriptor.Command;

private MacroDescriptor MacroDescriptor => (MacroDescriptor)ElementDescriptor;
private string Command => MacroDescriptor.Command;

private readonly IEntitySystemManager _entitySystemManager;
private readonly IUserInterfaceManager _uiManager;
Expand Down
3 changes: 2 additions & 1 deletion OpenDreamClient/Rendering/ClientAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private void OnNewAppearance(NewAppearanceEvent e) {
}

private void OnAnimation(AnimationEvent e) {
if (!_entityManager.TryGetComponent<DMISpriteComponent>(e.Entity, out var sprite))
EntityUid ent = _entityManager.GetEntity(e.Entity);
if (!_entityManager.TryGetComponent<DMISpriteComponent>(ent, out var sprite))
return;

LoadAppearance(e.TargetAppearanceId, targetAppearance => {
Expand Down
14 changes: 8 additions & 6 deletions OpenDreamClient/Rendering/ClientImagesSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public bool TryGetClientImages(EntityUid entity, Vector3? tileCoords, [NotNullWh
}

private void OnAddClientImage(AddClientImageEvent e) {
if(e.AttachedEntity == EntityUid.Invalid) {
EntityUid ent = _entityManager.GetEntity(e.AttachedEntity);
if(ent == EntityUid.Invalid) {
if(!TurfClientImages.TryGetValue(e.TurfCoords, out var iconList))
iconList = new List<int>();
if(!_idToIcon.ContainsKey(e.ImageAppearance)){
Expand All @@ -51,30 +52,31 @@ private void OnAddClientImage(AddClientImageEvent e) {
iconList.Add(e.ImageAppearance);
TurfClientImages[e.TurfCoords] = iconList;
} else {
if(!AMClientImages.TryGetValue(e.AttachedEntity, out var iconList))
if(!AMClientImages.TryGetValue(ent, out var iconList))
iconList = new List<int>();
if(!_idToIcon.ContainsKey(e.ImageAppearance)){
DreamIcon icon = new DreamIcon(e.ImageAppearance);
_idToIcon[e.ImageAppearance] = icon;
}
iconList.Add(e.ImageAppearance);
AMClientImages[e.AttachedEntity] = iconList;
AMClientImages[ent] = iconList;
}

}

private void OnRemoveClientImage(RemoveClientImageEvent e) {
if(e.AttachedEntity == EntityUid.Invalid) {
EntityUid ent = _entityManager.GetEntity(e.AttachedEntity);
if(ent == EntityUid.Invalid) {
if(!TurfClientImages.TryGetValue(e.TurfCoords, out var iconList))
return;
iconList.Remove(e.ImageAppearance);
TurfClientImages[e.TurfCoords] = iconList;
_idToIcon.Remove(e.ImageAppearance);
} else {
if(!AMClientImages.TryGetValue(e.AttachedEntity, out var iconList))
if(!AMClientImages.TryGetValue(ent, out var iconList))
return;
iconList.Remove(e.ImageAppearance);
AMClientImages[e.AttachedEntity] = iconList;
AMClientImages[ent] = iconList;
_idToIcon.Remove(e.ImageAppearance);
}
}
Expand Down
6 changes: 4 additions & 2 deletions OpenDreamClient/Rendering/ClientScreenOverlaySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public override void Shutdown() {
}

private void OnAddScreenObject(AddScreenObjectEvent e) {
ScreenObjects.Add(e.ScreenObject);
EntityUid ent = _entityManager.GetEntity(e.ScreenObject);
ScreenObjects.Add(ent);
}

private void OnRemoveScreenObject(RemoveScreenObjectEvent e) {
ScreenObjects.Remove(e.ScreenObject);
EntityUid ent = _entityManager.GetEntity(e.ScreenObject);
ScreenObjects.Remove(ent);
}
}
}
5 changes: 3 additions & 2 deletions OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,11 @@ private void ProcessIconComponents(DreamIcon icon, Vector2 position, EntityUid u
}

foreach (var visContent in icon.Appearance.VisContents) {
if (!_spriteQuery.TryGetComponent(visContent, out var sprite))
EntityUid visContentEntity = _entityManager.GetEntity(visContent);
if (!_spriteQuery.TryGetComponent(visContentEntity, out var sprite))
continue;

ProcessIconComponents(sprite.Icon, position, visContent, false, ref tieBreaker, result, current, keepTogether);
ProcessIconComponents(sprite.Icon, position, visContentEntity, false, ref tieBreaker, result, current, keepTogether);

// TODO: click uid should be set to current.uid again
// TODO: vis_flags
Expand Down
4 changes: 3 additions & 1 deletion OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ public void AnimateAppearance(DreamObjectAtom atom, TimeSpan duration, Action<Ic
// Don't send the updated appearance to clients, they will animate it
movable.SpriteComponent.SetAppearance(appearance, dirty: false);

AppearanceSystem.Animate(movable.Entity, appearance, duration);
NetEntity ent = _entityManager.GetNetEntity(movable.Entity);

AppearanceSystem.Animate(ent, appearance, duration);
}

public bool TryCreateAppearanceFrom(DreamValue value, [NotNullWhen(true)] out IconAppearance? appearance) {
Expand Down
18 changes: 9 additions & 9 deletions OpenDreamRuntime/DreamConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ public void HandleCommand(string fullCommand) {

switch (command) {
//TODO: Maybe move these verbs to DM code?
case ".north": Client?.SpawnProc("North"); break;
case ".east": Client?.SpawnProc("East"); break;
case ".south": Client?.SpawnProc("South"); break;
case ".west": Client?.SpawnProc("West"); break;
case ".northeast": Client?.SpawnProc("Northeast"); break;
case ".southeast": Client?.SpawnProc("Southeast"); break;
case ".southwest": Client?.SpawnProc("Southwest"); break;
case ".northwest": Client?.SpawnProc("Northwest"); break;
case ".center": Client?.SpawnProc("Center"); break;
case ".north": Client?.SpawnProc("North", Mob); break;
case ".east": Client?.SpawnProc("East", Mob); break;
case ".south": Client?.SpawnProc("South", Mob); break;
case ".west": Client?.SpawnProc("West", Mob); break;
case ".northeast": Client?.SpawnProc("Northeast", Mob); break;
case ".southeast": Client?.SpawnProc("Southeast", Mob); break;
case ".southwest": Client?.SpawnProc("Southwest", Mob); break;
case ".northwest": Client?.SpawnProc("Northwest", Mob); break;
case ".center": Client?.SpawnProc("Center", Mob); break;

default: {
if (_availableVerbs.TryGetValue(command, out var value)) {
Expand Down
Loading

0 comments on commit 5aa7584

Please sign in to comment.