Skip to content

Commit 59787a1

Browse files
committed
Generate methods now take config objects.
1 parent baf6982 commit 59787a1

1 file changed

Lines changed: 47 additions & 13 deletions

File tree

v3/src/animation/AnimationManager.js

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var Animation = require('./frame/Animation');
88
var Map = require('../structs/Map');
99
var Pad = require('../utils/string/Pad');
10+
var GetObjectValue = require('../utils/object/GetObjectValue');
1011

1112
/**
1213
* Animations are managed by the global AnimationManager. This is a singleton class that is
@@ -96,18 +97,38 @@ AnimationManager.prototype = {
9697
return child;
9798
},
9899

99-
generateFrameNumbers: function (key, startFrame, endFrame, firstFrame, out)
100+
generateFrameNumbers: function (key, config)
100101
{
101-
if (out === undefined) { out = []; }
102+
var startFrame = GetObjectValue(config, 'start', 0);
103+
var endFrame = GetObjectValue(config, 'end', -1);
104+
var firstFrame = GetObjectValue(config, 'first', false);
105+
var out = GetObjectValue(config, 'framesArray', []);
102106

103-
if (firstFrame)
107+
var texture = this.textureManager.get(key);
108+
109+
if (!texture)
110+
{
111+
return out;
112+
}
113+
114+
// No endFrame then see if we can get it
115+
116+
if (endFrame === -1)
117+
{
118+
endFrame = texture.frameTotal;
119+
}
120+
121+
if (firstFrame && texture.has(firstFrame))
104122
{
105123
out.push({ key: key, frame: firstFrame });
106124
}
107125

108126
for (var i = startFrame; i <= endFrame; i++)
109127
{
110-
out.push({ key: key, frame: i });
128+
if (texture.has(i))
129+
{
130+
out.push({ key: key, frame: i });
131+
}
111132
}
112133

113134
return out;
@@ -127,22 +148,35 @@ AnimationManager.prototype = {
127148
* @param {number} [zeroPad=0] - The number of zeros to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
128149
* @return {string[]} An array of framenames.
129150
*/
130-
generateFrameNames: function (key, prefix, start, stop, suffix, zeroPad, out)
151+
generateFrameNames: function (key, config)
131152
{
132-
if (suffix === undefined) { suffix = ''; }
133-
if (zeroPad === undefined) { zeroPad = 0; }
134-
if (out === undefined) { out = []; }
153+
var prefix = GetObjectValue(config, 'prefix', '');
154+
var start = GetObjectValue(config, 'start', 0);
155+
var end = GetObjectValue(config, 'end', 0);
156+
var suffix = GetObjectValue(config, 'suffix', '');
157+
var zeroPad = GetObjectValue(config, 'zeroPad', 0);
158+
var out = GetObjectValue(config, 'framesArray', []);
159+
160+
var diff = (start < end) ? 1 : -1;
135161

136-
var diff = (start < stop) ? 1 : -1;
162+
// Adjust because we use i !== end in the for loop
163+
end += diff;
137164

138-
// Adjust because we use i !== stop in the for loop
139-
stop += diff;
165+
var texture = this.textureManager.get(key);
166+
167+
if (!texture)
168+
{
169+
return out;
170+
}
140171

141-
for (var i = start; i !== stop; i += diff)
172+
for (var i = start; i !== end; i += diff)
142173
{
143174
var frame = prefix + Pad(i, zeroPad, '0', 1) + suffix;
144175

145-
out.push({ key: key, frame: frame });
176+
if (texture.has(frame))
177+
{
178+
out.push({ key: key, frame: frame });
179+
}
146180
}
147181

148182
return out;

0 commit comments

Comments
 (0)