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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* This file is based on WME Lite.
* http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
#include "engines/wintermute/dcgf.h"
#include "engines/wintermute/Base/BSprite.h"
#include "engines/wintermute/utils/StringUtil.h"
#include "engines/wintermute/utils/PathUtil.h"
#include "engines/wintermute/Base/BParser.h"
#include "engines/wintermute/Base/BDynBuffer.h"
#include "engines/wintermute/Base/BSurface.h"
#include "engines/wintermute/Base/BGame.h"
#include "engines/wintermute/Base/BFrame.h"
#include "engines/wintermute/Base/BSound.h"
#include "engines/wintermute/Base/BSubFrame.h"
#include "engines/wintermute/Base/BFileManager.h"
#include "engines/wintermute/PlatformSDL.h"
#include "engines/wintermute/Base/scriptables/ScValue.h"
#include "engines/wintermute/Base/scriptables/ScScript.h"
#include "engines/wintermute/Base/scriptables/ScStack.h"
namespace WinterMute {
IMPLEMENT_PERSISTENT(CBSprite, false)
//////////////////////////////////////////////////////////////////////
CBSprite::CBSprite(CBGame *inGame, CBObject *Owner): CBScriptHolder(inGame) {
_editorAllFrames = false;
_owner = Owner;
setDefaults();
}
//////////////////////////////////////////////////////////////////////
CBSprite::~CBSprite() {
cleanup();
}
//////////////////////////////////////////////////////////////////////////
void CBSprite::setDefaults() {
_currentFrame = -1;
_looping = false;
_lastFrameTime = 0;
_filename = NULL;
_finished = false;
_changed = false;
_paused = false;
_continuous = false;
_moveX = _moveY = 0;
_editorMuted = false;
_editorBgFile = NULL;
_editorBgOffsetX = _editorBgOffsetY = 0;
_editorBgAlpha = 0xFF;
_streamed = false;
_streamedKeepLoaded = false;
setName("");
_precise = true;
}
//////////////////////////////////////////////////////////////////////////
void CBSprite::cleanup() {
CBScriptHolder::cleanup();
for (int i = 0; i < _frames.getSize(); i++)
delete _frames[i];
_frames.removeAll();
delete[] _editorBgFile;
_editorBgFile = NULL;
setDefaults();
}
//////////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::draw(int x, int y, CBObject *registerOwner, float zoomX, float zoomY, uint32 alpha) {
GetCurrentFrame(zoomX, zoomY);
if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) return STATUS_OK;
// move owner if allowed to
if (_changed && _owner && _owner->_movable) {
_owner->_posX += _moveX;
_owner->_posY += _moveY;
_owner->afterMove();
x = _owner->_posX;
y = _owner->_posY;
}
// draw frame
return display(x, y, registerOwner, zoomX, zoomY, alpha);
}
//////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) {
Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(filename);
if (!file) {
_gameRef->LOG(0, "CBSprite::LoadFile failed for file '%s'", filename);
if (_gameRef->_dEBUG_DebugMode) return loadFile("invalid_debug.bmp", lifeTime, cacheType);
else return loadFile("invalid.bmp", lifeTime, cacheType);
} else {
_gameRef->_fileManager->closeFile(file);
file = NULL;
}
ERRORCODE ret;
AnsiString ext = PathUtil::getExtension(filename);
if (StringUtil::startsWith(filename, "savegame:", true) || StringUtil::compareNoCase(ext, "bmp") || StringUtil::compareNoCase(ext, "tga") || StringUtil::compareNoCase(ext, "png") || StringUtil::compareNoCase(ext, "jpg")) {
CBFrame *frame = new CBFrame(_gameRef);
CBSubFrame *subframe = new CBSubFrame(_gameRef);
subframe->setSurface(filename, true, 0, 0, 0, lifeTime, true);
if (subframe->_surface == NULL) {
_gameRef->LOG(0, "Error loading simple sprite '%s'", filename);
ret = STATUS_FAILED;
delete frame;
delete subframe;
} else {
CBPlatform::setRect(&subframe->_rect, 0, 0, subframe->_surface->getWidth(), subframe->_surface->getHeight());
frame->_subframes.add(subframe);
_frames.add(frame);
_currentFrame = 0;
ret = STATUS_OK;
}
} else {
byte *buffer = _gameRef->_fileManager->readWholeFile(filename);
if (buffer) {
if (DID_FAIL(ret = loadBuffer(buffer, true, lifeTime, cacheType))) _gameRef->LOG(0, "Error parsing SPRITE file '%s'", filename);
delete [] buffer;
}
}
_filename = new char [strlen(filename) + 1];
strcpy(_filename, filename);
return ret;
}
TOKEN_DEF_START
TOKEN_DEF(CONTINUOUS)
TOKEN_DEF(SPRITE)
TOKEN_DEF(LOOPING)
TOKEN_DEF(FRAME)
TOKEN_DEF(NAME)
TOKEN_DEF(PRECISE)
TOKEN_DEF(EDITOR_MUTED)
TOKEN_DEF(STREAMED_KEEP_LOADED)
TOKEN_DEF(STREAMED)
TOKEN_DEF(SCRIPT)
TOKEN_DEF(EDITOR_BG_FILE)
TOKEN_DEF(EDITOR_BG_OFFSET_X)
TOKEN_DEF(EDITOR_BG_OFFSET_Y)
TOKEN_DEF(EDITOR_BG_ALPHA)
TOKEN_DEF(EDITOR_PROPERTY)
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType cacheType) {
TOKEN_TABLE_START(commands)
TOKEN_TABLE(CONTINUOUS)
TOKEN_TABLE(SPRITE)
TOKEN_TABLE(LOOPING)
TOKEN_TABLE(FRAME)
TOKEN_TABLE(NAME)
TOKEN_TABLE(PRECISE)
TOKEN_TABLE(EDITOR_MUTED)
TOKEN_TABLE(STREAMED_KEEP_LOADED)
TOKEN_TABLE(STREAMED)
TOKEN_TABLE(SCRIPT)
TOKEN_TABLE(EDITOR_BG_FILE)
TOKEN_TABLE(EDITOR_BG_OFFSET_X)
TOKEN_TABLE(EDITOR_BG_OFFSET_Y)
TOKEN_TABLE(EDITOR_BG_ALPHA)
TOKEN_TABLE(EDITOR_PROPERTY)
TOKEN_TABLE_END
byte *params;
int cmd;
CBParser parser(_gameRef);
cleanup();
if (complete) {
if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITE) {
_gameRef->LOG(0, "'SPRITE' keyword expected.");
return STATUS_FAILED;
}
buffer = params;
}
int frameCount = 1;
CBFrame *frame;
while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) {
switch (cmd) {
case TOKEN_CONTINUOUS:
parser.scanStr((char *)params, "%b", &_continuous);
break;
case TOKEN_EDITOR_MUTED:
parser.scanStr((char *)params, "%b", &_editorMuted);
break;
case TOKEN_SCRIPT:
addScript((char *)params);
break;
case TOKEN_LOOPING:
parser.scanStr((char *)params, "%b", &_looping);
break;
case TOKEN_PRECISE:
parser.scanStr((char *)params, "%b", &_precise);
break;
case TOKEN_STREAMED:
parser.scanStr((char *)params, "%b", &_streamed);
if (_streamed && lifeTime == -1) {
lifeTime = 500;
cacheType = CACHE_ALL;
}
break;
case TOKEN_STREAMED_KEEP_LOADED:
parser.scanStr((char *)params, "%b", &_streamedKeepLoaded);
break;
case TOKEN_NAME:
setName((char *)params);
break;
case TOKEN_EDITOR_BG_FILE:
if (_gameRef->_editorMode) {
delete[] _editorBgFile;
_editorBgFile = new char[strlen((char *)params) + 1];
if (_editorBgFile) strcpy(_editorBgFile, (char *)params);
}
break;
case TOKEN_EDITOR_BG_OFFSET_X:
parser.scanStr((char *)params, "%d", &_editorBgOffsetX);
break;
case TOKEN_EDITOR_BG_OFFSET_Y:
parser.scanStr((char *)params, "%d", &_editorBgOffsetY);
break;
case TOKEN_EDITOR_BG_ALPHA:
parser.scanStr((char *)params, "%d", &_editorBgAlpha);
_editorBgAlpha = MIN(_editorBgAlpha, 255);
_editorBgAlpha = MAX(_editorBgAlpha, 0);
break;
case TOKEN_FRAME: {
int FrameLifeTime = lifeTime;
if (cacheType == CACHE_HALF && frameCount % 2 != 1) FrameLifeTime = -1;
frame = new CBFrame(_gameRef);
if (DID_FAIL(frame->loadBuffer(params, FrameLifeTime, _streamedKeepLoaded))) {
delete frame;
_gameRef->LOG(0, "Error parsing frame %d", frameCount);
return STATUS_FAILED;
}
_frames.add(frame);
frameCount++;
if (_currentFrame == -1) _currentFrame = 0;
}
break;
case TOKEN_EDITOR_PROPERTY:
parseEditorProperty(params, false);
break;
}
}
if (cmd == PARSERR_TOKENNOTFOUND) {
_gameRef->LOG(0, "Syntax error in SPRITE definition");
return STATUS_FAILED;
}
_canBreak = !_continuous;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////
void CBSprite::reset() {
if (_frames.getSize() > 0) _currentFrame = 0;
else _currentFrame = -1;
killAllSounds();
_lastFrameTime = 0;
_finished = false;
_moveX = _moveY = 0;
}
//////////////////////////////////////////////////////////////////////
bool CBSprite::GetCurrentFrame(float zoomX, float zoomY) {
//if(_owner && _owner->_freezable && _gameRef->_state == GAME_FROZEN) return true;
if (_currentFrame == -1) return false;
uint32 timer;
if (_owner && _owner->_freezable) timer = _gameRef->_timer;
else timer = _gameRef->_liveTimer;
int lastFrame = _currentFrame;
// get current frame
if (!_paused && !_finished && timer >= _lastFrameTime + _frames[_currentFrame]->_delay && _lastFrameTime != 0) {
if (_currentFrame < _frames.getSize() - 1) {
_currentFrame++;
if (_continuous) _canBreak = (_currentFrame == _frames.getSize() - 1);
} else {
if (_looping) {
_currentFrame = 0;
_canBreak = true;
} else {
_finished = true;
_canBreak = true;
}
}
_lastFrameTime = timer;
}
_changed = (lastFrame != _currentFrame || (_looping && _frames.getSize() == 1));
if (_lastFrameTime == 0) {
_lastFrameTime = timer;
_changed = true;
if (_continuous) _canBreak = (_currentFrame == _frames.getSize() - 1);
}
if (_changed) {
_moveX = _frames[_currentFrame]->_moveX;
_moveY = _frames[_currentFrame]->_moveY;
if (zoomX != 100 || zoomY != 100) {
_moveX = (int)((float)_moveX * (float)(zoomX / 100.0f));
_moveY = (int)((float)_moveY * (float)(zoomY / 100.0f));
}
}
return _changed;
}
//////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::display(int X, int Y, CBObject *Register, float ZoomX, float ZoomY, uint32 Alpha, float Rotate, TSpriteBlendMode BlendMode) {
if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) return STATUS_OK;
// on change...
if (_changed) {
if (_frames[_currentFrame]->_killSound) {
killAllSounds();
}
applyEvent("FrameChanged");
_frames[_currentFrame]->oneTimeDisplay(_owner, _gameRef->_editorMode && _editorMuted);
}
// draw frame
return _frames[_currentFrame]->draw(X - _gameRef->_offsetX, Y - _gameRef->_offsetY, Register, ZoomX, ZoomY, _precise, Alpha, _editorAllFrames, Rotate, BlendMode);
}
//////////////////////////////////////////////////////////////////////////
CBSurface *CBSprite::getSurface() {
// only used for animated textures for 3D models
if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) return NULL;
CBFrame *Frame = _frames[_currentFrame];
if (Frame && Frame->_subframes.getSize() > 0) {
CBSubFrame *Subframe = Frame->_subframes[0];
if (Subframe) return Subframe->_surface;
else return NULL;
} else return NULL;
}
//////////////////////////////////////////////////////////////////////////
bool CBSprite::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, float scaleY) {
if (!rect) return false;
CBPlatform::setRectEmpty(rect);
for (int i = 0; i < _frames.getSize(); i++) {
Rect32 frame;
Rect32 temp;
CBPlatform::copyRect(&temp, rect);
_frames[i]->getBoundingRect(&frame, x, y, scaleX, scaleY);
CBPlatform::unionRect(rect, &temp, &frame);
}
return true;
}
//////////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::saveAsText(CBDynBuffer *buffer, int indent) {
buffer->putTextIndent(indent, "SPRITE {\n");
buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name);
buffer->putTextIndent(indent + 2, "LOOPING=%s\n", _looping ? "TRUE" : "FALSE");
buffer->putTextIndent(indent + 2, "CONTINUOUS=%s\n", _continuous ? "TRUE" : "FALSE");
buffer->putTextIndent(indent + 2, "PRECISE=%s\n", _precise ? "TRUE" : "FALSE");
if (_streamed) {
buffer->putTextIndent(indent + 2, "STREAMED=%s\n", _streamed ? "TRUE" : "FALSE");
if (_streamedKeepLoaded)
buffer->putTextIndent(indent + 2, "STREAMED_KEEP_LOADED=%s\n", _streamedKeepLoaded ? "TRUE" : "FALSE");
}
if (_editorMuted)
buffer->putTextIndent(indent + 2, "EDITOR_MUTED=%s\n", _editorMuted ? "TRUE" : "FALSE");
if (_editorBgFile) {
buffer->putTextIndent(indent + 2, "EDITOR_BG_FILE=\"%s\"\n", _editorBgFile);
buffer->putTextIndent(indent + 2, "EDITOR_BG_OFFSET_X=%d\n", _editorBgOffsetX);
buffer->putTextIndent(indent + 2, "EDITOR_BG_OFFSET_Y=%d\n", _editorBgOffsetY);
buffer->putTextIndent(indent + 2, "EDITOR_BG_ALPHA=%d\n", _editorBgAlpha);
}
CBScriptHolder::saveAsText(buffer, indent + 2);
int i;
// scripts
for (i = 0; i < _scripts.getSize(); i++) {
buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename);
}
for (i = 0; i < _frames.getSize(); i++) {
_frames[i]->saveAsText(buffer, indent + 2);
}
buffer->putTextIndent(indent, "}\n\n");
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::persist(CBPersistMgr *persistMgr) {
CBScriptHolder::persist(persistMgr);
persistMgr->transfer(TMEMBER(_canBreak));
persistMgr->transfer(TMEMBER(_changed));
persistMgr->transfer(TMEMBER(_paused));
persistMgr->transfer(TMEMBER(_continuous));
persistMgr->transfer(TMEMBER(_currentFrame));
persistMgr->transfer(TMEMBER(_editorAllFrames));
persistMgr->transfer(TMEMBER(_editorBgAlpha));
persistMgr->transfer(TMEMBER(_editorBgFile));
persistMgr->transfer(TMEMBER(_editorBgOffsetX));
persistMgr->transfer(TMEMBER(_editorBgOffsetY));
persistMgr->transfer(TMEMBER(_editorMuted));
persistMgr->transfer(TMEMBER(_finished));
_frames.persist(persistMgr);
persistMgr->transfer(TMEMBER(_lastFrameTime));
persistMgr->transfer(TMEMBER(_looping));
persistMgr->transfer(TMEMBER(_moveX));
persistMgr->transfer(TMEMBER(_moveY));
persistMgr->transfer(TMEMBER(_owner));
persistMgr->transfer(TMEMBER(_precise));
persistMgr->transfer(TMEMBER(_streamed));
persistMgr->transfer(TMEMBER(_streamedKeepLoaded));
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// high level scripting interface
//////////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) {
//////////////////////////////////////////////////////////////////////////
// GetFrame
//////////////////////////////////////////////////////////////////////////
if (strcmp(name, "GetFrame") == 0) {
stack->correctParams(1);
int Index = stack->pop()->getInt(-1);
if (Index < 0 || Index >= _frames.getSize()) {
script->runtimeError("Sprite.GetFrame: Frame index %d is out of range.", Index);
stack->pushNULL();
} else stack->pushNative(_frames[Index], true);
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// DeleteFrame
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "DeleteFrame") == 0) {
stack->correctParams(1);
CScValue *Val = stack->pop();
if (Val->isInt()) {
int Index = Val->getInt(-1);
if (Index < 0 || Index >= _frames.getSize()) {
script->runtimeError("Sprite.DeleteFrame: Frame index %d is out of range.", Index);
}
} else {
CBFrame *Frame = (CBFrame *)Val->getNative();
for (int i = 0; i < _frames.getSize(); i++) {
if (_frames[i] == Frame) {
if (i == _currentFrame) _lastFrameTime = 0;
delete _frames[i];
_frames.removeAt(i);
break;
}
}
}
stack->pushNULL();
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// Reset
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Reset") == 0) {
stack->correctParams(0);
reset();
stack->pushNULL();
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// AddFrame
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "AddFrame") == 0) {
stack->correctParams(1);
CScValue *val = stack->pop();
const char *filename = NULL;
if (!val->isNULL()) filename = val->getString();
CBFrame *frame = new CBFrame(_gameRef);
if (filename != NULL) {
CBSubFrame *sub = new CBSubFrame(_gameRef);
if (DID_SUCCEED(sub->setSurface(filename))) {
sub->setDefaultRect();
frame->_subframes.add(sub);
} else delete sub;
}
_frames.add(frame);
stack->pushNative(frame, true);
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// InsertFrame
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "InsertFrame") == 0) {
stack->correctParams(2);
int index = stack->pop()->getInt();
if (index < 0)
index = 0;
CScValue *val = stack->pop();
const char *filename = NULL;
if (!val->isNULL())
filename = val->getString();
CBFrame *frame = new CBFrame(_gameRef);
if (filename != NULL) {
CBSubFrame *sub = new CBSubFrame(_gameRef);
if (DID_SUCCEED(sub->setSurface(filename))) frame->_subframes.add(sub);
else delete sub;
}
if (index >= _frames.getSize())
_frames.add(frame);
else _frames.insertAt(index, frame);
stack->pushNative(frame, true);
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// Pause
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Pause") == 0) {
stack->correctParams(0);
_paused = true;
stack->pushNULL();
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// Play
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Play") == 0) {
stack->correctParams(0);
_paused = false;
stack->pushNULL();
return STATUS_OK;
}
else return CBScriptHolder::scCallMethod(script, stack, thisStack, name);
}
//////////////////////////////////////////////////////////////////////////
CScValue *CBSprite::scGetProperty(const char *name) {
_scValue->setNULL();
//////////////////////////////////////////////////////////////////////////
// Type
//////////////////////////////////////////////////////////////////////////
if (strcmp(name, "Type") == 0) {
_scValue->setString("sprite");
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// NumFrames (RO)
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "NumFrames") == 0) {
_scValue->setInt(_frames.getSize());
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// CurrentFrame
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "CurrentFrame") == 0) {
_scValue->setInt(_currentFrame);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// PixelPerfect
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "PixelPerfect") == 0) {
_scValue->setBool(_precise);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// Looping
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Looping") == 0) {
_scValue->setBool(_looping);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// Owner (RO)
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Owner") == 0) {
if (_owner == NULL) _scValue->setNULL();
else _scValue->setNative(_owner, true);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// Finished (RO)
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Finished") == 0) {
_scValue->setBool(_finished);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// Paused (RO)
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Paused") == 0) {
_scValue->setBool(_paused);
return _scValue;
}
else return CBScriptHolder::scGetProperty(name);
}
//////////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::scSetProperty(const char *name, CScValue *value) {
//////////////////////////////////////////////////////////////////////////
// CurrentFrame
//////////////////////////////////////////////////////////////////////////
if (strcmp(name, "CurrentFrame") == 0) {
_currentFrame = value->getInt(0);
if (_currentFrame >= _frames.getSize() || _currentFrame < 0) {
_currentFrame = -1;
}
_lastFrameTime = 0;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// PixelPerfect
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "PixelPerfect") == 0) {
_precise = value->getBool();
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
// Looping
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "Looping") == 0) {
_looping = value->getBool();
return STATUS_OK;
}
else return CBScriptHolder::scSetProperty(name, value);
}
//////////////////////////////////////////////////////////////////////////
const char *CBSprite::scToString() {
return "[sprite]";
}
//////////////////////////////////////////////////////////////////////////
ERRORCODE CBSprite::killAllSounds() {
for (int i = 0; i < _frames.getSize(); i++) {
if (_frames[i]->_sound)
_frames[i]->_sound->stop();
}
return STATUS_OK;
}
} // end of namespace WinterMute
|