Fixed serialization bugs, bomb bug during dialogue
parent
6fac8e9a59
commit
e49c4cf4e8
|
@ -46,7 +46,6 @@ public class DialogueMenu extends TextBox implements Serializable {
|
|||
for (String s: newText) {
|
||||
currentLineWidth += metrics.stringWidth(s + " ");
|
||||
if (currentLineWidth - metrics.stringWidth(" ") < (GamePanel.GAME_WIDTH - PORTRAIT_WIDTH - PADDING*5)) {
|
||||
System.out.println(s + " " + currentLineWidth);
|
||||
lines.set(lastLineIndex, lines.get(lastLineIndex) + s + " ");
|
||||
} else {
|
||||
currentLineWidth = metrics.stringWidth(s);
|
||||
|
|
|
@ -28,15 +28,17 @@ public class FileManager {
|
|||
|
||||
public static Object readObjectFromFile(String fileLocation, List<String> allowedObject) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream objectStream;
|
||||
Object o;
|
||||
FileInputStream fileStream = new FileInputStream(fileLocation);
|
||||
if (!allowedObject.contains("Any")) {
|
||||
objectStream = new SafeObjectInputStream(fileStream, allowedObject);
|
||||
} else {
|
||||
objectStream = new ObjectInputStream(fileStream);
|
||||
}
|
||||
o = objectStream.readObject();
|
||||
objectStream.close();
|
||||
fileStream.close();
|
||||
return objectStream.readObject();
|
||||
return o;
|
||||
}
|
||||
|
||||
public static void writeObjectToFile(String fileLocation, Object o) throws IOException {
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.io.Serializable;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import javax.swing.*;
|
||||
|
@ -42,7 +43,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
// keeps track of how many ticks has elapsed since last frame change
|
||||
public int playerFrameCounter = 0;
|
||||
public int enemyFrameCounter = 0;
|
||||
public boolean isPaused, isDialogue, waitForDialogue;
|
||||
public boolean isPaused, isDialogue, waitForDialogue, mouseAlreadyTranslated;
|
||||
public PauseMenu pauseMenu;
|
||||
public DialogueMenu dialogueMenu;
|
||||
public ArrayList<String> dialogueArray = new ArrayList<String>();
|
||||
|
@ -143,13 +144,22 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
try {
|
||||
player.mousePressed(e);
|
||||
if (isDialogue || isPaused) {
|
||||
mouseAlreadyTranslated = true;
|
||||
keyPressed(new KeyEvent(new Component() {}, 0, 0, 0, KeyEvent.VK_ENTER));
|
||||
} else {
|
||||
player.mousePressed(e);
|
||||
}
|
||||
} catch (SpriteException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
player.mouseReleased(e);
|
||||
if (mouseAlreadyTranslated) {
|
||||
mouseAlreadyTranslated = false;
|
||||
} else if (!isDialogue && !isPaused) {
|
||||
player.mouseReleased(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -265,7 +275,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
|
||||
try {
|
||||
if (waitForDialogue) {
|
||||
System.out.println(dialogueArray);
|
||||
dialogueMenu.currentFrame = dialogueArray.get(0).length();
|
||||
dialogueMenu.frameCounter = 0;
|
||||
dialogueMenu.draw(g, dialogueArray.get(0), Color.white, Color.black);
|
||||
|
@ -274,7 +283,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
isDialogue = false;
|
||||
throw new RuntimeException(e);
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +394,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
// atomic save to prevent EOF errors
|
||||
FileManager.writeObjectToFile("local\\temp_state.dat", this);
|
||||
Files.move(Path.of("local", "temp_state.dat"), Path.of("local", "game_state.dat"), ATOMIC_MOVE);
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | ConcurrentModificationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
repaint();
|
||||
|
@ -421,10 +430,14 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
isPaused = !isPaused;
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
dialogueMenu.currentFrame = 0;
|
||||
dialogueMenu.frameCounter = 0;
|
||||
dialogueArray.remove(0);
|
||||
waitForDialogue = false;
|
||||
if (!waitForDialogue) {
|
||||
waitForDialogue = true;
|
||||
} else {
|
||||
dialogueMenu.currentFrame = 0;
|
||||
dialogueMenu.frameCounter = 0;
|
||||
dialogueArray.remove(0);
|
||||
waitForDialogue = false;
|
||||
}
|
||||
} else {
|
||||
player.keyPressed(e);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ public class Player extends GenericSprite {
|
|||
public static int mouseX;
|
||||
public static int mouseY;
|
||||
|
||||
public boolean leftMouseDown;
|
||||
public transient boolean leftMouseDown;
|
||||
|
||||
public boolean rightMouseDown;
|
||||
public transient boolean rightMouseDown;
|
||||
boolean holdingSteel;
|
||||
|
||||
boolean canPlaceSteel;
|
||||
|
|
Loading…
Reference in New Issue