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

Change the movable contents to special list, and make view include Contents #2050

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SaphireLattice
Copy link
Contributor

New list implementation was required to make += and such work. Not sure if SetVar would have helped? Actually didn't test if a reference to the list still updates the object on reference implementation, but it feels like it should. Then again, never know what weird shit might happen.

Also made view(...) include contents just like range(...) - these probably should share the implementation code, other than a boolean. They are pretty much the same, just with view culling.

Oh, this fixes:

  • TGUI of worn stuff (via view(), mostly)
  • Drones and probably borgs getting UI for RPD
  • Fire extinguishers dropping under your mob when you put them into the cabinet, while also being referenced by the cabinet, leading to fun teleport shenanigans

Though, worrding that it's shitcode to have public ChildEnumerator and public ChildCount exposed by the DreamObjectMovable. Maybe I could just give the MovableContentsList its Transform component?

@boring-cyborg boring-cyborg bot added the Runtime Involves the OpenDream server/runtime label Oct 20, 2024
Comment on lines 3027 to 3029
foreach (var content in centerContentsList.GetValues()) {
view.AddValue(content);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foreach (var content in centerContentsList.GetValues()) {
view.AddValue(content);
}
view.AddRange(centerContentsList.GetValues());

pretty sure this can just be an AddRange()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view is a DreamList which does not have any range-adding methods. Closest would be OperatorAppend() but that should probably be only be used by DM.

@SaphireLattice
Copy link
Contributor Author

Oh yeah, remembered another thing

I have no damn clue as to the stability of the iteration keys and trying to get items "by index" where it's just another iterator again and uhhh... yeah. It didn't seem to explode at least? Like, taking off stuff and moving things around in hands worked fine. Didn't check it with backpacks too much though.

@@ -1263,6 +1271,91 @@
}
}

// mob.contents, obj.contents list
public sealed class MovableContentsList(DreamObjectDefinition listDef, DreamObjectMovable movable) : DreamList(listDef, 0) {
private readonly DreamObjectMovable _movable = movable;

Check notice

Code scanning / InspectCode

Replace with primary constructor parameter Note

Replace with primary constructor parameter
// mob.contents, obj.contents list
public sealed class MovableContentsList(DreamObjectDefinition listDef, DreamObjectMovable movable) : DreamList(listDef, 0) {
private readonly DreamObjectMovable _movable = movable;
public override DreamValue GetValue(DreamValue key) {

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are missing elsewhere Warning

Blank lines are missing, expected minimum 1 instead of 0
throw new Exception($"Invalid index into movable contents list: {key}");


if (index < 1 || index > _movable.ChildCount)

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are redundant elsewhere Warning

Blank lines are redundant, expected maximum 1 instead of 2
throw new Exception($"Out of bounds index on movable contents list: {index}");


using (var childEnumerator = _movable.ChildEnumerator) {

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are redundant elsewhere Warning

Blank lines are redundant, expected maximum 1 instead of 2
throw new Exception($"Out of bounds index on movable contents list: {index}");


using (var childEnumerator = _movable.ChildEnumerator) {

Check notice

Code scanning / InspectCode

Convert into 'using' declaration Note

Convert into 'using' declaration

using (var childEnumerator = _movable.ChildEnumerator) {
while (index >= 1) {
var current = childEnumerator.MoveNext(out EntityUid child);

Check warning

Code scanning / InspectCode

Unused local variable Warning

Local variable 'current' is never used
public override List<DreamValue> GetValues() {
List<DreamValue> values = new List<DreamValue>(_movable.ChildCount);

using (var childEnumerator = _movable.ChildEnumerator) {

Check notice

Code scanning / InspectCode

Convert into 'using' declaration Note

Convert into 'using' declaration
if (!value.TryGetValueAsDreamObject<DreamObjectMovable>(out var movable))
return false;

if (!movable.TryGetVariable("loc", out var _locVariable))

Check warning

Code scanning / InspectCode

Inconsistent Naming Warning

Name '_locVariable' does not match rule 'Local variables'. Suggested name is 'locVariable'.
if (!movable.TryGetVariable("loc", out var _locVariable))
return false;

if (!_locVariable.TryGetValueAsDreamObject<DreamObjectAtom>(out var _loc))

Check warning

Code scanning / InspectCode

Inconsistent Naming Warning

Name '_loc' does not match rule 'Local variables'. Suggested name is 'loc'.
if (!value.TryGetValueAsDreamObject<DreamObjectMovable>(out var movable))
throw new Exception($"Cannot add {value} to movable contents");

movable.SetVariable("loc", new (_movable));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the SetLoc() method on movable instead. Feel free to make it public.

Comment on lines +145 to +151
public virtual void AddValueRange(DreamList valueRange) {
_values.AddRange(valueRange.GetValues());
}

public virtual void AddValueRange(IEnumerable<DreamValue> valueRange) {
_values.AddRange(valueRange);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding helper functions like this that perform directly on _values should be avoided. These would have to be overridden on every DreamList type to handle their special behaviors.

throw new Exception($"Out of bounds index on movable contents list: {index}");


using (var childEnumerator = _movable.ChildEnumerator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be noted that ChildEnumerator is an enumerator of a HashSet which has no defined order. This means the order could theoretically change at any time, breaking this.

I don't think this is a new bug so it doesn't really need to be worried about in this PR.

if (!value.TryGetValueAsDreamObject<DreamObjectMovable>(out var movable))
throw new Exception($"Cannot remove {value} from movable contents");

movable.SetVariable("loc", DreamValue.Null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't verify that this movable was even in our contents to begin with.

Also, use SetLoc() here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh forgot about that. Guess it would be a no-op if it isn't?

And thanks for telling about SetLoc, was not aware! Swear I've seen this pattern elsewhere.

Comment on lines +1341 to +1347
if (!movable.TryGetVariable("loc", out var _locVariable))
return false;

if (!_locVariable.TryGetValueAsDreamObject<DreamObjectAtom>(out var _loc))
return false;

return _loc == _movable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DreamObjectMovable.Loc can be used instead of indirectly going through variables.

Suggested change
if (!movable.TryGetVariable("loc", out var _locVariable))
return false;
if (!_locVariable.TryGetValueAsDreamObject<DreamObjectAtom>(out var _loc))
return false;
return _loc == _movable;
return dreamObject.Loc == movable;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo the changes to this.

@@ -19,6 +19,10 @@ public class DreamObjectMovable : DreamObjectAtom {

private readonly TransformComponent _transformComponent;

public readonly MovableContentsList Contents;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this up with the other public properties

Comment on lines +24 to +25
public TransformChildrenEnumerator ChildEnumerator => _transformComponent.ChildEnumerator;
public int ChildCount => _transformComponent.ChildCount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, worrding that it's shitcode to have public ChildEnumerator and public ChildCount exposed by the DreamObjectMovable. Maybe I could just give the MovableContentsList its Transform component?

I would prefer for you to do this.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge Conflict Runtime Involves the OpenDream server/runtime size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants