Skip to content

Commit

Permalink
Merge branch 'vcr-flxbutton-mouseup-fix' of https://github.com/IBwWG/…
Browse files Browse the repository at this point in the history
…flixel into vcr-flxbutton-mouseup-fix
  • Loading branch information
IBwWG committed Apr 22, 2016
2 parents b089ca5 + dba9e6e commit a848263
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 5 deletions.
6 changes: 3 additions & 3 deletions flixel/system/replay/FlxReplay.hx
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ class FlxReplay

#if FLX_KEYBOARD
var keysRecord:Array<CodeValuePair> = FlxG.keys.record();
if (keysRecord == null) continueFrame = false;
if (keysRecord != null) continueFrame = false;
#end

#if FLX_MOUSE
var mouseRecord:MouseRecord = FlxG.mouse.record();
if (mouseRecord == null) continueFrame = false;
if (mouseRecord != null) continueFrame = false;
#end

if (continueFrame)
{
frame++;
Expand Down
12 changes: 12 additions & 0 deletions flixel/tweens/FlxTween.hx
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ typedef TweenOptions =
?loopDelay:Null<Float>
}

/**
* A simple manager for tracking and updating game tween objects. Normally accessed via the static `FlxTween.manager` rather than being created separately.
*/
@:access(flixel.tweens.FlxTween)
class FlxTweenManager extends FlxBasic
{
Expand Down Expand Up @@ -796,4 +799,13 @@ class FlxTweenManager extends FlxBasic
remove(_tweens[0]);
}
}
/**
* Immediately updates all tweens of type PERSIST or ONESHOT to their endings.
*/
public function completeAll():Void
{
for (tween in _tweens)
if (tween.type == FlxTween.PERSIST || tween.type == FlxTween.ONESHOT)
tween.update(tween.duration);
}
}
17 changes: 15 additions & 2 deletions flixel/util/FlxTimer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class FlxTimer implements IFlxDestroyable
}

/**
* A simple manager for tracking and updating game timer objects.
* A simple manager for tracking and updating game timer objects. Normally accessed via the static `FlxTimer.manager` rather than being created separately.
*/
class FlxTimerManager extends FlxBasic
{
Expand Down Expand Up @@ -273,4 +273,17 @@ class FlxTimerManager extends FlxBasic
{
FlxArrayUtil.clearArray(_timers);
}
}

/**
* Calls the `onComplete` function of all timers, then removes them from the timer manager.
*
* WARNING: This just calls `onComplete()` without modifying the timer first, so it may not be appropriate
* for use with callbacks that rely on properties of the timer that change throughout the timer's lifespan.
*/
public function completeAll():Void
{
for (timer in _timers)
timer.onComplete(timer);
clear();
}
}
2 changes: 2 additions & 0 deletions tests/unit/src/TestSuite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import flixel.system.FlxAssetsTest;
import flixel.system.FlxSoundTest;
import flixel.system.frontEnds.DebuggerFontEndTest;
import flixel.system.frontEnds.SoundFrontEndTest;
import flixel.system.replay.FlxReplayTest;
import flixel.text.FlxBitmapTextTest;
import flixel.text.FlxTextTest;
import flixel.tile.FlxTileblockTest;
Expand Down Expand Up @@ -92,6 +93,7 @@ class TestSuite extends massive.munit.TestSuite
add(flixel.system.FlxSoundTest);
add(flixel.system.frontEnds.DebuggerFontEndTest);
add(flixel.system.frontEnds.SoundFrontEndTest);
add(flixel.system.replay.FlxReplayTest);
add(flixel.text.FlxBitmapTextTest);
add(flixel.text.FlxTextTest);
add(flixel.tile.FlxTileblockTest);
Expand Down
68 changes: 68 additions & 0 deletions tests/unit/src/flixel/system/replay/FlxReplayTest.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package flixel.system.replay;

import massive.munit.Assert;

class FlxReplayTest
{
var seed:Int;
var fgr:String;
var frameCount:Int;

@Before
function before()
{
seed = Std.random(0x3FFFFFFF);
frameCount = Std.random(10000) + 1;
fgr = seed + "\n";
var key:Int;
var x:Int;
var y:Int;
for (i in 0...frameCount)
{
key = Std.random(26) + 65; // some magic numbers here...I suppose this could be replaced with something more sophisticated involving Reflect and flixel.input.keyboard.FlxKeyList...
x = Std.random(FlxG.width);
y = Std.random(FlxG.height);
fgr += i + "k" + key + ":1m" + x + "," + y + ",2,0\n"; // each frame has a simultaneous key-already-down and mouse-just-down
}
}

@Test
function testReplayCreateSpecifyingSeed()
{
var replay = new FlxReplay();
replay.create(seed);
Assert.areEqual(seed, replay.seed);
}

@Test
function testReplayLoadSeed()
{
var replay = new FlxReplay();
replay.load(fgr);
Assert.areEqual(seed, replay.seed);
}

@Test
function testReplayLoadFrameCount()
{
var replay = new FlxReplay();
replay.load(fgr);
Assert.areEqual(frameCount, replay.frameCount);
}

@Test // #1739
function testReplayRecordSimultaneousKeydownAndMouseDown()
{
var replayPlayer = new FlxReplay();
var replayRecorder = new FlxReplay();
replayRecorder.create(seed);
replayPlayer.load(fgr);
while (!replayPlayer.finished)
{
replayPlayer.playNextFrame();
replayRecorder.recordFrame();
}
var resavedFGR:String = replayRecorder.save();
Assert.areEqual(fgr, resavedFGR);
}
}

0 comments on commit a848263

Please sign in to comment.