This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from zaethan/master
New Timer node
- Loading branch information
Showing
3 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package armory.logicnode; | ||
|
||
class TimerNode extends LogicNode { | ||
|
||
var currentDuration:Float = 0.0; | ||
var duration:Float = 0.0; | ||
|
||
var repetitions:Int = 0; | ||
var totalRepetitions:Int = 0; | ||
|
||
var running:Bool = false; | ||
|
||
var pause:Bool = false; | ||
var paused:Bool = false; | ||
|
||
var stop:Bool = false; | ||
|
||
public function new(tree:LogicTree) { | ||
super(tree); | ||
} | ||
|
||
override function run() { | ||
pause = inputs[1].get(); | ||
stop = inputs[2].get(); | ||
if(!running && !(stop || pause || paused)) { | ||
duration = inputs[3].get(); | ||
currentDuration = duration; | ||
repetitions = inputs[4].get(); | ||
totalRepetitions = repetitions; | ||
running = true; | ||
tree.notifyOnUpdate(update); | ||
} | ||
if(!running && !(stop || pause) && paused) { | ||
paused = false; | ||
running = true; | ||
} | ||
} | ||
|
||
override function get(from:Int):Dynamic { | ||
if(from == 2) { | ||
return running; | ||
} else { | ||
if(from == 3) { | ||
return paused; | ||
} else { | ||
if(from == 4) { | ||
return currentDuration; | ||
} else { | ||
if(from == 5) { | ||
if(repetitions < 0) { | ||
return 0; | ||
} else { | ||
return (totalRepetitions - repetitions + 1 - currentDuration/duration)/(totalRepetitions+1); | ||
} | ||
} else { | ||
return totalRepetitions - repetitions; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function update() { | ||
pause = inputs[1].get(); | ||
stop = inputs[2].get(); | ||
|
||
if(running && !(stop || pause)) { | ||
currentDuration -= iron.system.Time.delta; | ||
if(currentDuration <= 0) { | ||
runOutputs(0); | ||
if(repetitions == 0) { | ||
runOutputs(1); | ||
tree.removeUpdate(update); | ||
running = false; | ||
currentDuration = 0.0; | ||
duration = 0.0; | ||
repetitions = 0; | ||
totalRepetitions = 0; | ||
paused = false; | ||
} | ||
if(repetitions > 0) { | ||
repetitions -= 1; | ||
currentDuration = duration; | ||
} | ||
if(repetitions < 0) { | ||
currentDuration = duration; | ||
} | ||
} | ||
} | ||
|
||
if(running && pause) { | ||
running = false; | ||
if(!stop && pause) | ||
paused = true; | ||
} | ||
|
||
if(paused && !pause) { | ||
running = true; | ||
paused = false; | ||
} | ||
|
||
if(stop) { | ||
running = false; | ||
currentDuration = 0.0; | ||
duration = 0.0; | ||
repetitions = 0; | ||
totalRepetitions = 0; | ||
paused = false; | ||
tree.removeUpdate(update); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters