Skip to content

Commit

Permalink
Merge branch 'master' into Add-checkbox-support-to-menus
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle authored Sep 21, 2023
2 parents 18c1c05 + 90fce27 commit 15ed923
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 112 deletions.
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
3 changes: 3 additions & 0 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,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
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 @@ -344,7 +344,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
4 changes: 3 additions & 1 deletion OpenDreamRuntime/Input/MouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal sealed class MouseInputSystem : SharedMouseInputSystem {
[Dependency] private readonly AtomManager _atomManager = default!;
[Dependency] private readonly DreamManager _dreamManager = default!;
[Dependency] private readonly IDreamMapManager _dreamMapManager = default!;
[Dependency] private IEntityManager _entityManager = default!;

public override void Initialize() {
base.Initialize();
Expand All @@ -20,7 +21,8 @@ public override void Initialize() {
}

private void OnEntityClicked(EntityClickedEvent e, EntitySessionEventArgs sessionEvent) {
if (!_atomManager.TryGetMovableFromEntity(e.EntityUid, out var atom))
EntityUid ent = _entityManager.GetEntity(e.NetEntity);
if (!_atomManager.TryGetMovableFromEntity(ent, out var atom))
return;

HandleAtomClick(e, atom, sessionEvent);
Expand Down
19 changes: 12 additions & 7 deletions OpenDreamRuntime/Objects/DreamObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ public static bool StringIsProper(string str) {
return true;
case StringFormatEncoder.FormatSuffix.Improper:
return false;
default:
break;
}
}

Expand Down Expand Up @@ -312,9 +310,7 @@ public string GetDisplayName(StringFormatEncoder.FormatSuffix? suffix = null) {
if (this is DreamObjectClient client)
return client.Connection.Session!.Name;

if (!TryGetVariable("name", out DreamValue nameVar) || !nameVar.TryGetValueAsString(out string? name))
return ObjectDefinition.Type.ToString();

var name = GetRawName();
bool isProper = StringIsProper(name);
name = StringFormatEncoder.RemoveFormatting(name); // TODO: Care about other formatting macros for obj names beyond \proper & \improper
if(!isProper) {
Expand All @@ -335,9 +331,18 @@ public string GetDisplayName(StringFormatEncoder.FormatSuffix? suffix = null) {
/// Similar to <see cref="GetDisplayName"/> except it just returns the name as plaintext, with formatting removed. No article or anything.
/// </summary>
public string GetNameUnformatted() {
return StringFormatEncoder.RemoveFormatting(GetRawName());
}

/// <summary>
/// Returns the name of this object with no formatting evaluated
/// </summary>
/// <returns></returns>
public string GetRawName() {
if (!TryGetVariable("name", out DreamValue nameVar) || !nameVar.TryGetValueAsString(out string? name))
return ObjectDefinition?.Type.ToString() ?? String.Empty;
return StringFormatEncoder.RemoveFormatting(name);
return ObjectDefinition.Type.ToString();

return name;
}
#endregion Name Helpers

Expand Down
12 changes: 9 additions & 3 deletions OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ public virtual void AddValue(DreamValue value) {

//Does not include associations
public virtual bool ContainsValue(DreamValue value) {
return _values.Contains(value);
for (int i = 0; i < _values.Count; i++) {
if (_values[i].Equals(value))
return true;
}

return false;
}

public virtual bool ContainsKey(DreamValue value) {
Expand Down Expand Up @@ -687,6 +692,7 @@ private IconAppearance GetAppearance() {
// Operates on an atom's appearance
public sealed class DreamVisContentsList : DreamList {
[Dependency] private readonly AtomManager _atomManager = default!;
[Dependency] private IEntityManager _entityManager = default!;
private readonly PvsOverrideSystem? _pvsOverrideSystem;

private readonly List<DreamObjectAtom> _visContents = new();
Expand Down Expand Up @@ -750,7 +756,7 @@ public override void AddValue(DreamValue value) {

_atomManager.UpdateAppearance(_atom, appearance => {
// Add even an invalid UID to keep this and _visContents in sync
appearance.VisContents.Add(entity);
appearance.VisContents.Add(_entityManager.GetNetEntity(entity));
});
}

Expand All @@ -760,7 +766,7 @@ public override void RemoveValue(DreamValue value) {

_visContents.Remove(movable);
_atomManager.UpdateAppearance(_atom, appearance => {
appearance.VisContents.Remove(movable.Entity);
appearance.VisContents.Remove(_entityManager.GetNetEntity(movable.Entity));
});
}

Expand Down
Loading

0 comments on commit 15ed923

Please sign in to comment.