forked from Grasscutters/Grasscutter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7410a0
commit 6a42133
Showing
3 changed files
with
102 additions
and
13 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,50 @@ | ||
package emu.grasscutter.scripts; | ||
|
||
import emu.grasscutter.scripts.constants.EventType; | ||
import emu.grasscutter.scripts.data.ScriptArgs; | ||
import lombok.*; | ||
|
||
import java.util.*; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public final class SceneTimeAxis { | ||
private final Timer timer = new Timer(); | ||
|
||
private final SceneScriptManager handle; | ||
private final int groupId; | ||
|
||
private final String identifier; | ||
private final int delay; | ||
private final boolean loop; | ||
|
||
/** | ||
* Schedules the task to run. | ||
*/ | ||
public void start() { | ||
if (this.loop) { | ||
this.timer.scheduleAtFixedRate( | ||
new Task(), this.delay, this.delay); | ||
} else { | ||
this.timer.schedule(new Task(), this.delay); | ||
} | ||
} | ||
|
||
/** | ||
* Terminates a repeating task. | ||
*/ | ||
public void stop() { | ||
this.timer.cancel(); | ||
} | ||
|
||
final class Task extends TimerTask { | ||
@Override | ||
public void run() { | ||
// Invoke script event. | ||
SceneTimeAxis.this.handle.callEvent(new ScriptArgs( | ||
SceneTimeAxis.this.groupId, | ||
EventType.EVENT_TIME_AXIS_PASS | ||
).setEventSource(SceneTimeAxis.this.identifier)); | ||
} | ||
} | ||
} |
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