-
Notifications
You must be signed in to change notification settings - Fork 0
/
replace color.bas
65 lines (59 loc) · 1.22 KB
/
replace color.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
REM BASIC8
REM Copyright (C) 2018 - 2019 Tony Wang
REM Plugin program of BASIC8.
REM Loads the plugin.
def plug()
print "Loading plugin: Replace color...";
register_plugin
(
"sprite, map, tiles, quantized", ' Target assets.
"Replace color", ' Name.
"Replace all pixels in the color at the specified position with the active palette", ' Tooltips.
false, ' Selection only?
false, ' Square only?
10, ' Category.
20 ' Priority.
)
enddef
REM Runs the plugin.
def run()
' Prepares.
print "Running plugin: Replace color...";
src = 0
tgt = 0
' Gets the source and target colors.
p = get_cursor_position()
if p = nil then
return
endif
x = 0
y = 0
unpack(p, x, y)
src = get_pixel(x, y)
tgt = get_source_index()
if src = tgt then
return
endif
' Sets with the new color.
begin_operation("Replace color")
v = get_frame_size()
unpack(v, w, h)
for j = 0 to h - 1
for i = 0 to w - 1
c = get_pixel(i, j)
if c = src then
set_pixel(i, j, tgt)
endif
next
next
end_operation()
' Marks the asset dirty.
set_asset_unsaved()
enddef
REM Checks the operation.
ph = get_phase()
if ph = "plug" then
plug()
elseif ph = "run" then
run()
endif