-
Notifications
You must be signed in to change notification settings - Fork 129
Add GetPixel() for Icon #2524
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
Open
Sorrowfulwinds
wants to merge
8
commits into
OpenDreamProject:master
Choose a base branch
from
Sorrowfulwinds:icons-procs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−1
Open
Add GetPixel() for Icon #2524
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
08d3b6a
GetPixel work
Sorrowfulwinds 5e5e485
finish prototype
Sorrowfulwinds 78889f6
Confirm outliers and byondisms
Sorrowfulwinds 371c921
lowercase not upper
Sorrowfulwinds 505e309
Merge branch 'OpenDreamProject:master' into icons-procs
Sorrowfulwinds 3d196ad
cleanup
Sorrowfulwinds 0f4ea3a
Merge branch 'icons-procs' of https://github.com/Sorrowfulwinds/OpenD…
Sorrowfulwinds cc5540b
Merge branch 'OpenDreamProject:master' into icons-procs
Sorrowfulwinds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,5 +107,76 @@ public static DreamValue NativeProc_Turn(NativeProc.Bundle bundle, DreamObject? | |||||||||||||||||||||||||||||||||||
| public static void _NativeProc_TurnInternal(DreamObjectIcon src, float angle) { | ||||||||||||||||||||||||||||||||||||
| src.Turn(angle); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| [DreamProc("GetPixel")] | ||||||||||||||||||||||||||||||||||||
| [DreamProcParameter("x", Type = DreamValueTypeFlag.Float)] | ||||||||||||||||||||||||||||||||||||
| [DreamProcParameter("y", Type = DreamValueTypeFlag.Float)] | ||||||||||||||||||||||||||||||||||||
| [DreamProcParameter("icon_state", Type = DreamValueTypeFlag.String)] | ||||||||||||||||||||||||||||||||||||
| [DreamProcParameter("dir", Type = DreamValueTypeFlag.Float, DefaultValue = 0)] | ||||||||||||||||||||||||||||||||||||
| [DreamProcParameter("frame", Type = DreamValueTypeFlag.Float, DefaultValue = 0)] | ||||||||||||||||||||||||||||||||||||
| [DreamProcParameter("moving", Type = DreamValueTypeFlag.Float, DefaultValue = -1)] | ||||||||||||||||||||||||||||||||||||
| public static DreamValue NativeProc_GetPixel(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) { | ||||||||||||||||||||||||||||||||||||
| bundle.GetArgument(0, "x").TryGetValueAsInteger(out var xPos); | ||||||||||||||||||||||||||||||||||||
| bundle.GetArgument(1, "y").TryGetValueAsInteger(out var yPos); | ||||||||||||||||||||||||||||||||||||
| bundle.GetArgument(2, "icon_state").TryGetValueAsString(out var iconState); | ||||||||||||||||||||||||||||||||||||
| bundle.GetArgument(3, "dir").TryGetValueAsInteger(out var dir); | ||||||||||||||||||||||||||||||||||||
| bundle.GetArgument(4, "frame").TryGetValueAsInteger(out var frame); | ||||||||||||||||||||||||||||||||||||
| //TODO: Implement moving var | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| 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)) | ||||||||||||||||||||||||||||||||||||
| //Bad icon_state returns null | ||||||||||||||||||||||||||||||||||||
| return DreamValue.Null; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| //Position values less than 1 are out of bounds. Early escape. | ||||||||||||||||||||||||||||||||||||
| if (xPos < 1 || yPos < 1) return DreamValue.Null; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (frame < 1) { | ||||||||||||||||||||||||||||||||||||
| frame = 0; //BYONDISM: Frames less than 1 count as 0, | ||||||||||||||||||||||||||||||||||||
| } else if (frame > state.Frames) { | ||||||||||||||||||||||||||||||||||||
| return DreamValue.Null; | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| frame -= 1; // Convert from 1-index to 0-index | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+144
to
+156
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can cast the value instead of having a switch
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!state.Directions.TryGetValue(atomDir, out var frameList)) | ||||||||||||||||||||||||||||||||||||
| //Empty dir's return null | ||||||||||||||||||||||||||||||||||||
| return DreamValue.Null; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var finalFrame = frameList[frame].Image; | ||||||||||||||||||||||||||||||||||||
| if (finalFrame is null) return DreamValue.Null; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| //Out-of-bounds xy values return null. | ||||||||||||||||||||||||||||||||||||
| if (xPos > finalFrame.Width || yPos > finalFrame.Height) return DreamValue.Null; | ||||||||||||||||||||||||||||||||||||
| //SixLabors.Image<Rgba32> is 0-indexed from the top-left, BYOND is 1-indexed from the bottom left. | ||||||||||||||||||||||||||||||||||||
| xPos -= 1; | ||||||||||||||||||||||||||||||||||||
| yPos = finalFrame.Height - yPos; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var pix = finalFrame[xPos, yPos]; | ||||||||||||||||||||||||||||||||||||
| //If A is fully transparent return null | ||||||||||||||||||||||||||||||||||||
| //if A is partially transparent return "#RRGGBBAA" | ||||||||||||||||||||||||||||||||||||
| //if A is not transparent return "#RRGGBB" | ||||||||||||||||||||||||||||||||||||
| return pix.A switch { | ||||||||||||||||||||||||||||||||||||
| 0 => DreamValue.Null, | ||||||||||||||||||||||||||||||||||||
| 255 => new DreamValue($"#{pix.R:x2}{pix.G:x2}{pix.B:x2}"), | ||||||||||||||||||||||||||||||||||||
| _ => new DreamValue($"#{pix.R:x2}{pix.G:x2}{pix.B:x2}{pix.A:x2}") | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
DreamIcon.Statesis going to get you the textures before any sort of modifications like/icon.Blend()are applied. You need to use the result oficonObj.GenerateDMI()to get the final DMI.