-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sheet.aspl
67 lines (59 loc) · 1.63 KB
/
Sheet.aspl
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
import graphics
import math.geometry
class Sheet {
[readpublic]
property string name
[readpublic]
property string file
[readpublic]
property Size size
[public]
property Canvas? canvas
[public]
property Canvas? sheetCanvas
[readpublic]
property bool loaded
[public]
property bool hasChanged
[public]
method construct(string name, string file, Size size) {
this.name = name
this.file = file
this.size = size
}
[public]
[static]
method fromFile(string file) returns Sheet{
var name = file.reverse().split("/", 2)[0].split(".", 2)[1].reverse()
var size = new Size(float(graphics.get_image_width_from_file(file)), float(graphics.get_image_height_from_file(file)))
return new self(name, file, size)
}
[public]
method load(){
if(!loaded) {
sheetCanvas = Canvas:fromFile(file)
var canvasFile = file.reverse().split(".", 2)[1].reverse() + ".canvas.png"
if(!io.exists_file(canvasFile)) {
canvas = new Canvas(Canvas(sheetCanvas).width, Canvas(sheetCanvas).height)
Canvas(canvas).save(canvasFile)
}
canvas = Canvas:fromFile(canvasFile)
loaded = true
}
}
[public]
method unload(bool save){
if(loaded) {
if(save) {
this.save()
}
sheetCanvas = null
canvas = null
loaded = false
}
}
[public]
method save() {
Canvas(canvas).save(file.reverse().split(".", 2)[1].reverse() + ".canvas.png")
}
}