From cd6b39590b8aced78fc2f6ed0c345fb9af1960c0 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 24 Jan 2009 15:25:58 -0500 Subject: Replaced checked exceptions with RuntimeException --- src/com/fourisland/fourpuzzle/Audio.java | 68 ++++++++++++---------- src/com/fourisland/fourpuzzle/Display.java | 4 +- src/com/fourisland/fourpuzzle/Game.java | 2 +- src/com/fourisland/fourpuzzle/GameCharacters.java | 2 +- .../fourpuzzle/NoCharactersInPartyException.java | 14 ----- .../fourisland/fourpuzzle/PuzzleApplication.java | 54 ++++++++++------- src/com/fourisland/fourpuzzle/SaveFile.java | 24 +++++--- .../fourpuzzle/gamestate/GameOverGameState.java | 13 +++-- .../fourisland/fourpuzzle/gamestate/GameState.java | 10 ++-- .../fourpuzzle/gamestate/TitleScreenGameState.java | 13 +++-- .../fourpuzzle/gamestate/mapview/CharSet.java | 3 +- .../fourpuzzle/gamestate/mapview/ChipSet.java | 30 ++++++---- .../fourpuzzle/gamestate/mapview/Map.java | 4 +- .../gamestate/mapview/MapViewGameState.java | 38 +++++++----- .../fourpuzzle/gamestate/mapview/event/Event.java | 10 ++-- .../gamestate/mapview/event/HeroEvent.java | 20 +++---- .../gamestate/mapview/event/LayerEvent.java | 20 +++---- .../gamestate/mapview/event/PossibleEvent.java | 5 +- .../gamestate/mapview/event/SpecialEvent.java | 18 +++--- .../mapview/event/graphic/BlankEventGraphic.java | 3 +- .../mapview/event/graphic/CharSetEventGraphic.java | 2 +- .../mapview/event/graphic/EventGraphic.java | 2 +- .../mapview/event/movement/CustomMovementType.java | 2 +- .../mapview/event/movement/MovementType.java | 2 +- .../mapview/event/movement/RandomMovementType.java | 3 +- .../event/movement/StayStillMovementType.java | 2 +- .../precondition/HeroInPartyPrecondition.java | 3 +- .../event/precondition/HeroLevelPrecondition.java | 3 +- .../mapview/event/precondition/Precondition.java | 2 +- .../event/precondition/SwitchPrecondition.java | 3 +- .../precondition/VariableNumberPrecondition.java | 3 +- .../precondition/VariableVariablePrecondition.java | 3 +- .../mapview/event/specialmove/FaceMoveEvent.java | 2 +- .../mapview/event/specialmove/MoveEvent.java | 2 +- .../mapview/event/specialmove/MoveEventThread.java | 6 +- .../mapview/event/specialmove/StepMoveEvent.java | 10 +++- .../mapview/event/specialmove/WaitMoveEvent.java | 10 +++- .../fourpuzzle/transition/SquareTransition.java | 2 +- .../fourpuzzle/transition/Transition.java | 3 +- .../transition/TransitionUnsupportedException.java | 2 +- src/com/fourisland/fourpuzzle/util/Functions.java | 4 +- .../fourisland/fourpuzzle/util/ObjectLoader.java | 59 ++++++++++++++++--- .../fourpuzzle/util/ResourceNotFoundException.java | 29 +++++++++ 43 files changed, 320 insertions(+), 194 deletions(-) delete mode 100644 src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java create mode 100644 src/com/fourisland/fourpuzzle/util/ResourceNotFoundException.java diff --git a/src/com/fourisland/fourpuzzle/Audio.java b/src/com/fourisland/fourpuzzle/Audio.java index 39ce3d8..bc34eda 100644 --- a/src/com/fourisland/fourpuzzle/Audio.java +++ b/src/com/fourisland/fourpuzzle/Audio.java @@ -6,7 +6,11 @@ package com.fourisland.fourpuzzle; import com.fourisland.fourpuzzle.util.ObjectLoader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiSystem; +import javax.sound.midi.MidiUnavailableException; import javax.sound.midi.Sequencer; /** @@ -17,57 +21,61 @@ public class Audio { private static Sequencer seq; - public static void init() throws Exception + public static void init() { - seq = MidiSystem.getSequencer(); - seq.open(); + try { + seq = MidiSystem.getSequencer(); + seq.open(); - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - public void run() { - if (seq.isRunning()) - { - seq.stop(); - } + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + public void run() { + if (seq.isRunning()) { + seq.stop(); + } - seq.close(); - } - })); + seq.close(); + } + })); + } catch (MidiUnavailableException ex) { + Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); + } } - public static void playMusic(String file) throws Exception + public static void playMusic(String file) { playMusic(file, true, 1F); } - public static void playMusic(String file, boolean loop) throws Exception + public static void playMusic(String file, boolean loop) { playMusic(file, loop, 1F); } - public static void playMusic(String file, boolean loop, float speed) throws Exception + public static void playMusic(String file, boolean loop, float speed) { - seq.setSequence(ObjectLoader.getMusic(file)); + try { + seq.setSequence(ObjectLoader.getMusic(file)); - if (loop) - { - seq.setLoopCount(seq.LOOP_CONTINUOUSLY); - } else { - seq.setLoopCount(0); + if (loop) { + seq.setLoopCount(seq.LOOP_CONTINUOUSLY); + } else { + seq.setLoopCount(0); + } + + seq.setTempoFactor(speed); + + seq.start(); + } catch (InvalidMidiDataException ex) { + Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); } - - seq.setTempoFactor(speed); - - seq.start(); } - public static void stopMusic() throws Exception + public static void stopMusic() { - if (seq == null) + if (seq != null) { - init(); + seq.stop(); } - - seq.stop(); } } diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 45e6c22..6fab3ea 100644 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -21,7 +21,7 @@ public class Display { public static int tileAnimationFrame = 0; - public static void render(JDialog gameFrame) throws Exception + public static void render(JDialog gameFrame) { if (enabled) { @@ -57,7 +57,7 @@ public class Display { } } - private static void render(JDialog gameFrame, VolatileImage vImg) throws Exception + private static void render(JDialog gameFrame, VolatileImage vImg) { if (vImg.validate(gameFrame.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) { diff --git a/src/com/fourisland/fourpuzzle/Game.java b/src/com/fourisland/fourpuzzle/Game.java index 3e79dc5..0788a75 100644 --- a/src/com/fourisland/fourpuzzle/Game.java +++ b/src/com/fourisland/fourpuzzle/Game.java @@ -33,7 +33,7 @@ public class Game { { return gameState; } - public static void setGameState(GameState gameState) throws Exception + public static void setGameState(GameState gameState) { if (Game.gameState != null) { diff --git a/src/com/fourisland/fourpuzzle/GameCharacters.java b/src/com/fourisland/fourpuzzle/GameCharacters.java index 2a3b050..933b333 100644 --- a/src/com/fourisland/fourpuzzle/GameCharacters.java +++ b/src/com/fourisland/fourpuzzle/GameCharacters.java @@ -30,7 +30,7 @@ public class GameCharacters extends ArrayList return temp; } - public GameCharacter getLeader() throws Exception + public GameCharacter getLeader() { for (GameCharacter chara : this) { diff --git a/src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java b/src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java deleted file mode 100644 index 5d6d457..0000000 --- a/src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.fourisland.fourpuzzle; - -/** - * - * @author hatkirby - */ -public class NoCharactersInPartyException extends Exception { - -} diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 7a9aa6f..6fbe3a0 100644 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java @@ -130,27 +130,10 @@ public class PuzzleApplication extends Application { } } } - } catch (Throwable ex) { - JFrame errorBox = new JFrame(ex.getClass().getSimpleName()); - JLabel text = new JLabel(); - text.setText("
I'm sorry, but " + INSTANCE.getContext().getResourceMap().getString("Application.title") + - " has run into an error and been forced to quit.
Your save file has not been kept. The error was:

" + - ex.getMessage() + "
"); - if (ex instanceof Error) - { - text.setText(text.getText() + "

We have identified this problem as a serious error in the game."); - } - errorBox.add(text); - errorBox.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - errorBox.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - errorBox.pack(); - errorBox.setVisible(true); - ex.printStackTrace(); + } catch (RuntimeException ex) { + reportError(ex); + } catch (Error ex) { + reportError(ex); } } },"GameCycle").start(); @@ -160,4 +143,33 @@ public class PuzzleApplication extends Application { { return INSTANCE.getContext().getResourceMap().getString("Application.package"); } + + public void reportError(Throwable ex) + { + if ((ex instanceof Exception) && !(ex instanceof RuntimeException)) + { + return; + } + + JFrame errorBox = new JFrame(ex.getClass().getSimpleName()); + JLabel text = new JLabel(); + text.setText("
I'm sorry, but " + INSTANCE.getContext().getResourceMap().getString("Application.title") + + " has run into an error and been forced to quit.
Your save file has not been kept. The error was:

" + + ex.getMessage() + "
"); + if (ex instanceof Error) + { + text.setText(text.getText() + "

We have identified this problem as a serious error in the game."); + } + errorBox.add(text); + errorBox.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + errorBox.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + errorBox.pack(); + errorBox.setVisible(true); + ex.printStackTrace(); + } } diff --git a/src/com/fourisland/fourpuzzle/SaveFile.java b/src/com/fourisland/fourpuzzle/SaveFile.java index 27a5662..6e3e441 100644 --- a/src/com/fourisland/fourpuzzle/SaveFile.java +++ b/src/com/fourisland/fourpuzzle/SaveFile.java @@ -12,6 +12,8 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -21,9 +23,8 @@ public class SaveFile implements Serializable { /** * Creates a new SaveFile - * @throws java.lang.CloneNotSupportedException */ - public SaveFile() throws CloneNotSupportedException + public SaveFile() { switches = new HashMap(); party = GameCharacters.createParty(); @@ -35,21 +36,28 @@ public class SaveFile implements Serializable { /** * Loads a SaveFile * @param file The ID of the SaveFile to load - * @throws java.io.IOException - * @throws java.lang.ClassNotFoundException + * @throws IOException if the SaveFile specified does not exist */ - public SaveFile(int file) throws IOException, ClassNotFoundException + public SaveFile(int file) throws IOException { InputStream is = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openInputFile("Save" + file + ".sav"); ObjectInputStream ois = new ObjectInputStream(is); - SaveFile temp = (SaveFile) ois.readObject(); - + SaveFile temp = null; + try { + temp = (SaveFile) ois.readObject(); + } catch (IOException ex) { + Logger.getLogger(SaveFile.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(SaveFile.class.getName()).log(Level.SEVERE, null, ex); + } + switches = temp.getSwitches(); variables = temp.getVariables(); party = temp.getParty(); currentMap = temp.getCurrentMap(); - + ois.close(); + is.close(); } public void saveGame(int file) throws IOException diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index ebff457..48706ad 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -22,17 +22,18 @@ import java.util.logging.Logger; */ public class GameOverGameState implements GameState { - public void initalize() throws Exception + public void initalize() { Audio.playMusic("GameOver"); } - public void deinitalize() throws Exception + public void deinitalize() { Audio.stopMusic(); } - public void processInput() throws Exception { + public void processInput() + { if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) { Game.setSaveFile(new SaveFile()); @@ -49,11 +50,13 @@ public class GameOverGameState implements GameState { } } - public void doGameCycle() throws Exception { + public void doGameCycle() + { // Do nothing } - public void render(Graphics2D g) throws Exception { + public void render(Graphics2D g) + { g.drawImage(ObjectLoader.getImage("Picture", "GameOver"), 0, 0, null); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameState.java index 362631d..de4d7de 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/GameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameState.java @@ -13,12 +13,12 @@ import java.awt.Graphics2D; */ public interface GameState { - public void initalize() throws Exception; - public void deinitalize() throws Exception; + public void initalize(); + public void deinitalize(); - public void processInput() throws Exception; - public void doGameCycle() throws Exception; - public void render(Graphics2D g) throws Exception; + public void processInput(); + public void doGameCycle(); + public void render(Graphics2D g); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 1f9c376..683b361 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -17,17 +17,18 @@ import java.awt.event.KeyEvent; */ public class TitleScreenGameState implements GameState { - public void initalize() throws Exception + public void initalize() { Audio.playMusic("Opening"); } - public void deinitalize() throws Exception + public void deinitalize() { Audio.stopMusic(); } - public void processInput() throws Exception { + public void processInput() + { if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) { Game.setSaveFile(new SaveFile()); @@ -38,11 +39,13 @@ public class TitleScreenGameState implements GameState { } } - public void doGameCycle() throws Exception { + public void doGameCycle() + { // Do nothing, yet } - public void render(Graphics2D g) throws Exception { + public void render(Graphics2D g) + { g.drawImage(ObjectLoader.getImage("Picture", "Title"), 0, 0, null); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java index b6e23d6..841eaa4 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java @@ -29,7 +29,8 @@ public class CharSet { return charSetImage.getSubimage(sx, sy, 24, 32); } - public static CharSet getCharSet(String charSet) throws Exception { + public static CharSet getCharSet(String charSet) + { CharSet temp = new CharSet(); temp.charSetImage = ObjectLoader.getImage("CharSet", charSet); return temp; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java index 6eb40cc..7ebb4eb 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java @@ -7,11 +7,11 @@ package com.fourisland.fourpuzzle.gamestate.mapview; import com.fourisland.fourpuzzle.PuzzleApplication; import com.fourisland.fourpuzzle.util.ObjectLoader; -import java.awt.Graphics; -import java.awt.Image; +import com.fourisland.fourpuzzle.util.ResourceNotFoundException; import java.awt.image.BufferedImage; import java.util.HashMap; -import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -30,15 +30,25 @@ public abstract class ChipSet { return chipSetImage.getSubimage(sx, sy, 16, 16); } - public static ChipSet getChipSet(String chipSet) throws Exception + public static ChipSet getChipSet(String chipSet) { - Class chipSetClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.chipset." + chipSet); - Object chipSetObject = chipSetClass.newInstance(); - ChipSet temp = (ChipSet) chipSetObject; - temp.initalize(); - temp.chipSetImage = ObjectLoader.getImage("ChipSet", chipSet); + try { + Class chipSetClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.chipset." + chipSet); + Object chipSetObject = chipSetClass.newInstance(); + ChipSet temp = (ChipSet) chipSetObject; + temp.initalize(); + temp.chipSetImage = ObjectLoader.getImage("ChipSet", chipSet); + + return temp; + } catch (InstantiationException ex) { + Logger.getLogger(ChipSet.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(ChipSet.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + throw new ResourceNotFoundException("ChipSetData", chipSet); + } - return temp; + return null; } private HashMap chipSetData = new HashMap(); //162 diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 3df55dd..3e9c717 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java @@ -18,7 +18,7 @@ import java.util.Vector; */ public abstract class Map { - public abstract void initalize() throws Exception; + public abstract void initalize(); public void initalize(Dimension size) { @@ -59,7 +59,7 @@ public abstract class Map { return null; } - public boolean checkForCollision(int x, int y, Direction toMove) throws Exception + public boolean checkForCollision(int x, int y, Direction toMove) { if ((toMove == Direction.North) && (y == 0)) { diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 6aeac83..3d8d15d 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -17,8 +17,11 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; import com.fourisland.fourpuzzle.util.Functions; +import com.fourisland.fourpuzzle.util.ResourceNotFoundException; import java.awt.Graphics2D; import java.awt.event.KeyEvent; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -30,14 +33,14 @@ public class MapViewGameState implements GameState { boolean processInput = true; Map currentMap; - public MapViewGameState(String map, int x, int y) throws Exception + public MapViewGameState(String map, int x, int y) { //currentMap = ObjectLoader.getMap(map); setCurrentMap(map); Game.getSaveFile().getHero().setLocation(x, y); } - public void initalize() throws Exception + public void initalize() { //if (!currentMap.getMusic().equals("")) { @@ -45,7 +48,7 @@ public class MapViewGameState implements GameState { } } - public void deinitalize() throws Exception + public void deinitalize() { //if (!currentMap.getMusic().equals("")) { @@ -53,7 +56,7 @@ public class MapViewGameState implements GameState { } } - public void processInput() throws Exception + public void processInput() { if (processInput) { @@ -132,7 +135,7 @@ public class MapViewGameState implements GameState { } } - public void doGameCycle() throws Exception + public void doGameCycle() { HeroEvent hero = Game.getSaveFile().getHero(); if (hero.isMoving()) @@ -154,7 +157,7 @@ public class MapViewGameState implements GameState { } } - public void render(Graphics2D g) throws Exception + public void render(Graphics2D g) { ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet()); int i,x,y; @@ -202,19 +205,28 @@ public class MapViewGameState implements GameState { } } - public void initCurrentMap(String mapName) throws Exception + public void initCurrentMap(String mapName) { - Class mapClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.map." + mapName); - Object mapObject = mapClass.newInstance(); - Map map = (Map) mapObject; - map.initalize(); - currentMap = map; + try { + Class mapClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.map." + mapName); + Object mapObject = mapClass.newInstance(); + Map map = (Map) mapObject; + map.initalize(); + currentMap = map; + } catch (InstantiationException ex) { + Logger.getLogger(MapViewGameState.class.getName()).log(Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + Logger.getLogger(MapViewGameState.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + throw new ResourceNotFoundException("Map", mapName); + } } - public void setCurrentMap(String mapName) throws Exception + public void setCurrentMap(String mapName) { Game.getSaveFile().setCurrentMap(mapName); initCurrentMap(mapName); } + public Map getCurrentMap() { return currentMap; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index 1aa74c1..fbcfd7a 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java @@ -23,13 +23,13 @@ public interface Event { public void setLocation(Point location); public void setLocation(int x, int y); - public void render(Graphics g) throws Exception; + public void render(Graphics g); - public Direction getDirection() throws Exception; - public void setDirection(Direction direction) throws Exception; + public Direction getDirection(); + public void setDirection(Direction direction); public boolean isMoving(); - public void startMoving(Direction direction) throws Exception; + public void startMoving(Direction direction); - public Layer getLayer() throws Exception; + public Layer getLayer(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index 3bdb9de..50e16c8 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java @@ -12,7 +12,6 @@ import com.fourisland.fourpuzzle.Direction; import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.GameCharacter; import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; -import com.fourisland.fourpuzzle.NoCharactersInPartyException; /** * @@ -44,7 +43,7 @@ public class HeroEvent implements Event { location.setLocation(x, y); } - public void render(Graphics g) throws Exception + public void render(Graphics g) { int x = (location.x * 16) - 4; int y = (location.y * 16) - 16; @@ -66,15 +65,10 @@ public class HeroEvent implements Event { } } - try - { - GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); - if (!toDraw.getGraphic().equals("blank")) - { - g.drawImage(CharSet.getCharSet(toDraw.getGraphic()).getImage(toDraw.getGraphicOffset(), direction, animationStep), x, y, null); - } - } catch (NoCharactersInPartyException ex) + GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); + if (!toDraw.getGraphic().equals("blank")) { + g.drawImage(CharSet.getCharSet(toDraw.getGraphic()).getImage(toDraw.getGraphicOffset(), direction, animationStep), x, y, null); } } @@ -91,7 +85,7 @@ public class HeroEvent implements Event { private int moveTimer; private Direction moveDirection; - public void startMoving(Direction toMove) throws Exception + public void startMoving(Direction toMove) { setDirection(toMove); setAnimationStep(2); @@ -99,7 +93,7 @@ public class HeroEvent implements Event { moving = true; moveDirection = toMove; } - public void processMoving() throws Exception + public void processMoving() { if (moving) { @@ -149,7 +143,7 @@ public class HeroEvent implements Event { this.animationStep = animationStep; } - public Layer getLayer() throws Exception + public Layer getLayer() { return Layer.Middle; } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index b67f2aa..05192ce 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java @@ -68,7 +68,7 @@ public class LayerEvent implements Event { events.add(pe); } - private PossibleEvent getPossibleEvent() throws Exception + private PossibleEvent getPossibleEvent() { int i; for (i=(events.size()-1);i>-1;i--) @@ -89,7 +89,7 @@ public class LayerEvent implements Event { return new PossibleEvent(); } - public void render(Graphics g) throws Exception + public void render(Graphics g) { int x = (location.x * 16) - 4; int y = (location.y * 16) - 16; @@ -131,7 +131,7 @@ public class LayerEvent implements Event { private int moveTimer; private Direction moveDirection; - public void startMoving(Map map) throws Exception + public void startMoving(Map map) { Direction toMove = getPossibleEvent().getMovement().startMoving(); @@ -143,7 +143,7 @@ public class LayerEvent implements Event { } } } - public void startMoving(Direction toMove) throws Exception + public void startMoving(Direction toMove) { getPossibleEvent().setDirection(toMove); getPossibleEvent().setAnimationStep(2); @@ -151,7 +151,7 @@ public class LayerEvent implements Event { moving = true; moveDirection = toMove; } - public void processMoving() throws Exception + public void processMoving() { if (moving) { @@ -181,26 +181,26 @@ public class LayerEvent implements Event { } } - public Direction getDirection() throws Exception + public Direction getDirection() { return getPossibleEvent().getDirection(); } - public void setDirection(Direction direction) throws Exception + public void setDirection(Direction direction) { getPossibleEvent().setDirection(direction); } - public Layer getLayer() throws Exception + public Layer getLayer() { return getPossibleEvent().getLayer(); } - public EventCallTime getCalltime() throws Exception + public EventCallTime getCalltime() { return getPossibleEvent().getCalltime(); } - public EventCall getCallback() throws Exception + public EventCall getCallback() { return getPossibleEvent().getCallback(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index ce9773f..c18385d 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java @@ -47,7 +47,7 @@ public class PossibleEvent { animationStep = 1; } - public BufferedImage getImage() throws Exception + public BufferedImage getImage() { return graphic.getImage(); } @@ -88,7 +88,8 @@ public class PossibleEvent { return direction; } - public void setDirection(Direction direction) throws Exception { + public void setDirection(Direction direction) + { if (Functions.canTurn(this)) { this.direction = direction; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 121bbe8..077f42e 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -129,18 +129,16 @@ public class SpecialEvent { /** * Triggers the Game Over sequence - * @throws Exception */ - public void GameOver() throws Exception + public void GameOver() { throw new UnsupportedOperationException("Not yet implemented"); } /** * Returns the player to the Title Screen - * @throws Exception */ - public void TitleScreen() throws Exception + public void TitleScreen() { throw new UnsupportedOperationException("Not yet implemented"); } @@ -151,9 +149,8 @@ public class SpecialEvent { * @param map The name of the map to move to * @param x The X position on the map to move to * @param y The Y position on the map to move to - * @throws java.lang.Exception */ - public void Teleport(String map, int x, int y) throws Exception + public void Teleport(String map, int x, int y) { throw new UnsupportedOperationException("Not yet implemented"); } @@ -162,11 +159,14 @@ public class SpecialEvent { * Waits for a specified interval * * @param wait The time to wait in milliseconds - * @throws java.lang.InterruptedException */ - public void Wait(int wait) throws InterruptedException + public void Wait(int wait) { - Thread.sleep(wait); + try { + Thread.sleep(wait); + } catch (InterruptedException ex) { + Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex); + } } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java index 592c8a7..1f317f8 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java @@ -17,7 +17,8 @@ public class BlankEventGraphic implements EventGraphic { private Direction direction; private int animationStep; - public BufferedImage getImage() throws Exception { + public BufferedImage getImage() + { return null; } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java index b71a0b8..a2e8831 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java @@ -26,7 +26,7 @@ public class CharSetEventGraphic implements EventGraphic { this.graphicOffset = graphicOffset; } - public BufferedImage getImage() throws Exception + public BufferedImage getImage() { return CharSet.getCharSet(getGraphic()).getImage(getGraphicOffset(), getDirection(), getAnimationStep()); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java index 60afca5..7e83dd9 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java @@ -14,7 +14,7 @@ import java.awt.image.BufferedImage; */ public interface EventGraphic { - public BufferedImage getImage() throws Exception; + public BufferedImage getImage(); public Direction getDirection(); public void setDirection(Direction direction); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java index 3e3773f..5a82f91 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java @@ -21,7 +21,7 @@ public class CustomMovementType implements MovementType { this.moves = moves; } - public Direction startMoving() throws Exception + public Direction startMoving() { if (step >= moves.length) { diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java index 4911a54..5d5822e 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java @@ -13,7 +13,7 @@ import com.fourisland.fourpuzzle.Direction; */ public interface MovementType { - public Direction startMoving() throws Exception; + public Direction startMoving(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java index d0d96ce..b714ced 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java @@ -14,7 +14,8 @@ import java.util.Random; */ public class RandomMovementType implements MovementType { - public Direction startMoving() throws Exception { + public Direction startMoving() + { Random r = new Random(); int ra = r.nextInt(1000); Direction toMove = null; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java index a34a1f1..1f2a49c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java @@ -13,7 +13,7 @@ import com.fourisland.fourpuzzle.Direction; */ public class StayStillMovementType implements MovementType { - public Direction startMoving() throws Exception + public Direction startMoving() { return null; // Do nothing, stay still } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java index 7700674..0c0af20 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java @@ -20,7 +20,8 @@ public class HeroInPartyPrecondition implements Precondition { this.heroName = heroName; } - public boolean match() { + public boolean match() + { return Game.getSaveFile().getParty().exists(heroName); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java index 1b10e91..ae8183d 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java @@ -22,7 +22,8 @@ public class HeroLevelPrecondition implements Precondition { this.level = level; } - public boolean match() throws Exception { + public boolean match() + { return (Game.getSaveFile().getParty().exists(heroName) && (Game.getSaveFile().getParty().get(heroName).getLevel() == level)); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java index 3f75984..b275100 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java @@ -11,6 +11,6 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; */ public interface Precondition { - public boolean match() throws Exception; + public boolean match(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java index 794eae4..7bccadf 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java @@ -20,7 +20,8 @@ public class SwitchPrecondition implements Precondition { this.switchID = switchID; } - public boolean match() { + public boolean match() + { return (Game.getSaveFile().getSwitches().containsKey(switchID) && Game.getSaveFile().getSwitches().get(switchID)); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java index a3ce086..afedadd 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java @@ -25,7 +25,8 @@ public class VariableNumberPrecondition implements Precondition { this.number = number; } - public boolean match() { + public boolean match() + { if (Game.getSaveFile().getVariables().containsKey(variableID)) { int n1 = Game.getSaveFile().getVariables().get(variableID); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java index 1eb9b0c..dbdf019 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java @@ -25,7 +25,8 @@ public class VariableVariablePrecondition implements Precondition { this.variableID2 = variableID2; } - public boolean match() { + public boolean match() + { if (Game.getSaveFile().getVariables().containsKey(variableID)) { int n1 = Game.getSaveFile().getVariables().get(variableID); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java index a9dc891..fcc0a7a 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java @@ -20,7 +20,7 @@ public class FaceMoveEvent implements MoveEvent { this.direction = direction; } - public void doAction(Event ev) throws Exception + public void doAction(Event ev) { ev.setDirection(direction); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java index 66c9f6d..1d64d9e 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java @@ -14,6 +14,6 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; */ public interface MoveEvent { - public void doAction(Event ev) throws Exception; + public void doAction(Event ev); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index d6971f3..ab160f1 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java @@ -42,11 +42,7 @@ public class MoveEventThread implements Runnable { for (MoveEvent action : actions) { - try { - action.doAction(ev); - } catch (Exception ex) { - Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); - } + action.doAction(ev); } events.remove(ev); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java index 12b2421..74affc4 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java @@ -7,6 +7,8 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; import com.fourisland.fourpuzzle.Direction; import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -20,13 +22,17 @@ public class StepMoveEvent implements MoveEvent { this.direction = direction; } - public void doAction(Event ev) throws Exception + public void doAction(Event ev) { ev.startMoving(direction); while (ev.isMoving()) { - Thread.sleep(2); + try { + Thread.sleep(2); + } catch (InterruptedException ex) { + Logger.getLogger(StepMoveEvent.class.getName()).log(Level.SEVERE, null, ex); + } } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java index d9823d5..1464bcd 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java @@ -6,6 +6,8 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -19,9 +21,13 @@ public class WaitMoveEvent implements MoveEvent { this.wait = wait; } - public void doAction(Event ev) throws Exception + public void doAction(Event ev) { - Thread.sleep(wait); + try { + Thread.sleep(wait); + } catch (InterruptedException ex) { + Logger.getLogger(WaitMoveEvent.class.getName()).log(Level.SEVERE, null, ex); + } } } diff --git a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java index dc17844..d60282d 100644 --- a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java @@ -15,7 +15,7 @@ import java.awt.Graphics2D; public class SquareTransition extends Transition { private int tick; - public SquareTransition(boolean from) throws TransitionUnsupportedException + public SquareTransition(boolean from) { setDirection(from); diff --git a/src/com/fourisland/fourpuzzle/transition/Transition.java b/src/com/fourisland/fourpuzzle/transition/Transition.java index 83cec17..e25fbc9 100644 --- a/src/com/fourisland/fourpuzzle/transition/Transition.java +++ b/src/com/fourisland/fourpuzzle/transition/Transition.java @@ -14,7 +14,7 @@ import java.awt.Graphics2D; public abstract class Transition { private boolean way; - protected void setDirection(boolean from) throws TransitionUnsupportedException + protected void setDirection(boolean from) { if ((from) && !(isFromSupported())) { @@ -26,6 +26,7 @@ public abstract class Transition { way = from; } } + public boolean getDirection() { return way; diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java b/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java index a3d28ef..40f3db8 100644 --- a/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java +++ b/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java @@ -9,7 +9,7 @@ package com.fourisland.fourpuzzle.transition; * * @author hatkirby */ -public class TransitionUnsupportedException extends Exception { +public class TransitionUnsupportedException extends RuntimeException { public TransitionUnsupportedException(String className, String direction) { diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java index d1995f9..038ca46 100644 --- a/src/com/fourisland/fourpuzzle/util/Functions.java +++ b/src/com/fourisland/fourpuzzle/util/Functions.java @@ -15,7 +15,7 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.PossibleEvent; */ public class Functions { - public static boolean canTurn(PossibleEvent ev) throws Exception + public static boolean canTurn(PossibleEvent ev) { switch (ev.getAnimation()) { @@ -30,7 +30,7 @@ public class Functions { return false; } - public static boolean isFacing(Event ev1, Event ev2) throws Exception + public static boolean isFacing(Event ev1, Event ev2) { if ((ev1.getDirection() == Direction.North) && (ev2.getLocation().x == ev1.getLocation().x) && (ev2.getLocation().y == (ev1.getLocation().y - 1))) { diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java index c14a8a1..b149ddd 100644 --- a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java @@ -11,8 +11,13 @@ import java.awt.Image; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.awt.image.FilteredImageSource; +import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.imageio.ImageIO; +import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiSystem; import javax.sound.midi.Sequence; import org.jdesktop.application.ResourceMap; @@ -25,13 +30,25 @@ public class ObjectLoader { private static HashMap objectCache = new HashMap(); - public static BufferedImage getImage(String type, String name) throws Exception + public static BufferedImage getImage(String type, String name) { if (!objectCache.containsKey(type + "/" + name)) { ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; - BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename)); + InputStream str = rm.getClassLoader().getResourceAsStream(filename); + + if (str == null) + { + throw new ResourceNotFoundException(type, name); + } + + BufferedImage bImg = null; + try { + bImg = ImageIO.read(str); + } catch (IOException ex) { + Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); + } addToObjectCache(type,name,bImg); } @@ -39,13 +56,26 @@ public class ObjectLoader { return (BufferedImage) objectCache.get(type + "/" + name); } - public static BufferedImage getImage(String type, String name, int transparencyColor) throws Exception + public static BufferedImage getImage(String type, String name, int transparencyColor) { if (!objectCache.containsKey(type + "/" + name)) { ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); - String filename = rm.getResourcesDir() + type + "/" + name + ".png"; - BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename)); + String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; + InputStream str = rm.getClassLoader().getResourceAsStream(filename); + + if (str == null) + { + throw new ResourceNotFoundException(type, name); + } + + BufferedImage bImg = null; + try { + bImg = ImageIO.read(str); + } catch (IOException ex) { + Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); + } + bImg = new BufferedImage(bImg.getWidth(), bImg.getHeight(), BufferedImage.TYPE_INT_RGB); Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bImg.getSource(), new TransparentImageFilter(transparencyColor))); bImg.createGraphics().drawImage(image, 0, 0, null); @@ -65,7 +95,7 @@ public class ObjectLoader { return map; }*/ - public static void addToObjectCache(String type, String name, Object object) throws Exception + public static void addToObjectCache(String type, String name, Object object) { if (objectCache.size() >= 100) { @@ -75,13 +105,26 @@ public class ObjectLoader { objectCache.put(type + "/" + name, object); } - public static Sequence getMusic(String name) throws Exception + public static Sequence getMusic(String name) { if (!objectCache.containsKey("Music/" + name)) { ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); String filename = rm.getResourcesDir() + "music/" + name + ".mid"; - Sequence seq = MidiSystem.getSequence(rm.getClassLoader().getResourceAsStream(filename)); + InputStream str = rm.getClassLoader().getResourceAsStream(filename); + if (str == null) + { + throw new ResourceNotFoundException("Music", name); + } + + Sequence seq = null; + try { + seq = MidiSystem.getSequence(str); + } catch (InvalidMidiDataException ex) { + Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); + } addToObjectCache("Music", name, seq); } diff --git a/src/com/fourisland/fourpuzzle/util/ResourceNotFoundException.java b/src/com/fourisland/fourpuzzle/util/ResourceNotFoundException.java new file mode 100644 index 0000000..4db2f61 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/ResourceNotFoundException.java @@ -0,0 +1,29 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.util; + +/** + * + * @author hatkirby + */ +public class ResourceNotFoundException extends RuntimeException { + + String type; + String name; + + public ResourceNotFoundException(String type, String name) + { + this.type = type; + this.name = name; + } + + @Override + public String getMessage() + { + return type + " \"" + name + "\" could not be found"; + } + +} -- cgit 1.4.1