mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-07-04 09:29:28 +00:00
Added script location management features
This commit is contained in:
parent
4444380178
commit
53ba7ac8d4
@ -1,20 +1,25 @@
|
|||||||
package org.badvision.outlaweditor.data;
|
package org.badvision.outlaweditor.data;
|
||||||
|
|
||||||
import org.badvision.outlaweditor.Platform;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javafx.scene.image.WritableImage;
|
import javafx.scene.image.WritableImage;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.xml.bind.JAXBElement;
|
import javax.xml.bind.JAXBElement;
|
||||||
import org.badvision.outlaweditor.Application;
|
import org.badvision.outlaweditor.Application;
|
||||||
import org.badvision.outlaweditor.ui.UIAction;
|
import org.badvision.outlaweditor.Platform;
|
||||||
import org.badvision.outlaweditor.data.xml.Map;
|
import org.badvision.outlaweditor.data.xml.Map;
|
||||||
import org.badvision.outlaweditor.data.xml.Map.Chunk;
|
import org.badvision.outlaweditor.data.xml.Map.Chunk;
|
||||||
import org.badvision.outlaweditor.data.xml.ObjectFactory;
|
import org.badvision.outlaweditor.data.xml.ObjectFactory;
|
||||||
|
import org.badvision.outlaweditor.data.xml.Script;
|
||||||
|
import org.badvision.outlaweditor.data.xml.Script.LocationTrigger;
|
||||||
import org.badvision.outlaweditor.data.xml.Tile;
|
import org.badvision.outlaweditor.data.xml.Tile;
|
||||||
|
import org.badvision.outlaweditor.ui.UIAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -35,6 +40,57 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
|||||||
loadFromMap(m);
|
loadFromMap(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final double SATURATION = 0.5;
|
||||||
|
public static final double VALUE = 1.0;
|
||||||
|
public static double HUE = 0;
|
||||||
|
private java.util.Map<Integer, List<Script>> locationScripts = new HashMap<>();
|
||||||
|
private java.util.Map<Script, Color> scriptColors = new HashMap<>();
|
||||||
|
|
||||||
|
public Color getScriptColor(Script s) {
|
||||||
|
return scriptColors.get(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Script> getLocationScripts(int x, int y) {
|
||||||
|
List<Script> list = locationScripts.get(getMortonNumber(x, y));
|
||||||
|
if (list != null) {
|
||||||
|
return list;
|
||||||
|
} else {
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putLocationScript(int x, int y, Script s) {
|
||||||
|
LocationTrigger trigger = new Script.LocationTrigger();
|
||||||
|
trigger.setX(x);
|
||||||
|
trigger.setY(y);
|
||||||
|
s.getLocationTrigger().add(trigger);
|
||||||
|
registerLocationScript(x, y, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerLocationScript(int x, int y, Script s) {
|
||||||
|
if (!scriptColors.containsKey(s)) {
|
||||||
|
scriptColors.put(s, Color.hsb(HUE, SATURATION, VALUE));
|
||||||
|
HUE = (HUE + 20) % 360;
|
||||||
|
}
|
||||||
|
int loc = getMortonNumber(x, y);
|
||||||
|
List<Script> list = locationScripts.get(loc);
|
||||||
|
if (list == null) {
|
||||||
|
list = new ArrayList<>();
|
||||||
|
locationScripts.put(loc, list);
|
||||||
|
}
|
||||||
|
list.add(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMortonNumber(int x, int y) {
|
||||||
|
int morton = 0;
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
int mask = 1 << (i);
|
||||||
|
morton += (x & mask) << (i + 1);
|
||||||
|
morton += (y & mask) << i;
|
||||||
|
}
|
||||||
|
return morton;
|
||||||
|
}
|
||||||
|
|
||||||
public Tile get(int x, int y) {
|
public Tile get(int x, int y) {
|
||||||
if (size() <= y || get(y) == null) {
|
if (size() <= y || get(y) == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -52,7 +108,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
|||||||
add(null);
|
add(null);
|
||||||
}
|
}
|
||||||
if (get(y) == null) {
|
if (get(y) == null) {
|
||||||
set(y, new ArrayList<Tile>());
|
set(y, new ArrayList<>());
|
||||||
}
|
}
|
||||||
List<Tile> row = get(y);
|
List<Tile> row = get(y);
|
||||||
for (int i = row.size(); i <= x; i++) {
|
for (int i = row.size(); i <= x; i++) {
|
||||||
@ -93,7 +149,12 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
|||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
Set<Tile> unknownTiles = new HashSet<>();
|
Set<Tile> unknownTiles = new HashSet<>();
|
||||||
for (Chunk c : m.getChunk()) {
|
m.getScripts().getScript().forEach(
|
||||||
|
s -> s.getLocationTrigger().forEach(
|
||||||
|
l -> registerLocationScript(l.getX(), l.getY(), s)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
m.getChunk().forEach( c-> {
|
||||||
int y = c.getY();
|
int y = c.getY();
|
||||||
for (JAXBElement<List<String>> row : c.getRow()) {
|
for (JAXBElement<List<String>> row : c.getRow()) {
|
||||||
int x = c.getX();
|
int x = c.getX();
|
||||||
@ -114,7 +175,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
|
|||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
if (!unknownTiles.isEmpty()) {
|
if (!unknownTiles.isEmpty()) {
|
||||||
int numMissing = unknownTiles.size();
|
int numMissing = unknownTiles.size();
|
||||||
JOptionPane.showMessageDialog(null, (numMissing > 1
|
JOptionPane.showMessageDialog(null, (numMissing > 1
|
||||||
|
Loading…
Reference in New Issue
Block a user