mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-14 09:35:30 +01:00
5efeedbad9
## About The Pull Request This PR adds a universal framework for editing sprites, and adds an example implementation by way of porting paint canvases to it. This should have no impact on serializing paintings in the database. As part of this canvas refactor, zooming in and out of a canvas is now handled entirely on the client side. The paint palette component has also been refactored to allow a variable number of colors up to the specified maximum, instead of populating all color slots to start out with. Some features of the sprite editing framework are unused in this PR, as they were not necessary for feature parity with the current implementation of paintings. However, they remain present for use in future PRs, such as a PDA painting app that was separated out of this branch for atomicity. These features include: - Eraser tool - Undo history - Layers - Multi-dir icon support Support for animated icons is not present, but planned to be added when a new feature needs it. ### New Painting UI Screenshot: <img width="1210" height="596" alt="NewCanvasUiDemo" src="https://github.com/user-attachments/assets/4181745b-716b-4068-b3a2-d2491e5abf09" /> ## Why It's Good For The Game This framework opens the possibility for a wide variety of new features, such as Goofball's planned tailoring mechanic. Additionally, the consolidation of all the controls into a single window should make painting more user-friendly. ## Changelog 🆑 refactor: Painting has been significantly refactored with a new UI that should provide every painting control you need without having to unfocus the UI window. Please report any issues. refactor: Items that can store paint palettes now start with no colors. Colors can be added to and removed from the item's palette, up to the number of colors they previously stored. /🆑 --------- Co-authored-by: Jordan Dominion <dominion@tgstation13.org>
54 lines
1.7 KiB
Plaintext
54 lines
1.7 KiB
Plaintext
//a macro for the stringized key for coordinates to check later
|
|
#define CANVAS_COORD(x, y) "[x]:[y]"
|
|
#define IS_IN_BOUNDS(x, y) (x > 0 && x <= width && y > 0 && y <= height)
|
|
#define COLORS_ARE_EQUAL(a, b) ((a == b) || (endswith(a, "00") && endswith(b, "00")))
|
|
|
|
#define SHOULD_ADD_POINT(x, y) (!coord_cache[CANVAS_COORD(x, y)] && IS_IN_BOUNDS(x, y) && COLORS_ARE_EQUAL(grid[y][x], target_color))
|
|
|
|
#define ADD_POINT(x, y) \
|
|
points += list(list((x) - 1, (y) - 1, target_color));\
|
|
coord_cache[CANVAS_COORD(x, y)] = TRUE
|
|
|
|
/proc/flood_fill(list/grid, x, y, width, height)
|
|
var/target_color = grid[y][x]
|
|
var/list/coord_cache = list()
|
|
var/list/points = list()
|
|
var/list/coord_queue = list(x, x, y, 1, x, x, y-1, -1)
|
|
var/span_start
|
|
var/column
|
|
var/span_end
|
|
var/row
|
|
var/row_shift
|
|
while(length(coord_queue))
|
|
span_start = coord_queue[1]
|
|
column = span_start
|
|
span_end = coord_queue[2]
|
|
row = coord_queue[3]
|
|
row_shift = coord_queue[4]
|
|
coord_queue.Cut(1, 5)
|
|
if(SHOULD_ADD_POINT(column, row))
|
|
while(SHOULD_ADD_POINT(column - 1, row))
|
|
ADD_POINT(column - 1, row)
|
|
column--
|
|
if(column < span_start)
|
|
coord_queue += list(column, span_start - 1, row - row_shift, -row_shift)
|
|
while(span_start <= span_end)
|
|
while(SHOULD_ADD_POINT(span_start, row))
|
|
ADD_POINT(span_start, row)
|
|
span_start++
|
|
if(span_start > column)
|
|
coord_queue += list(column, span_start - 1, row + row_shift, row_shift)
|
|
if(span_start - 1 > span_end)
|
|
coord_queue += list(span_end + 1, span_start - 1, row - row_shift, -row_shift)
|
|
span_start++
|
|
while(span_start < span_end && !SHOULD_ADD_POINT(span_start, row))
|
|
span_start++
|
|
column = span_start
|
|
return points
|
|
|
|
#undef ADD_POINT
|
|
#undef SHOULD_ADD_POINT
|
|
#undef COLORS_ARE_EQUAL
|
|
#undef IS_IN_BOUNDS
|
|
#undef CANVAS_COORD
|