-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy to all.bas
81 lines (73 loc) · 1.45 KB
/
copy to all.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
REM BASIC8
REM Copyright (C) 2018 - 2019 Tony Wang
REM Plugin program of BASIC8.
REM Imports common modules.
import "common/frame"
REM Loads the plugin.
def plug()
print "Loading plugin: Copy to all...";
register_plugin
(
"sprite", ' Target assets.
"Copy to all", ' Name.
"Copy the current frame to all other ones in this asset", ' Tooltips.
false, ' Selection only?
false, ' Square only?
30, ' Category.
10 ' Priority.
)
enddef
REM Runs the plugin.
def run()
' Prepares.
print "Running plugin: Copy to all...";
x0 = 0
y0 = 0
x1 = 0
y1 = 0
w = 0
h = 0
d = nil
' Gets the operating area.
if has_selection() then
v = get_selection_range()
unpack(v, x0, y0, x1, y1)
else
v = get_frame_size()
unpack(v, x1, y1)
x1 = x1 - 1
y1 = y1 - 1
endif
w = x1 - x0 + 1
h = y1 - y0 + 1
' Gets the current pixels.
d = get_pixels_rect(x0, y0, w, h)
' Sets with the new pixels.
g = get_frame_index()
n = get_frame_count()
for f = 1 to n
if f = g then next
set_frame_index(f)
begin_operation("Copy frame")
for j = 0 to h - 1
y = y0 + j
for i = 0 to w - 1
x = x0 + i
k = hash_xy(x, y, w)
c = get(d, k)
set_pixel(x, y, c)
next
next
end_operation()
next
set_frame_index(g)
' 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