Reduced reflection usage / Improved event system
This commit is contained in:
@@ -48,7 +48,7 @@ public class ContentDatabase{
|
||||
//fire unlock event so other classes can use it
|
||||
if(ret){
|
||||
content.onUnlock();
|
||||
Events.fire(UnlockEvent.class, content);
|
||||
Events.fire(new UnlockEvent(content));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,64 +6,78 @@ import io.anuke.ucore.function.Event;
|
||||
|
||||
public class EventType{
|
||||
|
||||
public interface PlayEvent extends Event{
|
||||
void handle();
|
||||
public static class PlayEvent implements Event{
|
||||
|
||||
}
|
||||
|
||||
public interface ResetEvent extends Event{
|
||||
void handle();
|
||||
public static class ResetEvent implements Event{
|
||||
|
||||
}
|
||||
|
||||
public interface WaveEvent extends Event{
|
||||
void handle();
|
||||
public static class WaveEvent implements Event{
|
||||
|
||||
}
|
||||
|
||||
public interface GameOverEvent extends Event{
|
||||
void handle();
|
||||
public static class GameOverEvent implements Event{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is called from the logic thread.
|
||||
* DO NOT INITIALIZE GRAPHICS HERE.
|
||||
*/
|
||||
public interface WorldLoadEvent extends Event{
|
||||
void handle();
|
||||
public static class WorldLoadEvent implements Event{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the WorldLoadEvent is, and all logic has been loaded.
|
||||
* It is safe to intialize graphics here.
|
||||
*/
|
||||
public interface WorldLoadGraphicsEvent extends Event{
|
||||
void handle();
|
||||
public static class WorldLoadGraphicsEvent implements Event{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the logic thread. Do not access graphics here!
|
||||
*/
|
||||
public interface TileChangeEvent extends Event{
|
||||
void handle(Tile tile);
|
||||
public static class TileChangeEvent implements Event{
|
||||
public final Tile tile;
|
||||
|
||||
public TileChangeEvent(Tile tile){
|
||||
this.tile = tile;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO unimplemented; remove?
|
||||
public interface TileRemoveEvent extends Event{
|
||||
void handle(Tile tile, Team oldTeam);
|
||||
public static class StateChangeEvent implements Event{
|
||||
public final State from, to;
|
||||
|
||||
public StateChangeEvent(State from, State to){
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
}
|
||||
|
||||
public interface StateChangeEvent extends Event{
|
||||
void handle(State from, State to);
|
||||
public static class UnlockEvent implements Event{
|
||||
public final Content content;
|
||||
|
||||
public UnlockEvent(Content content){
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
public interface UnlockEvent extends Event{
|
||||
void handle(Content content);
|
||||
public static class BlockBuildEvent implements Event{
|
||||
public final Tile tile;
|
||||
public final Team team;
|
||||
|
||||
public BlockBuildEvent(Tile tile, Team team){
|
||||
this.tile = tile;
|
||||
this.team = team;
|
||||
}
|
||||
}
|
||||
|
||||
public interface BlockBuildEvent extends Event{
|
||||
void handle(Team team, Tile tile);
|
||||
}
|
||||
public static class ResizeEvent implements Event{
|
||||
|
||||
public interface ResizeEvent extends Event{
|
||||
void handle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ public class Saves{
|
||||
private long lastTimestamp;
|
||||
|
||||
public Saves(){
|
||||
Events.on(StateChangeEvent.class, (prev, state) -> {
|
||||
if(state == State.menu){
|
||||
Events.on(StateChangeEvent.class, event -> {
|
||||
if(event.to == State.menu){
|
||||
threads.run(() -> {
|
||||
totalPlaytime = 0;
|
||||
lastTimestamp = 0;
|
||||
|
||||
Reference in New Issue
Block a user