-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport tilesheet.bas
69 lines (62 loc) · 1.25 KB
/
import tilesheet.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
REM BASIC8
REM Copyright (C) 2018 - 2019 Tony Wang
REM Plugin program of BASIC8.
REM Imports common modules.
REM Loads the plugin.
def plug()
print "Loading plugin: Import tilesheet...";
register_plugin
(
"tiles", ' Target assets.
"Import tilesheet", ' Name.
"Import a tilesheet of image to the current tiles asset", ' Tooltips.
false, ' Selection only?
false, ' Square only?
40, ' Category.
40 ' Priority.
)
enddef
REM Runs the plugin.
def run()
' Prepares.
print "Running plugin: Import tilesheet...";
w = 0
h = 0
' Gets the asset information.
v = get_frame_size()
unpack(v, w, h)
' Gets a file.
f = open_file_dialog("png,bmp,tga,jpg")
if not f then
return
endif
' Gets the source image.
g = image()
g.load(f)
iw = g.len(0)
ih = g.len(1)
if iw <> w or ih <> h then
g.resize(w, h)
iw = w
ih = h
endif
' Fills the frame.
begin_operation("Fill tiles")
for j = 0 to h - 1
for i = 0 to w - 1
c = g.get(i, j)
c = get_palette_from_color(c)
set_pixel(i, j, c)
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