forked from Mari0-CE/Mari0-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
characterloader.lua
185 lines (155 loc) · 7.26 KB
/
characterloader.lua
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function loadcharacter(charname)
local folder = "characters/" .. charname .. "/"
if not love.filesystem.getInfo(folder .. "config.txt") then
return false
end
local s = love.filesystem.read(folder .. "config.txt")
--------------------
--VARIABLE LOADING--
--------------------
local char = JSON:decode(s)
char.name = (char.name and string.lower(char.name)) or string.lower(charname)
if char.defaultcolors then
for i, colors in ipairs(char.defaultcolors) do
for j, color in ipairs (colors) do
for k = 1, 3 do
char.defaultcolors[i][j][k] = char.defaultcolors[i][j][k] / 255
end
end
end
end
-----------------
--IMAGE LOADING--
-----------------
for t = 1, 4 do
local curtype
if t == 1 then
curtype = "animations"
elseif t == 2 then
curtype = "biganimations"
elseif t == 3 then
curtype = "nogunanimations"
else
curtype = "nogunbiganimations"
end
if char.defaultcolors and love.filesystem.getInfo(folder .. curtype .. "1.png") then --MULTIPLE IMAGES
local imagecount = #char.defaultcolors[1]
for i = 1, imagecount do
if not love.filesystem.getInfo(folder .. curtype .. i .. ".png") then
if t <= 2 then
return false
else
break
end
end
if not char[curtype] then
char[curtype] = {}
end
char[curtype][i] = love.graphics.newImage(folder .. curtype .. i .. ".png")
end
--0 Image
if love.filesystem.getInfo(folder .. curtype .. "0.png") then
char[curtype][0] = love.graphics.newImage(folder .. curtype .. "0.png")
end
--Dot Image
if love.filesystem.getInfo(folder .. curtype .. "dot.png") then
char[curtype]["dot"] = love.graphics.newImage(folder .. curtype .. "dot.png")
end
else
if love.filesystem.getInfo(folder .. curtype .. ".png") then
char[curtype] = love.graphics.newImage(folder .. curtype .. ".png")
end
end
end
----------------
--QUAD LOADING--
----------------
local quadnum = 5
if char.nopointing then
quadnum = 1
end
char.idle = {}
char.run = {}
char.slide = {}
char.jump = {}
char.die = {}
char.climb = {}
char.swim = {}
char.grow = {}
char.customframe = {}
for i = 1, quadnum do
local add = 0
char.idle[i] = love.graphics.newQuad(0, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.run[i] = {}
for j = 1, char.runframes do
char.run[i][j] = love.graphics.newQuad(j*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
end
add = add + char.runframes
char.slide[i] = love.graphics.newQuad((add+1)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.jump[i] = {}
for j = 1, char.jumpframes do
char.jump[i][j] = love.graphics.newQuad((add+1+j)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
end
add = add + char.jumpframes
char.die[i] = love.graphics.newQuad((add+2)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.climb[i] = {}
char.climb[i][1] = love.graphics.newQuad((add+3)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.climb[i][2] = love.graphics.newQuad((add+4)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.swim[i] = {}
char.swim[i][1] = love.graphics.newQuad((add+5)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.swim[i][2] = love.graphics.newQuad((add+6)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
char.grow[i] = love.graphics.newQuad((add+7)*char.smallquadwidth, 0, char.smallquadwidth, char.smallimgheight, char.smallimgwidth, char.smallimgheight)
char.customframe[i] = {}
for j = 1, (char.customframes or 0) do
char.customframe[i][j] = love.graphics.newQuad((add+7+j)*char.smallquadwidth, (i-1)*char.smallquadheight, char.smallquadwidth, char.smallquadheight, char.smallimgwidth, char.smallimgheight)
end
end
char.bigidle = {}
char.bigrun = {}
char.bigslide = {}
char.bigjump = {}
char.bigfire = {}
char.bigclimb = {}
char.bigswim = {}
char.bigduck = {} --hehe duck.
char.bigcustomframe = {}
for i = 1, quadnum do
local add = 0
char.bigidle[i] = love.graphics.newQuad(0, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigrun[i] = {}
for j = 1, char.runframes do
char.bigrun[i][j] = love.graphics.newQuad(j*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
end
add = add + char.runframes
char.bigslide[i] = love.graphics.newQuad((add+1)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigjump[i] = {}
for j = 1, char.jumpframes do
char.bigjump[i][j] = love.graphics.newQuad((add+1+j)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
end
add = add + char.jumpframes
char.bigfire[i] = love.graphics.newQuad((add+2)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigclimb[i] = {}
char.bigclimb[i][1] = love.graphics.newQuad((add+3)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigclimb[i][2] = love.graphics.newQuad((add+4)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigswim[i] = {}
char.bigswim[i][1] = love.graphics.newQuad((add+5)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigswim[i][2] = love.graphics.newQuad((add+6)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigduck[i] = love.graphics.newQuad((add+7)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
char.bigcustomframe[i] = {}
for j = 1, (char.customframes or 0) do
char.bigcustomframe[i][j] = love.graphics.newQuad((add+7+j)*char.bigquadwidth, (i-1)*char.bigquadheight, char.bigquadwidth, char.bigquadheight, char.bigimgwidth, char.bigimgheight)
end
end
return char
end
characterlist = {}
characters = {}
for i, v in pairs(love.filesystem.getDirectoryItems("characters/")) do
if love.filesystem.getInfo("characters/" .. v, "directory") then
local temp = loadcharacter(v)
if temp then
characters[v] = temp
table.insert(characterlist, v)
end
end
end