Skip to content
This repository has been archived by the owner on Dec 10, 2017. It is now read-only.

Commit

Permalink
Ignore clicks if not in clickable state
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Aug 7, 2012
1 parent a779bce commit 1ab1502
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/kacount/util/StateMachine.as
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ package kacount.util {
};
}

public function transition(transitionName:String, ... args:Array):void {
if (!this._template.isTransition(transitionName)) {
throw new Error("Invalid transition: " + transitionName);
public function canTransition(transitionName:String):Boolean {
return this._template.findTransitions(this._state, transitionName).length > 0;
}

private function validTransition(name:String):Boolean {
return this._template.isTransition(name);
}

private function validateTransition(name:String):void {
if (!this.validTransition(name)) {
throw new Error("Invalid transition: " + name);
}
}

public function transition(transitionName:String, ... args:Array):void {
this.validateTransition(transitionName);

var ts:Vector.<StateTransition> = this._template.findTransitions(this._state, transitionName);
if (ts.length === 1) {
Expand Down
6 changes: 4 additions & 2 deletions src/kacount/view/Player.as
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ package kacount.view {
}

public function click():void {
this._sm.click();
Sounds.bloop.play();
if (this._sm.canTransition('click')) {
this._sm.click();
Sounds.bloop.play();
}
}

public function start():void { this._sm.start(); }
Expand Down

0 comments on commit 1ab1502

Please sign in to comment.