Skip to content

Add GetPixel() for Icon#2524

Open
Sorrowfulwinds wants to merge 7 commits intoOpenDreamProject:masterfrom
Sorrowfulwinds:icons-procs
Open

Add GetPixel() for Icon#2524
Sorrowfulwinds wants to merge 7 commits intoOpenDreamProject:masterfrom
Sorrowfulwinds:icons-procs

Conversation

@Sorrowfulwinds
Copy link
Contributor

Adds proc/GetPixel(x, y, icon_state, dir = 0, frame = 0, moving = -1) for #2194.

It has 2 TODOs that cannot be implemented currently:
-The moving var does nothing as OD does not currently track that variable from DMI's
-If icon_state is not in the icon BYOND will either pull the empty string/null icon_state by default or if one does not exist it will pull the first icon_state in the dmi. OD does not track this so it only defaults to checking for an empty string state before failing.

Vars:
X&Y - Must be >1 and less than the max dimension +1 of the icon_state.
icon_state - Must be a string.
dir - Must be a valid integer of dirs N E S W NE NW SE SW (1,2,4,5,6,8,9,10) or 0. 0 counts as South.
frame - Values less than 1 count as 1. Must be less than the total frames +1 of the icon_state.
moving - not implemented

@boring-cyborg boring-cyborg bot added Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime labels Mar 6, 2026
@github-actions github-actions bot added the size/M label Mar 6, 2026
remove unused directive
remove unused var, todo will suffice
DreamIcon iconObj = ((DreamObjectIcon)src!).Icon;
//TODO BYONDISM: A non-existent icon_state will default to the empty string icon_state,
//or if one doesn't exist it will default to the first icon_state in the DMI.
if(!iconObj.States.TryGetValue(iconState ?? string.Empty, out var state))
Copy link
Member

Choose a reason for hiding this comment

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

Using DreamIcon.States is going to get you the textures before any sort of modifications like /icon.Blend() are applied. You need to use the result of iconObj.GenerateDMI() to get the final DMI.

Comment on lines +144 to +156
AtomDirection atomDir = dir switch {
0 or 2 => AtomDirection.South,
1 => AtomDirection.North,
4 => AtomDirection.East,
5 => AtomDirection.Northeast,
6 => AtomDirection.Southeast,
8 => AtomDirection.West,
9 => AtomDirection.Northwest,
10 => AtomDirection.Southwest,
_ => AtomDirection.None
};
//BYONDISM: Bad dir values just crash instantly :)
if (atomDir == AtomDirection.None) return 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.

You can cast the value instead of having a switch

Suggested change
AtomDirection atomDir = dir switch {
0 or 2 => AtomDirection.South,
1 => AtomDirection.North,
4 => AtomDirection.East,
5 => AtomDirection.Northeast,
6 => AtomDirection.Southeast,
8 => AtomDirection.West,
9 => AtomDirection.Northwest,
10 => AtomDirection.Southwest,
_ => AtomDirection.None
};
//BYONDISM: Bad dir values just crash instantly :)
if (atomDir == AtomDirection.None) return DreamValue.Null;
//BYONDISM: Bad dir values just crash instantly :)
if (!Enum.IsDefined(typeof(AtomDirection), dir)) return DreamValue.Null;
var atomDir = (AtomDirection)dir;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants