Skip to content

Commit

Permalink
kinda working I guess
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Dec 24, 2023
1 parent a3dcd59 commit 9bad414
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ public sealed class DreamVisContentsList : DreamList {
[Dependency] private IEntityManager _entityManager = default!;
private readonly PvsOverrideSystem? _pvsOverrideSystem;

private readonly List<DreamObjectAtom> _visContents = new();
private readonly List<DreamObject> _visContents = new();
private readonly DreamObject _atom;

public DreamVisContentsList(DreamObjectDefinition listDef, PvsOverrideSystem? pvsOverrideSystem, DreamObject atom) : base(listDef, 0) {
Expand Down Expand Up @@ -747,6 +747,9 @@ public override void AddValue(DreamValue value) {
} else if (value.TryGetValueAsDreamObject<DreamObjectTurf>(out var turf)) {
_visContents.Add(turf);
entity = EntityUid.Invalid; // TODO: Support turfs in vis_contents
} else if(value.TryGetValueAsDreamObject<DreamObjectImage>(out var image)) {
_visContents.Add(image);
entity = image.GetEntity();
} else {
throw new Exception($"Cannot add {value} to a vis_contents list");
}
Expand Down
23 changes: 23 additions & 0 deletions OpenDreamRuntime/Objects/Types/DreamObjectImage.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using OpenDreamRuntime.Procs;
using OpenDreamRuntime.Rendering;
using OpenDreamShared.Dream;
using Robust.Shared.Map;

namespace OpenDreamRuntime.Objects.Types;

public sealed class DreamObjectImage : DreamObject {

public IconAppearance? Appearance;

private DreamObject? _loc;
private DreamList _overlays;
private DreamList _underlays;
private EntityUid _entity = EntityUid.Invalid;

/// <summary>
/// All the args in /image/New() after "icon" and "loc", in their correct order
Expand Down Expand Up @@ -189,4 +193,23 @@ protected override void SetVar(string varName, DreamValue value) {
public DreamObject? GetAttachedLoc(){
return this._loc;
}

/// <summary>
/// Get or create the entity associated with this image. Used for putting this image in the world ie, with vis_contents
/// The associated entity is deleted when the image is.
/// </summary>
public EntityUid GetEntity() {
if(_entity == EntityUid.Invalid) {
_entity = EntityManager.SpawnEntity(null, new MapCoordinates(0, 0, MapId.Nullspace));
DMISpriteComponent sprite = EntityManager.AddComponent<DMISpriteComponent>(_entity);
sprite.SetAppearance(Appearance!);
}
return _entity;
}

protected override void HandleDeletion() {
if(_entity != EntityUid.Invalid) {
EntityManager.DeleteEntity(_entity);
}
}
}
9 changes: 8 additions & 1 deletion TestGame/code.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
New()
..()
loc = locate(5, 5, 1)
//color = rgb(rand(0,255), rand(0,255), rand(0,255))
var/image/i = image(icon = 'icons/hanoi.dmi', icon_state="8")
src.vis_contents += i
spawn(50)
src << "changing image"
i.icon_state = "1"
spawn(100)
src << "removing image"
src.vis_contents.Cut()

Login()
world.log << "login ran"
Expand Down

0 comments on commit 9bad414

Please sign in to comment.