Skip to content

Commit

Permalink
Fix VCR to record simultaneous keys+mouse, closes HaxeFlixel#1739 (Ha…
Browse files Browse the repository at this point in the history
  • Loading branch information
IBwWG authored and Gama11 committed Apr 22, 2016
1 parent a475b52 commit 71cdf01
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
3 changes: 2 additions & 1 deletion flixel/input/mouse/FlxMouse.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import flash.Lib;
import flash.ui.Mouse;
import flash.Vector;
import flixel.FlxG;
import flixel.input.FlxInput.FlxInputState;
import flixel.input.IFlxInputManager;
import flixel.input.mouse.FlxMouseButton;
import flixel.system.FlxAssets;
import flixel.system.replay.MouseRecord;
import flixel.util.FlxDestroyUtil;
import flixel.input.mouse.FlxMouseButton.FlxMouseButtonID;
#if FLX_NATIVE_CURSOR
import flash.ui.MouseCursor;
import flash.ui.MouseCursorData;
Expand Down
4 changes: 2 additions & 2 deletions flixel/system/replay/FlxReplay.hx
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ 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)
Expand Down
74 changes: 74 additions & 0 deletions tests/unit/src/flixel/system/replay/FlxReplayTest.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package flixel.system.replay;

import flixel.input.keyboard.FlxKey;
import massive.munit.Assert;

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

@Before
function before()
{
seed = 123456789;
frameCount = 300;
fgr = seed + "\n";
var key:Int;
var x:Int;
var y:Int;
var possibleKeys:Array<Int> = [for (key in FlxKey.toStringMap.keys()) key];
for (key in [-1, -2, 192, 220]) // exclude not-really-keys, and debugger activators (so as not to affect other tests by having the debugger open)
possibleKeys.remove(key);
for (i in 0...frameCount)
{
key = possibleKeys[i % possibleKeys.length];
x = i % FlxG.width;
y = FlxG.height - (i % FlxG.height);
fgr += i + "k" + key + ":1m" + x + "," + y + ",2,0\n"; // each frame has a simultaneous key-already-down and mouse-just-down
}
fgr += (frameCount++) + "km0,0,2,0\n"; // put everything back how it was for the next test
}

@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();
step();
}
var resavedFGR:String = replayRecorder.save();
Assert.areEqual(fgr, resavedFGR);
}
}

0 comments on commit 71cdf01

Please sign in to comment.