-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from StefanKunde/dev
Implemented support for shaped maps.
- Loading branch information
Showing
5 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package listener; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
import gui.MainFrame; | ||
|
||
public class ElderChBoxListener implements ActionListener { | ||
|
||
private MainFrame frame; | ||
|
||
public ElderChBoxListener(MainFrame frame) { | ||
this.frame = frame; | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if(frame.isLoadedElderMaps()) { | ||
frame.getChckbxShapedMap().setEnabled(true); | ||
frame.setLoadedShapedMaps(false); | ||
frame.setLoadedElderMaps(false); | ||
} else { | ||
frame.getChckbxShapedMap().setEnabled(false); | ||
frame.setLoadedElderMaps(true); | ||
frame.loadMapsFromJson(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package listener; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import com.stefank.Main; | ||
|
||
import gui.MainFrame; | ||
|
||
public class ShapedChBoxListener implements ActionListener { | ||
|
||
private MainFrame frame; | ||
|
||
public ShapedChBoxListener(MainFrame frame) { | ||
this.frame = frame; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if(frame.isLoadedShapedMaps()) { | ||
frame.getChckbxElderMap().setEnabled(true); | ||
frame.setLoadedElderMaps(false); | ||
frame.setLoadedShapedMaps(false); | ||
} else { | ||
frame.getChckbxElderMap().setEnabled(false); | ||
frame.setLoadedShapedMaps(true); | ||
loadMapsFromJson("shapedMaps.json"); | ||
} | ||
} | ||
|
||
private void loadMapsFromJson(String fileName) { | ||
String[] allMaps; | ||
List<String> allMapsAsList = new ArrayList<String>(); | ||
String text = new Scanner(Main.class.getResourceAsStream(fileName)).useDelimiter("\\A").next(); | ||
byte[] bytes; | ||
String mapsAsJsonString = ""; | ||
try { | ||
bytes = text.getBytes("UTF-8"); | ||
mapsAsJsonString = new String(bytes, "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
JSONObject json = new JSONObject(mapsAsJsonString); | ||
JSONArray maps = json.getJSONArray("maps"); | ||
// convert json array into arraylist | ||
for(int i = 0; i < maps.length(); i++) { | ||
|
||
allMapsAsList.add(maps.get(i).toString()); | ||
} | ||
Collections.sort(allMapsAsList, String.CASE_INSENSITIVE_ORDER); | ||
frame.getCmb_maps_bulks().removeAllItems(); | ||
|
||
for(int i = 0; i < allMapsAsList.size(); i++) { | ||
frame.getCmb_maps_bulks().addItem( allMapsAsList.get(i) ); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"maps": [ "Shaped Flooded Mine", "Shaped Channel", "Shaped Atoll", "Shaped Ramparts", | ||
"Shaped Dungeon", "Shaped Pen", "Shaped Arid Lake", "Shaped Iceberg", "Shaped Thicket", "Shaped Armoury", | ||
"Shaped Graveyard", "Shaped Desert", "Shaped Cage", "Shaped Excavation", "Shaped Penisula", "Shaped Grotto", "Shaped Bone Crypt", "Shaped Shipyard", "Shaped Cursed Crypt", "Shaped Fungal Hallow", | ||
"Shaped Lookout", "Shaped Beach", "Shaped Marshes", "Shaped Strand", "Shaped Lighthouse", "Shaped Spider Lair", "Shaped Barrows", "Shaped Courtyard", "Shaped Glacier", "Shaped Crater", | ||
"Shaped Alleyways", "Shaped Port", "Shaped City Square", "Shaped Maze", "Shaped Mausoleum", "Shaped Jungle Valley", "Shaped Underground Sea", "Shaped Residence", "Shaped Gardens", "Shaped Vaal Pyramid", | ||
"Shaped Volcano", "Shaped Canyon", "Shaped Sulpur Vents", "Shaped Haunted Mansion", "Shaped Fields", "Shaped Phantasmagoria", "Shaped Academy", "Shaped Wharf", "Shaped Ashen Wood", "Shaped Temple", "Shaped Precinct", | ||
"Shaped Cells", "Shaped Arcade", "Shaped Conservatory", "Shaped Toxic Sewer", "Shaped Lava Chamber", "Shaped Dunes", "Shaped Underground River", "Shaped Bazaar", "Shaped Geode", "Shaped Primorial Pool", "Shaped Ghetto", | ||
"Shaped Arachnid Nest", "Shaped Laboratory", "Shaped Infested Valley", "Shaped Overgrown Ruin", "Shaped Mud Geyser", "Shaped Shore", "Shaped Mineral Pools", "Shaped Sepulchre", "Shaped Wasteland", "Shaped Orchard", "Shaped Promenade", | ||
"Shaped Relic Chambers", "Shaped Ancient City", "Shaped Cemetery", "Shaped Tropical Island", "Shaped Moon Temple", "Shaped Waste Pool", "Shaped Vault", "Shaped Arena", "Shaped Museum", "Shaped Scriptorium", "Shaped Waterways", | ||
"Shaped Leyline", "Shaped Coral Ruins", "Shaped Plateau", "Shaped Estuary", "Shaped Belfry", "Shaped Pier", "Shaped Spider Forest", "Shaped Coves", "Shaped Pit", "Shaped Plaza"] | ||
} |