From 8b8e44782659c65b9899f81a1ad5e09477c37354 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 22 Feb 2009 17:11:32 -0500 Subject: Engine: Rewrote Database Transition storage --- src/com/fourisland/fourpuzzle/Display.java | 8 ++- .../fourisland/fourpuzzle/database/Database.java | 6 +-- .../fourpuzzle/database/Transitions.java | 58 ++++------------------ .../fourpuzzle/gamestate/GameOverGameState.java | 2 +- .../fourpuzzle/gamestate/TitleScreenGameState.java | 4 +- .../gamestate/mapview/event/SpecialEvent.java | 6 +-- .../fourpuzzle/transition/TransitionPair.java | 38 ++++++++++++++ 7 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/transition/TransitionPair.java (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index cf1cb2d..a8c9a37 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -11,6 +11,7 @@ import com.fourisland.fourpuzzle.transition.MultidirectionalTransition; import com.fourisland.fourpuzzle.transition.OutTransition; import com.fourisland.fourpuzzle.transition.Transition; import com.fourisland.fourpuzzle.transition.TransitionDirection; +import com.fourisland.fourpuzzle.transition.TransitionPair; import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; import com.fourisland.fourpuzzle.util.Renderable; import java.awt.Color; @@ -208,7 +209,7 @@ public class Display { } private static Executor transitioner = Executors.newSingleThreadExecutor(); - public static void transition(final Transition out, final GameState gameState, final Transition in, boolean thread) + public static void transition(final OutTransition out, final GameState gameState, final InTransition in, boolean thread) { Runnable transitionCall = new Runnable() { public void run() @@ -237,6 +238,11 @@ public class Display { } } + public static void transition(TransitionPair trans, GameState gameState, boolean thread) + { + transition(trans.getOutTransition(), gameState, trans.getInTransition(), thread); + } + public static boolean isTransitionRunning() { return transitionRunning; diff --git a/src/com/fourisland/fourpuzzle/database/Database.java b/src/com/fourisland/fourpuzzle/database/Database.java index 922ab60..03405c8 100755 --- a/src/com/fourisland/fourpuzzle/database/Database.java +++ b/src/com/fourisland/fourpuzzle/database/Database.java @@ -6,7 +6,7 @@ package com.fourisland.fourpuzzle.database; import com.fourisland.fourpuzzle.gamestate.mapview.Map; -import com.fourisland.fourpuzzle.transition.Transition; +import com.fourisland.fourpuzzle.transition.TransitionPair; import java.util.HashMap; /** @@ -77,7 +77,7 @@ public class Database { key.setValue(value); } - public static Transition getTransition(Transitions key) + public static TransitionPair getTransition(Transitions key) { return key.getValue().copy(); } @@ -96,7 +96,7 @@ public class Database { * @param key The transition to change * @param value The transition to change it to */ - public static void setTransition(Transitions key, Transition value) + public static void setTransition(Transitions key, TransitionPair value) { key.setValue(value); } diff --git a/src/com/fourisland/fourpuzzle/database/Transitions.java b/src/com/fourisland/fourpuzzle/database/Transitions.java index 98345a9..74c0674 100644 --- a/src/com/fourisland/fourpuzzle/database/Transitions.java +++ b/src/com/fourisland/fourpuzzle/database/Transitions.java @@ -6,71 +6,33 @@ package com.fourisland.fourpuzzle.database; import com.fourisland.fourpuzzle.transition.FadeTransition; -import com.fourisland.fourpuzzle.transition.InTransition; -import com.fourisland.fourpuzzle.transition.MultidirectionalTransition; -import com.fourisland.fourpuzzle.transition.OutTransition; import com.fourisland.fourpuzzle.transition.SquareTransition; -import com.fourisland.fourpuzzle.transition.Transition; import com.fourisland.fourpuzzle.transition.TransitionDirection; -import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; +import com.fourisland.fourpuzzle.transition.TransitionPair; /** * * @author hatkirby */ public enum Transitions { - TitleExit(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), - TitleToMap(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), - MapExit(TransitionDirection.Out, new SquareTransition(TransitionDirection.Out)), - MapEnter(TransitionDirection.In, new SquareTransition(TransitionDirection.In)), - MapToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), - TitleEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), - MapToGameOver(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), - GameOverEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), - GameOverToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)); - private final TransitionDirection dir; - private Transition trans; - private Transitions(TransitionDirection dir, Transition trans) + Generic(new TransitionPair(new FadeTransition(TransitionDirection.Out), new FadeTransition(TransitionDirection.In))), + Map(new TransitionPair(new SquareTransition(TransitionDirection.Out), new SquareTransition(TransitionDirection.In))); + + private TransitionPair trans; + private Transitions(TransitionPair trans) { - this.dir = dir; - - if (isTransitionSupported(dir, trans)) - { - this.trans = trans; - } else { - throw new TransitionUnsupportedException(trans.getClass().getName(), dir); - } + this.trans = trans; } - Transition getValue() + TransitionPair getValue() { return trans; } - void setValue(Transition trans) + void setValue(TransitionPair trans) { - if (isTransitionSupported(dir, trans)) - { - this.trans = trans; - } else { - throw new TransitionUnsupportedException(trans.getClass().getName(), dir); - } + this.trans = trans; } - private boolean isTransitionSupported(TransitionDirection dir, Transition trans) - { - if (trans instanceof MultidirectionalTransition) - { - return (((MultidirectionalTransition) trans).getDirection() == dir); - } else if (trans instanceof OutTransition) - { - return (dir == TransitionDirection.Out); - } else if (trans instanceof InTransition) - { - return (dir == TransitionDirection.In); - } - - return false; - } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index 670d900..692554e 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -38,7 +38,7 @@ public class GameOverGameState implements GameState { { Game.setSaveFile(new SaveFile()); - Display.transition(Database.getTransition(Transitions.GameOverToTitle), new TitleScreenGameState(), Database.getTransition(Transitions.TitleEnter), true); + Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index a72a22a..cedf5a6 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -56,7 +56,7 @@ public class TitleScreenGameState implements GameState { { Game.setSaveFile(new SaveFile()); - Display.transition(Database.getTransition(Transitions.TitleExit), new MapViewGameState("TestMap", 1, 2), Database.getTransition(Transitions.TitleToMap), true); + Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) { // Do nothing, yet @@ -65,7 +65,7 @@ public class TitleScreenGameState implements GameState { new Thread(new Runnable() { public void run() { try { - Display.transition(Database.getTransition(Transitions.TitleExit)); + Display.transition(Database.getTransition(Transitions.Generic).getOutTransition()); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index ebb0e27..c3bec32 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -157,7 +157,7 @@ public class SpecialEvent { { Audio.stopMusic(); - Display.transition(Database.getTransition(Transitions.MapToGameOver), new GameOverGameState(), Database.getTransition(Transitions.GameOverEnter), false); + Display.transition(Database.getTransition(Transitions.Generic), new GameOverGameState(), false); } /** @@ -169,7 +169,7 @@ public class SpecialEvent { { Audio.stopMusic(); - Display.transition(Database.getTransition(Transitions.MapToTitle), new TitleScreenGameState(), Database.getTransition(Transitions.TitleEnter), false); + Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), false); } private boolean startedTransition = false; @@ -211,7 +211,7 @@ public class SpecialEvent { { if (!startedTransition) { - Display.transition(Database.getTransition(Transitions.MapExit), new MapViewGameState(map, x, y), Database.getTransition(Transitions.MapEnter), false); + Display.transition(Database.getTransition(Transitions.Map), new MapViewGameState(map, x, y), false); } else { Game.setGameState(new MapViewGameState(map, x, y)); } diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionPair.java b/src/com/fourisland/fourpuzzle/transition/TransitionPair.java new file mode 100644 index 0000000..a73e671 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/TransitionPair.java @@ -0,0 +1,38 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.transition; + +/** + * + * @author hatkirby + */ +public class TransitionPair { + + private OutTransition out; + private InTransition in; + + public TransitionPair(OutTransition out, InTransition in) + { + this.out = out; + this.in = in; + } + + public OutTransition getOutTransition() + { + return out; + } + + public InTransition getInTransition() + { + return in; + } + + public TransitionPair copy() + { + return new TransitionPair((OutTransition) out.copy(), (InTransition) in.copy()); + } + +} -- cgit 1.4.1