Skip to content

Commit

Permalink
Fix some NREs
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Jan 5, 2025
1 parent 26be28e commit 1e54318
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ private ServerAppearanceSystem? AppearanceSystem {
return _appearanceSystem;
}
}

private ServerVerbSystem VerbSystem => _verbSystem ??= _entitySystemManager.GetEntitySystem<ServerVerbSystem>();

private DMISpriteSystem? DMISpriteSystem {
get {
if(_dmiSpriteSystem is null)
_entitySystemManager.TryGetEntitySystem(out _dmiSpriteSystem);
return _dmiSpriteSystem;
}
}

private ServerVerbSystem? VerbSystem {
get {
if(_verbSystem is null)
_entitySystemManager.TryGetEntitySystem(out _verbSystem);
return _verbSystem;
}
}

private ServerAppearanceSystem? _appearanceSystem;
private ServerVerbSystem? _verbSystem;
private DMISpriteSystem DMISpriteSystem => _dmiSpriteSystem ??= _entitySystemManager.GetEntitySystem<DMISpriteSystem>();
private DMISpriteSystem? _dmiSpriteSystem;

// ReSharper disable ForCanBeConvertedToForeach (the collections could be added to)
Expand Down Expand Up @@ -200,7 +214,7 @@ public EntityUid CreateMovableEntity(DreamObjectMovable movable) {
var entity = _entityManager.SpawnEntity(null, new MapCoordinates(0, 0, MapId.Nullspace));

DMISpriteComponent sprite = _entityManager.AddComponent<DMISpriteComponent>(entity);
DMISpriteSystem.SetSpriteAppearance(new(entity, sprite), GetAppearanceFromDefinition(movable.ObjectDefinition));
DMISpriteSystem?.SetSpriteAppearance(new(entity, sprite), GetAppearanceFromDefinition(movable.ObjectDefinition));

_entityToAtom.Add(entity, movable);
return entity;
Expand Down Expand Up @@ -363,15 +377,15 @@ public void SetAppearanceVar(MutableAppearance appearance, string varName, Dream
continue;

if (!verb.VerbId.HasValue)
VerbSystem.RegisterVerb(verb);
VerbSystem?.RegisterVerb(verb);
if (appearance.Verbs.Contains(verb.VerbId!.Value))
continue;

appearance.Verbs.Add(verb.VerbId.Value);
}
} else if (value.TryGetValueAsProc(out var verb)) {
if (!verb.VerbId.HasValue)
VerbSystem.RegisterVerb(verb);
VerbSystem?.RegisterVerb(verb);

appearance.Verbs.Add(verb.VerbId!.Value);
}
Expand Down Expand Up @@ -515,7 +529,7 @@ public ImmutableAppearance MustGetAppearance(DreamObject atom) {
public bool TryGetAppearance(DreamObject atom, [NotNullWhen(true)] out ImmutableAppearance? appearance) {
if (atom is DreamObjectTurf turf)
appearance = turf.Appearance;
else if (atom is DreamObjectMovable movable && movable.SpriteComponent.Appearance is not null)
else if (atom is DreamObjectMovable { SpriteComponent.Appearance: not null } movable)
appearance = movable.SpriteComponent.Appearance;
else if (atom is DreamObjectImage image)
appearance = image.IsMutableAppearance ? AppearanceSystem!.AddAppearance(image.MutableAppearance!, registerAppearance: false) : image.SpriteComponent?.Appearance;
Expand All @@ -538,23 +552,23 @@ public void SetAtomAppearance(DreamObject atom, MutableAppearance appearance) {
if (atom is DreamObjectTurf turf) {
_dreamMapManager.SetTurfAppearance(turf, appearance);
} else if (atom is DreamObjectMovable movable) {
DMISpriteSystem.SetSpriteAppearance(new(movable.Entity, movable.SpriteComponent), appearance);
DMISpriteSystem?.SetSpriteAppearance(new(movable.Entity, movable.SpriteComponent), appearance);
} else if (atom is DreamObjectImage image) {
if(image.IsMutableAppearance)
image.MutableAppearance = MutableAppearance.GetCopy(appearance); //this needs to be a copy
else
DMISpriteSystem.SetSpriteAppearance(new(image.Entity, image.SpriteComponent!), appearance);
DMISpriteSystem?.SetSpriteAppearance(new(image.Entity, image.SpriteComponent!), appearance);
} else if (atom is DreamObjectArea area) {
_dreamMapManager.SetAreaAppearance(area, appearance);
}
}

public void SetMovableScreenLoc(DreamObjectMovable movable, ScreenLocation screenLocation) {
DMISpriteSystem.SetSpriteScreenLocation(new(movable.Entity, movable.SpriteComponent), screenLocation);
DMISpriteSystem?.SetSpriteScreenLocation(new(movable.Entity, movable.SpriteComponent), screenLocation);
}

public void SetSpriteAppearance(Entity<DMISpriteComponent> ent, MutableAppearance appearance) {
DMISpriteSystem.SetSpriteAppearance(ent, appearance);
DMISpriteSystem?.SetSpriteAppearance(ent, appearance);
}

public void AnimateAppearance(DreamObject atom, TimeSpan duration, AnimationEasing easing, int loop, AnimationFlags flags, int delay, bool chainAnim, Action<MutableAppearance> animate) {
Expand All @@ -568,7 +582,7 @@ public void AnimateAppearance(DreamObject atom, TimeSpan duration, AnimationEasi
targetEntity = movable.Entity;
targetComponent = movable.SpriteComponent;
appearance = MustGetAppearance(atom).ToMutable();
} else if (atom is DreamObjectImage image && !image.IsMutableAppearance){
} else if (atom is DreamObjectImage { IsMutableAppearance: false } image) {
targetEntity = image.Entity;
targetComponent = image.SpriteComponent;
appearance = MustGetAppearance(atom).ToMutable();
Expand All @@ -593,7 +607,7 @@ public void AnimateAppearance(DreamObject atom, TimeSpan duration, AnimationEasi
if(targetComponent is not null) {
ent = _entityManager.GetNetEntity(targetEntity);
// Don't send the updated appearance to clients, they will animate it
DMISpriteSystem.SetSpriteAppearance(new(targetEntity, targetComponent), appearance, dirty: false);
DMISpriteSystem?.SetSpriteAppearance(new(targetEntity, targetComponent), appearance, dirty: false);
} else if (atom is DreamObjectTurf turf) {
//TODO: turf appearances are just set to the end appearance, they do not get properly animated
_dreamMapManager.SetTurfAppearance(turf, appearance);
Expand Down

0 comments on commit 1e54318

Please sign in to comment.