Skip to content

Commit

Permalink
Now able to load custom triggers into the map.
Browse files Browse the repository at this point in the history
Still needs fixing.
  • Loading branch information
tommai78101 committed Jun 26, 2015
1 parent 0174e9a commit 2254092
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cache.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\area\testC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\res\script
C:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\area\testC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\DesktopC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\res\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalkingC:\Users\tom_m_000\Documents\Workspace\PokemonWalkingC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\scriptC:\Users\tom_m_000\Documents\Workspace\PokemonWalking\mod\script
Binary file modified mod/area/aas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions mod/script/aas.script

This file was deleted.

23 changes: 23 additions & 0 deletions mod/script/test.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$0
@Eraser
%


$0
@Eraser

%


$1
@NewTrigger
#Hello

?Hi

+Test.
?Bye.
-Gone.
%


3 changes: 2 additions & 1 deletion src/level/OverWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public OverWorld(Player player, Game game) {
this.worldID = WorldConstants.OVERWORLD;

if (!this.areas.isEmpty())
areas.clear();
this.areas.clear();
WorldConstants.getAllNewScripts();
this.areas = WorldConstants.getAllNewAreas();

// Overworld properties
Expand Down
37 changes: 31 additions & 6 deletions src/level/WorldConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ private WorldConstants() {
public static ArrayList<Map.Entry<ItemText, Item>> items = Item.loadItems("item/items.txt");

// Areas
public static List<Area> areas = new ArrayList<Area>();
public static List<Area> moddedAreas = new ArrayList<Area>();
public static List<Area> areas = new ArrayList<Area>(0);
public static List<Area> moddedAreas = new ArrayList<Area>(0);

// Modded maps enabled?
public static Boolean isModsEnabled = null;

// Movement
// TODO (11/24/2014): Make map more flexible by allowing scripting files of different filenames to be loaded. Not sure where it was being loaded.
public static ArrayList<Script> scripts = Script.getAllScripts();
public static ArrayList<Script> scripts = new ArrayList<Script>(0);
public static ArrayList<Script> moddedScripts = new ArrayList<Script>(0);
// public static ArrayList<Script> gameScripts = Script.loadScript("script/aas.script"); // TODO (6/19/2015): Check to see why there's a need to load "aas.script".

//Custom scripts
//This array list is made for a script + area file name. They both go together.
public static ArrayList<Map.Entry<Script, String>> customScripts = new ArrayList<Map.Entry<Script, String>>();
//public static ArrayList<Map.Entry<Script, String>> customScripts = new ArrayList<Map.Entry<Script, String>>();

// All bitmaps
public static ArrayList<BaseBitmap> bitmaps = new ArrayList<BaseBitmap>();
Expand Down Expand Up @@ -120,7 +121,7 @@ public static List<Area> getAllNewAreas() {
WorldConstants.isModsEnabled = Boolean.TRUE;
}
}
if (WorldConstants.isModsEnabled == Boolean.FALSE) {
if (WorldConstants.isModsEnabled == Boolean.FALSE || WorldConstants.isModsEnabled == null) {
if (WorldConstants.areas.isEmpty()) {
WorldConstants.areas.add(new Area(Art.testArea, TEST_WORLD_1));
WorldConstants.areas.add(new Area(Art.testArea2, TEST_WORLD_2));
Expand All @@ -134,14 +135,38 @@ public static List<Area> getAllNewAreas() {
// result.add(new Area(Art.testArea_debug, Debug));
return WorldConstants.areas;
}
else { // Including NULL value.
else {
for (int i = 0; i < Mod.moddedAreas.size(); i++) {
Map.Entry<BaseBitmap, Integer> entry = Mod.moddedAreas.get(i);
WorldConstants.moddedAreas.add(new Area(entry.getKey(), entry.getValue()));
}
return WorldConstants.moddedAreas;
}
}

/**
* Returns all available scripts defined.
*
* @return A List<Script> object containing all available scripts in specified order defined.
* */
public static List<Script> getAllNewScripts(){
if (WorldConstants.isModsEnabled == null) {
if (Mod.moddedAreas.isEmpty()) {
WorldConstants.isModsEnabled = Boolean.FALSE;
}
else {
WorldConstants.isModsEnabled = Boolean.TRUE;
}
}
if (WorldConstants.isModsEnabled.booleanValue()){
WorldConstants.moddedScripts = Script.loadModdedScripts();
return WorldConstants.moddedScripts;
}
else {
WorldConstants.scripts = Script.loadDefaultScripts();
return WorldConstants.scripts;
}
}

/**
* Goes with the static method, "getAllNewAreas()".
Expand Down
3 changes: 2 additions & 1 deletion src/main/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ public void load() {
// TODO: Load data.
this.screen.reload();
Mod.loadModdedResources();
WorldConstants.isModsEnabled = null;
if (WorldConstants.isModsEnabled == null)
WorldConstants.isModsEnabled = Boolean.FALSE;
player.reload();
this.overworld = new OverWorld(player, this);
this.state = State.GAME;
Expand Down
33 changes: 23 additions & 10 deletions src/resources/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public class Mod {
private static final String[] names = new String[] { "area", "script" };
public static List<Map.Entry<BaseBitmap, Integer>> moddedAreas = new ArrayList<Map.Entry<BaseBitmap, Integer>>();
// public static List<Map.Entry<Script, Integer>> moddedScripts = new ArrayList<Map.Entry<Script, Integer>>();
private static boolean hasLoaded = false;

private static Comparator<File> ALPHABETICAL_ORDER = new Comparator<File>() {
Expand All @@ -47,21 +48,33 @@ public static void loadModdedResources() {
if (Mod.hasLoaded)
return;
Mod.initialization();
int id = 1;
File directory = new File("mod");
if (directory.exists()) {
List<File> list = Mod.getContents(directory);
List<File> list = Mod.getMapContents(directory);
Collections.sort(list, ALPHABETICAL_ORDER);
int id = 1;
for (File f : list) {
moddedAreas.add(new AbstractMap.SimpleEntry<BaseBitmap, Integer>(BaseScreen.load(f), id + 1000));
Mod.moddedAreas.add(new AbstractMap.SimpleEntry<BaseBitmap, Integer>(BaseScreen.load(f), id + 1000));
id++;
}
// ArrayList<Script> moddedScripts = Script.loadModdedScripts();
// id = 1;
// for (Script s : moddedScripts){
// Mod.moddedScripts.add(new AbstractMap.SimpleEntry<Script, Integer>(s, id++));
// }
}
else
throw new RuntimeException("Something is wrong with detecting the mod folder.");
Mod.hasLoaded = true;
}

/**
* <p>Initializes the "mod" folder directory if the game doesn't see it. Even if the game sees
* the folder, if the contents of the folder and its sub-folders are missing, it will recreate the basic necessary
* contents. This is deliberate and intentionally designed, unless re-developed.</p>
*
* @return Nothing.
* */
private static void initialization() {
File directory = new File("mod");
if (!directory.exists())
Expand Down Expand Up @@ -226,21 +239,21 @@ private static void initialization() {
}
}

private static List<File> getContents(File file) {
private static List<File> getMapContents(File file) {
List<File> results = new ArrayList<File>();
if (file.exists()) {
if (file != null && file.exists()) {
if (file.isDirectory()) {
File[] list = file.listFiles();
for (int i = 0; i < list.length; i++) {
results.addAll(getContents(list[i]));
results.addAll(Mod.getMapContents(list[i]));
}
}
else {
String filename = file.getPath();
int dotCount = filename.lastIndexOf('.');
int pathDotCount = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
String filepath = file.getPath();
int dotCount = filepath.lastIndexOf('.');
int pathDotCount = Math.max(filepath.lastIndexOf('/'), filepath.lastIndexOf('\\'));
if (dotCount > pathDotCount) {
if (filename.substring(dotCount + 1).toLowerCase().equals("png"))
if (filepath.substring(dotCount + 1).toLowerCase().equals("png"))
results.add(file);
}
}
Expand Down
24 changes: 22 additions & 2 deletions src/saving/GameSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class GameSave {
public AreaInfo areaInfo;

private GameSave() {
//TODO (6/25/2015): Needs a way to load save data for modded map.
headerInfo = new HeaderInfo();
playerInfo = new PlayerInfo();
areaInfo = new AreaInfo();
Expand Down Expand Up @@ -309,8 +310,27 @@ public static void save(Game game, String filename) {
}

public static void load(Game game, String filename) {
File load = new File(filename);
if (load.isFile()) {
File load = null;
if (WorldConstants.isModsEnabled.booleanValue()){
File modDirectory = new File("mod");
if (modDirectory.exists() && modDirectory.isDirectory()){
File[] files = modDirectory.listFiles();
NESTED_LOOP: for (File f : files){
if (f.getName().equals("area")){
File[] saves = f.listFiles();
for (File saveFile : saves){
if (saveFile.getName().equals(filename)){
load = saveFile;
break NESTED_LOOP;
}
}
}
}
}
}
else
load = new File(filename);
if (load != null && load.isFile()) {
GameSave data = new GameSave();
RandomAccessFile raf = null;
try {
Expand Down
20 changes: 10 additions & 10 deletions src/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,12 @@ private static void append(Movement moves, char[] list) {
}

/**
* Load all default and modded scripts.
* Load all default scripts.
* */
public static ArrayList<Script> getAllScripts() {
ArrayList<Script> scripts = Script.loadScript("script/scripts.txt", false);
ArrayList<Script> moddedScripts = Script.loadModdedScripts();
scripts.addAll(moddedScripts);
return scripts;
}

public static ArrayList<Script> loadDefaultScripts(){
return Script.loadScript("script/scripts.txt", false);
}

/**
* Load all modded scripts.
* */
Expand All @@ -346,7 +343,10 @@ public static ArrayList<Script> loadModdedScripts() {
for (int j = 0; j<scripts.length;j++){
String filePath = directory.getPath() + File.separator + scripts[j];
if (filePath.endsWith(".script")){
results = Script.loadScript(filePath, true);
if (results == null)
results = Script.loadScript(filePath, true);
else
results.addAll(Script.loadScript(filePath, true));
}
}
break LOOP;
Expand All @@ -355,4 +355,4 @@ public static ArrayList<Script> loadModdedScripts() {
}
return results;
}
}
}
5 changes: 2 additions & 3 deletions src/script/TriggerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public TriggerData loadTriggerData(int pixel) {
this.y = (pixel >> 16) & 0xFF;
if (this.finished)
this.finished = false;
if (WorldConstants.scripts.isEmpty())
System.out.println("Scripts are empty");
for (Script s : WorldConstants.scripts) {
ArrayList<Script> scriptList = (WorldConstants.isModsEnabled.booleanValue() ? WorldConstants.moddedScripts : WorldConstants.scripts);
for (Script s : scriptList) {
if (s.triggerID == (pixel & 0xFFFF)) {
this.script = s;
if (s.repeat)
Expand Down
7 changes: 6 additions & 1 deletion src/script_editor/ScriptChanger.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class ScriptChanger extends JPanel implements ActionListener, DocumentLis

private final ScriptEditor editor;

//TODO (6/25/2015): ID Field needs to default to a number > 0. New triggers currently does not auto-set itself.

private JTextField nameField, idField;
private JButton upButton, downButton, leftButton, rightButton;
private JButton questionDialogue, affirmativeDialogue, negativeDialogue, speechDialogue;
Expand Down Expand Up @@ -251,7 +253,7 @@ private JPanel constructDialogues() {
panel.add(speechDialogue);
questionDialogue = new JButton("?");
questionDialogue.setMargin(inset);
questionDialogue.setToolTipText("<html><b>Question Dialogue:</b><br/> A question dialogue asking for the player's response to YES or NO. <br/><br/><b>Usage:</b><br/>?[One-line-only Question] <br/><br/><b>Example:</b><br/>?Do you want to trade your Bulbasaur for my Pikachu?</html>");
questionDialogue.setToolTipText("<html><b>Question Dialogue:</b><br/> A question dialogue asking for the player's response to YES or NO.<br/><br/><b>WARNING:</b><br/>A single question must be followed by an Affirmative and a Negative Dialogue.<br/><br/><b>Usage:</b><br/>?[One-line-only Question] <br/><br/><b>Example:</b><br/>?Do you want to trade your Bulbasaur for my Pikachu?<br/>+Great! Let's trade!<br/>-Aw... I thought you had one.</html>");
questionDialogue.setActionCommand("?");
questionDialogue.addActionListener(dialogueActions);
panel.add(questionDialogue);
Expand Down Expand Up @@ -323,6 +325,7 @@ public void clear() {
scriptArea.setText("");
}

@Override
public void disable() {
this.nameField.setEnabled(false);
this.idField.setEnabled(false);
Expand All @@ -341,6 +344,7 @@ public void disable() {
this.isEnabled = false;
}

@Override
public void enable() {
this.nameField.setEnabled(true);
this.idField.setEnabled(true);
Expand All @@ -359,6 +363,7 @@ public void enable() {
this.isEnabled = true;
}

@Override
public boolean isEnabled() {
return this.isEnabled;
}
Expand Down
2 changes: 2 additions & 0 deletions src/script_editor/ScriptToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import editor.LevelEditor;
import editor.Trigger;

//TODO (6/25/2015): Save the already-opened file without needing to open up a JFileChooser.

public class ScriptToolbar extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private final ScriptEditor editor;
Expand Down

0 comments on commit 2254092

Please sign in to comment.