Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement set src = usr.contents #1673

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement set src = usr.contents
  • Loading branch information
wixoaGit committed Feb 14, 2024
commit 2e75001c3c4d187eca84dfaaf3ed503459a895fe
5 changes: 0 additions & 5 deletions DMCompiler/DM/Builders/DMProcBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,13 @@ public void ProcessStatementSet(DMASTProcStatementSet statementSet) {
switch (statementSet.Value) {
case DMASTIdentifier {Identifier: "usr"}:
_proc.VerbSrc = statementSet.WasInKeyword ? VerbSrc.InUsr : VerbSrc.Usr;
if (statementSet.WasInKeyword)
DMCompiler.UnimplementedWarning(statementSet.Location,
"'set src = usr.contents' is unimplemented");
break;
case DMASTDereference {Expression: DMASTIdentifier{Identifier: "usr"}, Operations: var operations}:
if (operations is not [DMASTDereference.FieldOperation {Identifier: var deref}])
goto default;

if (deref == "contents") {
_proc.VerbSrc = VerbSrc.InUsr;
DMCompiler.UnimplementedWarning(statementSet.Location,
"'set src = usr.contents' is unimplemented");
} else if (deref == "loc") {
_proc.VerbSrc = VerbSrc.UsrLoc;
DMCompiler.UnimplementedWarning(statementSet.Location,
Expand Down
11 changes: 8 additions & 3 deletions OpenDreamClient/ClientVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OpenDreamClient.Rendering;
using OpenDreamShared.Dream;
using OpenDreamShared.Rendering;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Asynchronous;
Expand All @@ -17,6 +18,7 @@ public sealed class ClientVerbSystem : VerbSystem {
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly ITimerManager _timerManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;

private EntityQuery<DMISpriteComponent> _spriteQuery;
private EntityQuery<DreamMobSightComponent> _sightQuery;
Expand Down Expand Up @@ -72,12 +74,10 @@ public IEnumerable<VerbInfo> GetAllVerbs() {
/// <param name="ignoreHiddenAttr">Whether to ignore "set hidden = TRUE"</param>
/// <returns>The ID, src, and information of every executable verb</returns>
public IEnumerable<(int Id, ClientObjectReference Src, VerbInfo VerbInfo)> GetExecutableVerbs(bool ignoreHiddenAttr = false) {
ClientObjectReference? ourMob = null;
sbyte? seeInvisibility = null;
if (_playerManager.LocalEntity != null) {
_sightQuery.TryGetComponent(_playerManager.LocalEntity.Value, out var mobSight);

ourMob = new ClientObjectReference(_entityManager.GetNetEntity(_playerManager.LocalEntity.Value));
seeInvisibility = mobSight?.SeeInvisibility;
}

Expand Down Expand Up @@ -112,7 +112,12 @@ public IEnumerable<VerbInfo> GetAllVerbs() {
// Check the verb's "set src" allows us to execute this
switch (verb.Accessibility) {
case VerbAccessibility.Usr:
if (!src.Equals(ourMob))
if (entity != _playerManager.LocalEntity)
continue;

break;
case VerbAccessibility.InUsr:
if (_transformSystem.GetParentUid(entity) != _playerManager.LocalEntity)
continue;

break;
Expand Down
8 changes: 4 additions & 4 deletions OpenDreamRuntime/Objects/Types/DreamObjectMovable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace OpenDreamRuntime.Objects.Types;
public class DreamObjectMovable : DreamObjectAtom {
public EntityUid Entity;
public readonly DMISpriteComponent SpriteComponent;
public DreamObjectAtom? Loc;

// TODO: Cache this shit. GetWorldPosition is slow.
public Vector2i Position => (Vector2i?)TransformSystem?.GetWorldPosition(_transformComponent) ?? (0, 0);
Expand All @@ -18,7 +19,6 @@ public class DreamObjectMovable : DreamObjectAtom {

private readonly TransformComponent _transformComponent;

private DreamObjectAtom? _loc;

private string? ScreenLoc {
get => _screenLoc;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
value = new(Z);
return true;
case "loc":
value = new(_loc);
value = new(Loc);
return true;
case "screen_loc":
value = (ScreenLoc != null) ? new(ScreenLoc) : DreamValue.Null;
Expand All @@ -97,7 +97,7 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
case "locs":
// Unimplemented; just return a list containing src.loc
DreamList locs = ObjectTree.CreateList();
locs.AddValue(new(_loc));
locs.AddValue(new(Loc));

value = new DreamValue(locs);
return true;
Expand Down Expand Up @@ -152,7 +152,7 @@ protected override void SetVar(string varName, DreamValue value) {
}

private void SetLoc(DreamObjectAtom? loc) {
_loc = loc;
Loc = loc;
if (TransformSystem == null)
return;

Expand Down
5 changes: 5 additions & 0 deletions OpenDreamRuntime/ServerVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ private bool CanExecute(DreamConnection connection, DreamObject src, DreamProc v
switch (verbInfo.Accessibility) {
case VerbAccessibility.Usr:
return src == connection.Mob;
case VerbAccessibility.InUsr:
if (src is not DreamObjectMovable srcMovable)
return false;

return srcMovable.Loc == connection.Mob;
default:
// TODO: All the other kinds
return true;
Expand Down
Loading