mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
wavefunction collapse first integration
This commit is contained in:
@@ -107,7 +107,13 @@ public class Main {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
for(int i=0;i<args.length;i++)
|
||||
{
|
||||
if(args[i].equals("testMap"))
|
||||
{
|
||||
Forge.createNewAdventureMap=true;
|
||||
}
|
||||
}
|
||||
new Lwjgl3Application(start, config);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class BiomeEdit extends JComponent {
|
||||
public TextListEdit pointsOfInterest =new TextListEdit();
|
||||
|
||||
public TerrainsEditor terrain =new TerrainsEditor();
|
||||
|
||||
public StructureEditor structures =new StructureEditor();
|
||||
private boolean updating=false;
|
||||
|
||||
public BiomeEdit()
|
||||
@@ -46,11 +46,12 @@ public class BiomeEdit extends JComponent {
|
||||
center.add(new JLabel("enemies:")); center.add(enemies);
|
||||
center.add(new JLabel("pointsOfInterest:")); center.add(pointsOfInterest);
|
||||
center.add(new JLabel("color:")); center.add(color);
|
||||
center.add(new JLabel("terrain:")); center.add(terrain);
|
||||
center.add(new JLabel("terrain/structures:"));
|
||||
BorderLayout layout=new BorderLayout();
|
||||
setLayout(layout);
|
||||
add(center,BorderLayout.PAGE_START);
|
||||
add(center,BorderLayout.NORTH);
|
||||
add(terrain,BorderLayout.CENTER);
|
||||
add(structures,BorderLayout.SOUTH);
|
||||
|
||||
name.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
|
||||
tilesetName.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeEdit.this.updateTerrain()));
|
||||
@@ -81,6 +82,7 @@ public class BiomeEdit extends JComponent {
|
||||
currentData.tilesetAtlas = tilesetAtlas.edit.getText();
|
||||
currentData.tilesetName = tilesetName.getName();
|
||||
currentData.terrain = terrain.getBiomeTerrainData();
|
||||
currentData.structures = structures.getBiomeStructureData();
|
||||
currentData.width = (Float) width.getValue();
|
||||
currentData.height = (Float) height.getValue();
|
||||
currentData.color = color.getText();
|
||||
@@ -109,7 +111,8 @@ public class BiomeEdit extends JComponent {
|
||||
name.setText(currentData.name);
|
||||
tilesetAtlas.edit.setText( currentData.tilesetAtlas);
|
||||
tilesetName.setText(currentData.tilesetName);
|
||||
terrain.setTerrains(currentData.terrain);
|
||||
terrain.setTerrains(currentData);
|
||||
structures.setStructures(currentData);
|
||||
width.setValue(currentData.width);
|
||||
height.setValue(currentData.height);
|
||||
color.setText(currentData.color);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package forge.adventure.editor;
|
||||
|
||||
import forge.adventure.data.BiomeData;
|
||||
import forge.adventure.data.BiomeStructureData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
|
||||
public class BiomeStructureEdit extends JComponent {
|
||||
SwingAtlasPreview preview=new SwingAtlasPreview(128);
|
||||
private boolean updating=false;
|
||||
BiomeStructureData currentData;
|
||||
BiomeData currentBiomeData;
|
||||
public JTextField structureAtlasPath=new JTextField();
|
||||
public FloatSpinner x= new FloatSpinner();
|
||||
public FloatSpinner y= new FloatSpinner();
|
||||
public FloatSpinner size= new FloatSpinner();
|
||||
public JCheckBox randomPosition=new JCheckBox();
|
||||
public JCheckBox collision=new JCheckBox();
|
||||
|
||||
public BiomeStructureEdit()
|
||||
{
|
||||
JComponent center=new JComponent() { };
|
||||
center.setLayout(new GridLayout(6,2));
|
||||
|
||||
center.add(new JLabel("structureAtlasPath:")); center.add(structureAtlasPath);
|
||||
center.add(new JLabel("x:")); center.add(x);
|
||||
center.add(new JLabel("y:")); center.add(y);
|
||||
center.add(new JLabel("size:")); center.add(size);
|
||||
center.add(new JLabel("randomPosition:")); center.add(randomPosition);
|
||||
center.add(new JLabel("collision:")); center.add(collision);
|
||||
BorderLayout layout=new BorderLayout();
|
||||
setLayout(layout);
|
||||
add(preview,BorderLayout.LINE_START);
|
||||
add(center,BorderLayout.CENTER);
|
||||
|
||||
structureAtlasPath.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeStructureEdit.this.updateStructure()));
|
||||
|
||||
|
||||
x.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
|
||||
y.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
|
||||
size.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
|
||||
randomPosition.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
|
||||
collision.addChangeListener(e -> BiomeStructureEdit.this.updateStructure());
|
||||
refresh();
|
||||
}
|
||||
private void refresh() {
|
||||
setEnabled(currentData!=null);
|
||||
if(currentData==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
updating=true;
|
||||
structureAtlasPath.setText(currentData.structureAtlasPath);
|
||||
x.setValue(currentData.x);
|
||||
y.setValue(currentData.y);
|
||||
size.setValue(currentData.size);
|
||||
randomPosition.setSelected(currentData.randomPosition);
|
||||
collision.setSelected(currentData.collision);
|
||||
preview.setSpritePath(currentBiomeData.tilesetAtlas,currentData.structureAtlasPath);
|
||||
updating=false;
|
||||
}
|
||||
public void updateStructure()
|
||||
{
|
||||
|
||||
if(currentData==null||updating)
|
||||
return;
|
||||
currentData.structureAtlasPath=structureAtlasPath.getText();
|
||||
|
||||
currentData.x= x.floatValue();
|
||||
currentData.y= y.floatValue();
|
||||
currentData.size= size.floatValue();
|
||||
currentData.randomPosition=randomPosition.isSelected();
|
||||
currentData.collision=collision.isSelected();
|
||||
preview.setSpritePath(currentBiomeData.tilesetAtlas,currentData.structureAtlasPath);
|
||||
emitChanged();
|
||||
}
|
||||
public void setCurrentStructure(BiomeStructureData biomeTerrainData, BiomeData data) {
|
||||
currentData =biomeTerrainData;
|
||||
currentBiomeData=data;
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void addChangeListener(ChangeListener listener) {
|
||||
listenerList.add(ChangeListener.class, listener);
|
||||
}
|
||||
protected void emitChanged() {
|
||||
ChangeListener[] listeners = listenerList.getListeners(ChangeListener.class);
|
||||
if (listeners != null && listeners.length > 0) {
|
||||
ChangeEvent evt = new ChangeEvent(this);
|
||||
for (ChangeListener listener : listeners) {
|
||||
listener.stateChanged(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,88 @@
|
||||
package forge.adventure.editor;
|
||||
|
||||
import forge.adventure.data.BiomeData;
|
||||
import forge.adventure.data.BiomeTerrainData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
|
||||
public class BiomeTerrainEdit extends JComponent {
|
||||
public void setCurrentTerrain(BiomeTerrainData biomeTerrainData) {
|
||||
}
|
||||
public void addChangeListener(ChangeListener listener) {
|
||||
SwingAtlasPreview preview=new SwingAtlasPreview(128);
|
||||
private boolean updating=false;
|
||||
BiomeTerrainData currentData;
|
||||
BiomeData currentBiomeData;
|
||||
public JTextField spriteName=new JTextField();
|
||||
public JSpinner min= new JSpinner(new SpinnerNumberModel(0.0f, 0.f, 1f, 0.1f));
|
||||
public JSpinner max= new JSpinner(new SpinnerNumberModel(0.0f, 0.f, 1f, 0.1f));
|
||||
public JSpinner resolution= new JSpinner(new SpinnerNumberModel(0.0f, 0.f, 1f, 0.1f));
|
||||
|
||||
public BiomeTerrainEdit()
|
||||
{
|
||||
JComponent center=new JComponent() { };
|
||||
center.setLayout(new GridLayout(4,2));
|
||||
|
||||
center.add(new JLabel("spriteName:")); center.add(spriteName);
|
||||
center.add(new JLabel("min:")); center.add(min);
|
||||
center.add(new JLabel("max:")); center.add(max);
|
||||
center.add(new JLabel("resolution:")); center.add(resolution);
|
||||
BorderLayout layout=new BorderLayout();
|
||||
setLayout(layout);
|
||||
add(preview,BorderLayout.LINE_START);
|
||||
add(center,BorderLayout.CENTER);
|
||||
|
||||
spriteName.getDocument().addDocumentListener(new DocumentChangeListener(() -> BiomeTerrainEdit.this.updateTerrain()));
|
||||
|
||||
min.addChangeListener(e -> BiomeTerrainEdit.this.updateTerrain());
|
||||
max.addChangeListener(e -> BiomeTerrainEdit.this.updateTerrain());
|
||||
resolution.addChangeListener(e -> BiomeTerrainEdit.this.updateTerrain());
|
||||
|
||||
|
||||
refresh();
|
||||
}
|
||||
private void refresh() {
|
||||
setEnabled(currentData!=null);
|
||||
if(currentData==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
updating=true;
|
||||
spriteName.setText(currentData.spriteName);
|
||||
min.setValue(currentData.min);
|
||||
max.setValue(currentData.max);
|
||||
resolution.setValue(currentData.resolution);
|
||||
preview.setSpritePath(currentBiomeData.tilesetAtlas,currentData.spriteName);
|
||||
updating=false;
|
||||
}
|
||||
public void updateTerrain()
|
||||
{
|
||||
|
||||
if(currentData==null||updating)
|
||||
return;
|
||||
currentData.spriteName=spriteName.getText();
|
||||
currentData.min= (float) min.getValue();
|
||||
currentData.max= (float) max.getValue();
|
||||
currentData.resolution= (float) resolution.getValue();
|
||||
preview.setSpritePath(currentBiomeData.tilesetAtlas,currentData.spriteName);
|
||||
emitChanged();
|
||||
}
|
||||
public void setCurrentTerrain(BiomeTerrainData biomeTerrainData, BiomeData data) {
|
||||
currentData =biomeTerrainData;
|
||||
currentBiomeData=data;
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void addChangeListener(ChangeListener listener) {
|
||||
listenerList.add(ChangeListener.class, listener);
|
||||
}
|
||||
protected void emitChanged() {
|
||||
ChangeListener[] listeners = listenerList.getListeners(ChangeListener.class);
|
||||
if (listeners != null && listeners.length > 0) {
|
||||
ChangeEvent evt = new ChangeEvent(this);
|
||||
for (ChangeListener listener : listeners) {
|
||||
listener.stateChanged(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ public class EditorMainWindow extends JFrame {
|
||||
BorderLayout layout=new BorderLayout();
|
||||
setLayout(layout);
|
||||
add(tabs);
|
||||
tabs.addTab("POI",new PointOfInterestEditor());
|
||||
tabs.addTab("World",new WorldEditor());
|
||||
tabs.addTab("POI",new PointOfInterestEditor());
|
||||
tabs.addTab("Items",new ItemsEditor());
|
||||
tabs.addTab("Enemies",new EnemyEditor());
|
||||
setVisible(true);
|
||||
|
||||
@@ -10,8 +10,6 @@ import java.awt.*;
|
||||
*/
|
||||
public class EnemyEdit extends JComponent {
|
||||
EnemyData currentData;
|
||||
|
||||
|
||||
JTextField nameField=new JTextField();
|
||||
JTextField colorField=new JTextField();
|
||||
JSpinner lifeFiled= new JSpinner(new SpinnerNumberModel(0, 0, 1000, 1));
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package forge.adventure.editor;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FloatSpinner extends JSpinner{
|
||||
|
||||
public FloatSpinner()
|
||||
{
|
||||
this( 0.f, 1f, 0.1f);
|
||||
}
|
||||
public FloatSpinner(float min,float max,float stepSize)
|
||||
{
|
||||
super(new SpinnerNumberModel(new Float(0.0f), new Float(min), new Float (max), new Float(stepSize)));
|
||||
}
|
||||
public float floatValue()
|
||||
{
|
||||
return ((Float)getValue()).floatValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package forge.adventure.editor;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class IntSpinner extends JSpinner {
|
||||
|
||||
public IntSpinner()
|
||||
{
|
||||
this( 0, 100, 1);
|
||||
}
|
||||
public IntSpinner(int min,int max,int stepSize)
|
||||
{
|
||||
super(new SpinnerNumberModel(new Integer(0), new Integer(min), new Integer (max), new Integer(stepSize)));
|
||||
}
|
||||
public int intValue()
|
||||
{
|
||||
return ((Integer)getValue()).intValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package forge.adventure.editor;
|
||||
|
||||
import forge.adventure.data.BiomeData;
|
||||
import forge.adventure.data.BiomeStructureData;
|
||||
import forge.adventure.data.BiomeTerrainData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* Editor class to edit configuration, maybe moved or removed
|
||||
*/
|
||||
public class StructureEditor extends JComponent{
|
||||
DefaultListModel<BiomeStructureData> model = new DefaultListModel<>();
|
||||
JList<BiomeStructureData> list = new JList<>(model);
|
||||
JToolBar toolBar = new JToolBar("toolbar");
|
||||
BiomeStructureEdit edit=new BiomeStructureEdit();
|
||||
|
||||
BiomeData currentData;
|
||||
|
||||
public class StructureDataRenderer extends DefaultListCellRenderer {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(
|
||||
JList list, Object value, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if(!(value instanceof BiomeTerrainData))
|
||||
return label;
|
||||
BiomeTerrainData structureData=(BiomeTerrainData) value;
|
||||
StringBuilder builder=new StringBuilder();
|
||||
builder.append("Structure");
|
||||
builder.append(" ");
|
||||
builder.append(structureData.spriteName);
|
||||
label.setText(builder.toString());
|
||||
return label;
|
||||
}
|
||||
}
|
||||
public void addButton(String name, ActionListener action)
|
||||
{
|
||||
JButton newButton=new JButton(name);
|
||||
newButton.addActionListener(action);
|
||||
toolBar.add(newButton);
|
||||
|
||||
}
|
||||
|
||||
public StructureEditor()
|
||||
{
|
||||
|
||||
list.setCellRenderer(new StructureDataRenderer());
|
||||
list.addListSelectionListener(e -> StructureEditor.this.updateEdit());
|
||||
addButton("add", e -> StructureEditor.this.addStructure());
|
||||
addButton("remove", e -> StructureEditor.this.remove());
|
||||
addButton("copy", e -> StructureEditor.this.copy());
|
||||
BorderLayout layout=new BorderLayout();
|
||||
setLayout(layout);
|
||||
add(list, BorderLayout.LINE_START);
|
||||
add(toolBar, BorderLayout.PAGE_START);
|
||||
add(edit,BorderLayout.CENTER);
|
||||
|
||||
|
||||
edit.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
emitChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
protected void emitChanged() {
|
||||
ChangeListener[] listeners = listenerList.getListeners(ChangeListener.class);
|
||||
if (listeners != null && listeners.length > 0) {
|
||||
ChangeEvent evt = new ChangeEvent(this);
|
||||
for (ChangeListener listener : listeners) {
|
||||
listener.stateChanged(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void copy() {
|
||||
|
||||
int selected=list.getSelectedIndex();
|
||||
if(selected<0)
|
||||
return;
|
||||
BiomeStructureData data=new BiomeStructureData(model.get(selected));
|
||||
model.add(model.size(),data);
|
||||
}
|
||||
|
||||
private void updateEdit() {
|
||||
|
||||
int selected=list.getSelectedIndex();
|
||||
if(selected<0)
|
||||
return;
|
||||
edit.setCurrentStructure(model.get(selected),currentData);
|
||||
}
|
||||
|
||||
void addStructure()
|
||||
{
|
||||
BiomeStructureData data=new BiomeStructureData();
|
||||
model.add(model.size(),data);
|
||||
}
|
||||
void remove()
|
||||
{
|
||||
int selected=list.getSelectedIndex();
|
||||
if(selected<0)
|
||||
return;
|
||||
model.remove(selected);
|
||||
}
|
||||
public void setStructures(BiomeData data) {
|
||||
|
||||
currentData=data;
|
||||
model.clear();
|
||||
if(data==null||data.structures==null)
|
||||
return;
|
||||
for (int i=0;i<data.structures.length;i++) {
|
||||
model.add(i,data.structures[i]);
|
||||
}
|
||||
list.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
public BiomeStructureData[] getBiomeStructureData() {
|
||||
|
||||
BiomeStructureData[] rewards= new BiomeStructureData[model.getSize()];
|
||||
for(int i=0;i<model.getSize();i++)
|
||||
{
|
||||
rewards[i]=model.get(i);
|
||||
}
|
||||
return rewards;
|
||||
}
|
||||
public void addChangeListener(ChangeListener listener) {
|
||||
listenerList.add(ChangeListener.class, listener);
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,15 @@ import static java.awt.Image.SCALE_FAST;
|
||||
*/
|
||||
public class SwingAtlas {
|
||||
|
||||
int imageSize=32;
|
||||
HashMap<String, ArrayList<ImageIcon>> images=new HashMap<>();
|
||||
public HashMap<String, ArrayList<ImageIcon>> getImages()
|
||||
{
|
||||
return images;
|
||||
}
|
||||
public SwingAtlas(FileHandle path)
|
||||
public SwingAtlas(FileHandle path,int imageSize)
|
||||
{
|
||||
this.imageSize=imageSize;
|
||||
if(!path.exists()||!path.toString().endsWith(".atlas"))
|
||||
return;
|
||||
TextureAtlas.TextureAtlasData data=new TextureAtlas.TextureAtlasData(path,path.parent(),false);
|
||||
@@ -37,17 +39,28 @@ public class SwingAtlas {
|
||||
images.put(name,new ArrayList<>());
|
||||
}
|
||||
ArrayList<ImageIcon> imageList=images.get(name);
|
||||
try {
|
||||
try
|
||||
{
|
||||
imageList.add(spriteToImage(region));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public SwingAtlas(FileHandle path)
|
||||
{
|
||||
this(path,32);
|
||||
}
|
||||
|
||||
private ImageIcon spriteToImage(TextureAtlas.TextureAtlasData.Region sprite) throws IOException {
|
||||
BufferedImage img = ImageIO.read(sprite.page.textureFile.file());
|
||||
return new ImageIcon(img.getSubimage(sprite.left,sprite.top, sprite.width, sprite.height).getScaledInstance(32,32,SCALE_FAST));
|
||||
if(sprite.width== sprite.height)
|
||||
return new ImageIcon(img.getSubimage(sprite.left,sprite.top, sprite.width, sprite.height).getScaledInstance(imageSize,imageSize,SCALE_FAST));
|
||||
if(sprite.width>sprite.height)
|
||||
return new ImageIcon(img.getSubimage(sprite.left,sprite.top, sprite.width, sprite.height).getScaledInstance(imageSize, (int) (imageSize*(sprite.height/(float)sprite.width)),SCALE_FAST));
|
||||
return new ImageIcon(img.getSubimage(sprite.left,sprite.top, sprite.width, sprite.height).getScaledInstance((int) (imageSize*(sprite.width/(float)sprite.height)),imageSize,SCALE_FAST));
|
||||
}
|
||||
|
||||
public ImageIcon get(String name) {
|
||||
|
||||
@@ -13,11 +13,12 @@ import java.util.Map;
|
||||
* Editor class to edit configuration, maybe moved or removed
|
||||
*/
|
||||
public class SwingAtlasPreview extends Box {
|
||||
int imageSize=32;
|
||||
private String sprite="";
|
||||
private String spriteName="";
|
||||
Timer timer;
|
||||
public SwingAtlasPreview() {
|
||||
super(BoxLayout.Y_AXIS);
|
||||
|
||||
timer = new Timer(200, new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -28,25 +29,51 @@ public class SwingAtlasPreview extends Box {
|
||||
}
|
||||
});
|
||||
}
|
||||
public SwingAtlasPreview(int size) {
|
||||
this();
|
||||
imageSize=size;
|
||||
}
|
||||
int counter=0;
|
||||
List<Pair<JLabel,ArrayList<ImageIcon>>> labels=new ArrayList<>();
|
||||
public void setSpritePath(String sprite) {
|
||||
|
||||
if(this.sprite==null||this.sprite.equals(sprite))
|
||||
setSpritePath(sprite,null);
|
||||
}
|
||||
public void setSpritePath(String sprite,String name) {
|
||||
|
||||
if(this.sprite==null||name==null||sprite==null||(this.sprite.equals(sprite)&&(spriteName==null&&spriteName.equals(name))))
|
||||
return;
|
||||
removeAll();
|
||||
counter=0;
|
||||
labels.clear();
|
||||
this.sprite=sprite;
|
||||
SwingAtlas atlas=new SwingAtlas(Config.instance().getFile(sprite));
|
||||
this.spriteName=name;
|
||||
SwingAtlas atlas=new SwingAtlas(Config.instance().getFile(sprite),imageSize);
|
||||
int maxCount=0;
|
||||
for(Map.Entry<String, ArrayList<ImageIcon>> element:atlas.getImages().entrySet())
|
||||
{
|
||||
JLabel image=new JLabel(element.getValue().get(0));
|
||||
add(new JLabel(element.getKey()));
|
||||
add(image);
|
||||
labels.add(Pair.of(image, element.getValue()));
|
||||
if(name==null||element.getKey().equals(name))
|
||||
{
|
||||
JLabel image=new JLabel(element.getValue().get(0));
|
||||
if(maxCount<element.getValue().size())
|
||||
maxCount=element.getValue().size();
|
||||
add(new JLabel(element.getKey()));
|
||||
add(image);
|
||||
labels.add(Pair.of(image, element.getValue()));
|
||||
}
|
||||
}
|
||||
timer.restart();
|
||||
if(maxCount<=1)
|
||||
{
|
||||
timer.stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.restart();
|
||||
}
|
||||
doLayout();
|
||||
revalidate();
|
||||
update(getGraphics());
|
||||
repaint();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package forge.adventure.editor;
|
||||
|
||||
import forge.adventure.data.BiomeData;
|
||||
import forge.adventure.data.BiomeTerrainData;
|
||||
import forge.adventure.data.RewardData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
@@ -18,7 +18,7 @@ public class TerrainsEditor extends JComponent{
|
||||
JToolBar toolBar = new JToolBar("toolbar");
|
||||
BiomeTerrainEdit edit=new BiomeTerrainEdit();
|
||||
|
||||
|
||||
BiomeData currentData;
|
||||
|
||||
public class TerrainDataRenderer extends DefaultListCellRenderer {
|
||||
@Override
|
||||
@@ -26,21 +26,13 @@ public class TerrainsEditor extends JComponent{
|
||||
JList list, Object value, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
if(!(value instanceof RewardData))
|
||||
if(!(value instanceof BiomeTerrainData))
|
||||
return label;
|
||||
RewardData reward=(RewardData) value;
|
||||
BiomeTerrainData terrainData=(BiomeTerrainData) value;
|
||||
StringBuilder builder=new StringBuilder();
|
||||
if(reward.type==null||reward.type.isEmpty())
|
||||
builder.append("Terrain");
|
||||
else
|
||||
builder.append(reward.type);
|
||||
builder.append("Terrain");
|
||||
builder.append(" ");
|
||||
builder.append(reward.count);
|
||||
if(reward.addMaxCount>0)
|
||||
{
|
||||
builder.append("-");
|
||||
builder.append(reward.count+reward.addMaxCount);
|
||||
}
|
||||
builder.append(terrainData.spriteName);
|
||||
label.setText(builder.toString());
|
||||
return label;
|
||||
}
|
||||
@@ -58,7 +50,7 @@ public class TerrainsEditor extends JComponent{
|
||||
|
||||
list.setCellRenderer(new TerrainDataRenderer());
|
||||
list.addListSelectionListener(e -> TerrainsEditor.this.updateEdit());
|
||||
addButton("add", e -> TerrainsEditor.this.addReward());
|
||||
addButton("add", e -> TerrainsEditor.this.addTerrain());
|
||||
addButton("remove", e -> TerrainsEditor.this.remove());
|
||||
addButton("copy", e -> TerrainsEditor.this.copy());
|
||||
BorderLayout layout=new BorderLayout();
|
||||
@@ -98,10 +90,10 @@ public class TerrainsEditor extends JComponent{
|
||||
int selected=list.getSelectedIndex();
|
||||
if(selected<0)
|
||||
return;
|
||||
edit.setCurrentTerrain(model.get(selected));
|
||||
edit.setCurrentTerrain(model.get(selected),currentData);
|
||||
}
|
||||
|
||||
void addReward()
|
||||
void addTerrain()
|
||||
{
|
||||
BiomeTerrainData data=new BiomeTerrainData();
|
||||
model.add(model.size(),data);
|
||||
@@ -113,14 +105,16 @@ public class TerrainsEditor extends JComponent{
|
||||
return;
|
||||
model.remove(selected);
|
||||
}
|
||||
public void setTerrains(BiomeTerrainData[] terrain) {
|
||||
public void setTerrains(BiomeData data) {
|
||||
|
||||
currentData=data;
|
||||
model.clear();
|
||||
if(terrain==null)
|
||||
if(data==null||data.terrain==null)
|
||||
return;
|
||||
for (int i=0;i<terrain.length;i++) {
|
||||
model.add(i,terrain[i]);
|
||||
for (int i=0;i<data.terrain.length;i++) {
|
||||
model.add(i,data.terrain[i]);
|
||||
}
|
||||
list.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
public BiomeTerrainData[] getBiomeTerrainData() {
|
||||
|
||||
@@ -10,7 +10,12 @@ import forge.adventure.util.Config;
|
||||
import forge.adventure.util.Paths;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class WorldEditor extends JComponent {
|
||||
@@ -63,8 +68,26 @@ public class WorldEditor extends JComponent {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void updateBiome() {
|
||||
|
||||
int selected=list.getSelectedIndex();
|
||||
if(selected<0)
|
||||
return;
|
||||
edit.setCurrentBiome(model.get(selected));
|
||||
}
|
||||
|
||||
public WorldEditor() {
|
||||
list.setCellRenderer(new BiomeDataRenderer());
|
||||
list.addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
WorldEditor.this.updateBiome();
|
||||
}
|
||||
});
|
||||
BorderLayout layout = new BorderLayout();
|
||||
setLayout(layout);
|
||||
add(tabs);
|
||||
@@ -103,9 +126,42 @@ public class WorldEditor extends JComponent {
|
||||
JButton newButton=new JButton("save");
|
||||
newButton.addActionListener(e -> WorldEditor.this.save());
|
||||
toolBar.add(newButton);
|
||||
|
||||
newButton=new JButton("load");
|
||||
newButton.addActionListener(e -> WorldEditor.this.load());
|
||||
toolBar.add(newButton);
|
||||
|
||||
toolBar.addSeparator();
|
||||
|
||||
newButton=new JButton("test map");
|
||||
newButton.addActionListener(e -> WorldEditor.this.test());
|
||||
toolBar.add(newButton);
|
||||
}
|
||||
|
||||
private void test() {
|
||||
|
||||
String javaHome = System.getProperty("java.home");
|
||||
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
String className = forge.adventure.Main.class.getName();
|
||||
|
||||
ArrayList<String> command = new ArrayList<>();
|
||||
command.add(javaBin);
|
||||
command.add("-cp");
|
||||
command.add(classpath);
|
||||
command.add(className);
|
||||
|
||||
command.add("testMap");
|
||||
|
||||
ProcessBuilder build= new ProcessBuilder(command);
|
||||
build .redirectInput(ProcessBuilder.Redirect.INHERIT)
|
||||
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
|
||||
.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
try {
|
||||
Process process= build.start();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void save()
|
||||
|
||||
@@ -55,6 +55,11 @@
|
||||
<artifactId>gdx-freetype</artifactId>
|
||||
<version>1.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.sjcasey21</groupId>
|
||||
<artifactId>wavefunctioncollapse</artifactId>
|
||||
<version>0.2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -123,6 +123,7 @@ public class Forge implements ApplicationListener {
|
||||
private static Cursor cursor0, cursor1, cursor2, cursorA0, cursorA1, cursorA2;
|
||||
public static boolean forcedEnglishonCJKMissing = false;
|
||||
public static boolean adventureLoaded = false;
|
||||
public static boolean createNewAdventureMap = false;
|
||||
private static Localizer localizer;
|
||||
|
||||
public static ApplicationListener getApp(Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0, boolean value, boolean androidOrientation, int totalRAM, boolean isTablet, int AndroidAPI, String AndroidRelease, String deviceName) {
|
||||
|
||||
@@ -30,6 +30,7 @@ public class BiomeData implements Serializable {
|
||||
public String[] spriteNames;
|
||||
public List<String> enemies;
|
||||
public List<String> pointsOfInterest;
|
||||
public BiomeStructureData[] structures;
|
||||
|
||||
private ArrayList<EnemyData> enemyList;
|
||||
private ArrayList<PointOfInterestData> pointOfInterestList;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package forge.adventure.data;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BiomeStructureData {
|
||||
public int N = 3;
|
||||
public float x;
|
||||
public float y;
|
||||
public float size;
|
||||
public boolean randomPosition;
|
||||
public boolean collision;
|
||||
|
||||
public String structureAtlasPath;
|
||||
public boolean periodicInput;
|
||||
public float height;
|
||||
public float width;
|
||||
public int ground;
|
||||
public int symmetry;
|
||||
public boolean periodicOutput;
|
||||
|
||||
public BiomeStructureData( )
|
||||
{
|
||||
|
||||
}
|
||||
public BiomeStructureData(BiomeStructureData biomeStructureData) {
|
||||
this.structureAtlasPath=biomeStructureData.structureAtlasPath;
|
||||
this.x=biomeStructureData.x;
|
||||
this.y=biomeStructureData.y;
|
||||
this.size=biomeStructureData.size;
|
||||
this.randomPosition=biomeStructureData.randomPosition;
|
||||
this.collision=biomeStructureData.collision;
|
||||
}
|
||||
|
||||
public BufferedImage sourceImage() {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,11 @@ public class NewGameScene extends UIScene {
|
||||
public void enter() {
|
||||
updateAvatar();
|
||||
Gdx.input.setInputProcessor(stage); //Start taking input from the ui
|
||||
|
||||
if(Forge.createNewAdventureMap)
|
||||
{
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,9 +7,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import forge.Forge;
|
||||
import forge.adventure.stage.GameHUD;
|
||||
import forge.adventure.stage.GameStage;
|
||||
import forge.adventure.stage.MapStage;
|
||||
import forge.adventure.util.Config;
|
||||
import forge.adventure.util.Controls;
|
||||
import forge.adventure.util.Current;
|
||||
import forge.adventure.world.WorldSave;
|
||||
import forge.screens.TransitionScreen;
|
||||
|
||||
@@ -104,6 +106,13 @@ public class StartScene extends UIScene {
|
||||
}
|
||||
|
||||
Gdx.input.setInputProcessor(stage); //Start taking input from the ui
|
||||
|
||||
if(Forge.createNewAdventureMap)
|
||||
{
|
||||
this.NewGame();
|
||||
Current.setDebug(true);
|
||||
GameStage.maximumScrollDistance=4f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,6 +36,8 @@ public abstract class GameStage extends Stage {
|
||||
private float touchY = -1;
|
||||
private final float timer = 0;
|
||||
private float animationTimeout = 0;
|
||||
public static float maximumScrollDistance=1.5f;
|
||||
public static float minimumScrollDistance=0.3f;
|
||||
|
||||
public void startPause(float i) {
|
||||
startPause(i, null);
|
||||
@@ -222,10 +224,10 @@ public abstract class GameStage extends Stage {
|
||||
if (isPaused())
|
||||
return true;
|
||||
camera.zoom += (amountY * 0.03);
|
||||
if (camera.zoom < 0.3f)
|
||||
camera.zoom = 0.3f;
|
||||
if (camera.zoom > 1.5f)
|
||||
camera.zoom = 1.5f;
|
||||
if (camera.zoom < minimumScrollDistance)
|
||||
camera.zoom = minimumScrollDistance;
|
||||
if (camera.zoom > maximumScrollDistance)
|
||||
camera.zoom = maximumScrollDistance;
|
||||
return super.scrolled(amountX, amountY);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,19 +176,7 @@ public class WorldStage extends GameStage implements SaveFileContent {
|
||||
public boolean isColliding(Rectangle boundingRect)
|
||||
{
|
||||
|
||||
World world = WorldSave.getCurrentSave().getWorld();
|
||||
int currentBiome = World.highestBiome(world.getBiome((int) boundingRect.getX() / world.getTileSize(), (int) boundingRect.getY() / world.getTileSize()));
|
||||
if(currentBiome==0)
|
||||
return true;
|
||||
currentBiome = World.highestBiome(world.getBiome((int) (boundingRect.getX()+boundingRect.getWidth()) / world.getTileSize(), (int) boundingRect.getY() / world.getTileSize()));
|
||||
if(currentBiome==0)
|
||||
return true;
|
||||
currentBiome = World.highestBiome(world.getBiome((int) (boundingRect.getX()+boundingRect.getWidth())/ world.getTileSize(), (int) (boundingRect.getY()+boundingRect.getHeight()) / world.getTileSize()));
|
||||
if(currentBiome==0)
|
||||
return true;
|
||||
currentBiome = World.highestBiome(world.getBiome((int) boundingRect.getX() / world.getTileSize(), (int) (boundingRect.getY()+boundingRect.getHeight()) / world.getTileSize()));
|
||||
|
||||
return (currentBiome==0);
|
||||
return WorldSave.getCurrentSave().getWorld().collidingTile(boundingRect);
|
||||
}
|
||||
|
||||
private void HandleMonsterSpawn(float delta) {
|
||||
|
||||
114
forge-gui-mobile/src/forge/adventure/world/BiomeStructure.java
Normal file
114
forge-gui-mobile/src/forge/adventure/world/BiomeStructure.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package forge.adventure.world;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.github.sjcasey21.wavefunctioncollapse.OverlappingModel;
|
||||
import forge.adventure.data.BiomeStructureData;
|
||||
import forge.adventure.util.Config;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BiomeStructure {
|
||||
|
||||
private BiomeStructureData data;
|
||||
long seed;
|
||||
private int biomeWidth;
|
||||
private int biomeHeight;
|
||||
private int dataMap[][];
|
||||
boolean init=false;
|
||||
private TextureAtlas structureAtlas;
|
||||
public BiomeStructure(BiomeStructureData data,long seed,int width,int height)
|
||||
{
|
||||
this.data=data;
|
||||
this.seed=seed;
|
||||
this.biomeWidth = width;
|
||||
this.biomeHeight = height;
|
||||
}
|
||||
public TextureAtlas atlas() {
|
||||
if(structureAtlas==null)
|
||||
{
|
||||
structureAtlas = Config.instance().getAtlas(data.structureAtlasPath);
|
||||
}
|
||||
return structureAtlas;
|
||||
}
|
||||
public int structureObjectCount() {
|
||||
int count=0;
|
||||
for(TextureAtlas.AtlasRegion region:atlas ().getRegions())
|
||||
{
|
||||
if(region.name.startsWith("structure"))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public int objectID(int x, int y) {
|
||||
|
||||
if(!init)
|
||||
{
|
||||
init=true;
|
||||
initialize();
|
||||
}
|
||||
if(x>biomeWidth*data.width)
|
||||
return -1;
|
||||
if(y>biomeHeight*data.height)
|
||||
return -1;
|
||||
if(x<biomeWidth*data.x)
|
||||
return -1;
|
||||
if(y<biomeHeight*data.y)
|
||||
return -1;
|
||||
return dataMap[x][y];
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
OverlappingModel model= new OverlappingModel(sourceImage(),data.N, (int) (data.width* biomeWidth), (int) (data.height*biomeHeight),data.periodicInput,data.periodicOutput,data.symmetry,data.ground);
|
||||
HashMap<Integer,Integer> colorIdMap=new HashMap<>();
|
||||
int counter=0;
|
||||
for(TextureAtlas.AtlasRegion region:atlas ().getRegions())
|
||||
{
|
||||
if(region.name.startsWith("structure"))
|
||||
{
|
||||
String[] split= region.name.split("_");
|
||||
if(split.length<2)
|
||||
continue;
|
||||
int rgb=Integer.parseInt(split[1],16);
|
||||
colorIdMap.put(rgb,counter);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
BufferedImage image=model.graphics();
|
||||
dataMap=new int[image.getWidth()][image.getHeight()];
|
||||
for(int x=0;x<image.getWidth();x++)
|
||||
{
|
||||
|
||||
for(int y=0;y<image.getHeight();y++)
|
||||
{
|
||||
int rgb=image.getRGB(x,y);
|
||||
if(!colorIdMap.containsKey(rgb))
|
||||
{
|
||||
dataMap[x][y]=-1;
|
||||
}
|
||||
else {
|
||||
dataMap[x][y]=colorIdMap.get(rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BufferedImage sourceImage() {
|
||||
TextureAtlas.AtlasRegion region=atlas().findRegion("Source");
|
||||
if(region==null)
|
||||
return null;
|
||||
try {
|
||||
return ImageIO.read(new File(Config.instance().getFilePath(data.structureAtlasPath))).getSubimage((int) region.offsetX, (int) region.offsetY,region.originalWidth,region.originalHeight);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import forge.adventure.data.BiomeData;
|
||||
import forge.adventure.data.BiomeStructureData;
|
||||
import forge.adventure.data.BiomeTerrainData;
|
||||
import forge.adventure.util.Config;
|
||||
import forge.gui.FThreads;
|
||||
@@ -19,7 +20,7 @@ import java.util.ArrayList;
|
||||
public class BiomeTexture implements Serializable {
|
||||
private final BiomeData data;
|
||||
private final int tileSize;
|
||||
public Pixmap emptyPixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
|
||||
public static Pixmap emptyPixmap = null;
|
||||
ArrayList<ArrayList<Pixmap>> images = new ArrayList<>();
|
||||
ArrayList<ArrayList<Pixmap>> smallImages = new ArrayList<>();
|
||||
ArrayList<IntMap<Pixmap>> edgeImages = new ArrayList<>();
|
||||
@@ -45,7 +46,6 @@ public class BiomeTexture implements Serializable {
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Pixmap completePicture = null;
|
||||
|
||||
if (images != null) {
|
||||
for (ArrayList<Pixmap> val : images) {
|
||||
@@ -79,22 +79,38 @@ public class BiomeTexture implements Serializable {
|
||||
edgeImages = new ArrayList<>();
|
||||
|
||||
ArrayList<TextureAtlas.AtlasRegion> regions =new ArrayList<>();
|
||||
ArrayList<TextureAtlas> source =new ArrayList<>();
|
||||
regions.add(Config.instance().getAtlas(data.tilesetAtlas).findRegion(data.tilesetName));
|
||||
source.add(Config.instance().getAtlas(data.tilesetAtlas));
|
||||
if(data.terrain!=null)
|
||||
{
|
||||
for(BiomeTerrainData terrain:data.terrain)
|
||||
{
|
||||
regions.add(Config.instance().getAtlas(data.tilesetAtlas).findRegion(terrain.spriteName));
|
||||
source.add(Config.instance().getAtlas(data.tilesetAtlas));
|
||||
}
|
||||
}
|
||||
if(data.structures!=null)
|
||||
{
|
||||
for(BiomeStructureData structureData:data.structures)
|
||||
{
|
||||
BiomeStructure structure=new BiomeStructure(structureData,0,0,0);
|
||||
for(TextureAtlas.AtlasRegion region:structure.atlas ().getRegions())
|
||||
{
|
||||
if(region.name.startsWith("structure"))
|
||||
{
|
||||
regions.add(region);
|
||||
source.add(structure.atlas());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (TextureAtlas.AtlasRegion region : regions) {
|
||||
ArrayList<Pixmap> pics = new ArrayList<>();
|
||||
ArrayList<Pixmap> spics = new ArrayList<>();
|
||||
if (completePicture == null) {
|
||||
region.getTexture().getTextureData().prepare();
|
||||
completePicture = region.getTexture().getTextureData().consumePixmap();
|
||||
}
|
||||
|
||||
Pixmap completePicture = region.getTexture().getTextureData().consumePixmap();
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int x = 0; x < 3; x++) {
|
||||
int px = region.getRegionX() + (x * tileSize);
|
||||
@@ -117,6 +133,7 @@ public class BiomeTexture implements Serializable {
|
||||
smallImages.add(spics);
|
||||
edgeImages.add(new IntMap<>());
|
||||
|
||||
completePicture.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -124,6 +141,8 @@ public class BiomeTexture implements Serializable {
|
||||
|
||||
public Pixmap getPixmap(int biomeSubIndex) {
|
||||
if (biomeSubIndex >= edgeImages.size() || biomeSubIndex < 0) {
|
||||
if(emptyPixmap==null)
|
||||
emptyPixmap=new Pixmap(1, 1, Pixmap.Format.RGBA8888);
|
||||
return emptyPixmap;
|
||||
}
|
||||
return images.get(biomeSubIndex).get(BigPictures.Center.value);
|
||||
|
||||
@@ -9,11 +9,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import forge.adventure.data.BiomeData;
|
||||
import forge.adventure.data.BiomeSpriteData;
|
||||
import forge.adventure.data.BiomeTerrainData;
|
||||
import forge.adventure.data.PointOfInterestData;
|
||||
import forge.adventure.data.WorldData;
|
||||
import forge.adventure.data.*;
|
||||
import forge.adventure.pointofintrest.PointOfInterest;
|
||||
import forge.adventure.pointofintrest.PointOfInterestMap;
|
||||
import forge.adventure.scene.Scene;
|
||||
@@ -24,10 +20,7 @@ import forge.adventure.util.SaveFileContent;
|
||||
import forge.adventure.util.SaveFileData;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class that will create the world from the configuration
|
||||
@@ -55,6 +48,26 @@ public class World implements Disposable, SaveFileContent {
|
||||
return (int) (Math.log(Long.highestOneBit(biome)) / Math.log(2));
|
||||
}
|
||||
|
||||
public boolean collidingTile(Rectangle boundingRect)
|
||||
{
|
||||
Set<Pair<Integer,Integer>> points=new HashSet<>();
|
||||
|
||||
int xLeft=(int) boundingRect.getX() / getTileSize();
|
||||
int yTop=(int) boundingRect.getY() / getTileSize();
|
||||
int xRight=(int) (boundingRect.getX()+boundingRect.getWidth()) / getTileSize();
|
||||
int yBottom= (int) (boundingRect.getY()+boundingRect.getHeight()) / getTileSize();
|
||||
|
||||
if(getBiome(xLeft,yTop)==0)
|
||||
return true;
|
||||
if(getBiome(xLeft,yBottom)==0)
|
||||
return true;
|
||||
if(getBiome(xRight,yBottom)==0)
|
||||
return true;
|
||||
if(getBiome(xRight,yTop)==0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public void loadWorldData() {
|
||||
if(worldDataLoaded)
|
||||
return;
|
||||
@@ -85,6 +98,9 @@ public class World implements Disposable, SaveFileContent {
|
||||
biomeImage=saveFileData.readPixmap("biomeImage");
|
||||
biomeMap=(long[][])saveFileData.readObject("biomeMap");
|
||||
terrainMap=(int[][])saveFileData.readObject("terrainMap");
|
||||
|
||||
|
||||
|
||||
width=saveFileData.readInt("width");
|
||||
height=saveFileData.readInt("height");
|
||||
mapObjectIds = new SpritesDataMap(getChunkSize(), this.data.tileSize, this.data.width / getChunkSize());
|
||||
@@ -269,6 +285,7 @@ public class World implements Disposable, SaveFileContent {
|
||||
endX = width;
|
||||
endY = height;
|
||||
}
|
||||
HashMap<BiomeStructureData,BiomeStructure> structureDataMap=new HashMap<>();
|
||||
for (int x = beginX; x < endX; x++) {
|
||||
for (int y = beginY; y < endY; y++) {
|
||||
//value 0-1 based on noise
|
||||
@@ -288,16 +305,34 @@ public class World implements Disposable, SaveFileContent {
|
||||
pix.drawPixel(x, y);
|
||||
biomeMap[x][y] |= (1L << biomeIndex);
|
||||
int terrainCounter=1;
|
||||
if(biome.terrain==null)
|
||||
continue;
|
||||
for(BiomeTerrainData terrain:biome.terrain)
|
||||
if(biome.terrain!=null)
|
||||
{
|
||||
float terrainNoise = ((float)noise.eval(x / (float) width * (noiseZoom*terrain.resolution), y / (float) height * (noiseZoom*terrain.resolution)) + 1) / 2;
|
||||
if(terrainNoise>=terrain.min&&terrainNoise<=terrain.max)
|
||||
for(BiomeTerrainData terrain:biome.terrain)
|
||||
{
|
||||
terrainMap[x][y]=terrainCounter;
|
||||
float terrainNoise = ((float)noise.eval(x / (float) width * (noiseZoom*terrain.resolution), y / (float) height * (noiseZoom*terrain.resolution)) + 1) / 2;
|
||||
if(terrainNoise>=terrain.min&&terrainNoise<=terrain.max)
|
||||
{
|
||||
terrainMap[x][y]=terrainCounter;
|
||||
}
|
||||
terrainCounter++;
|
||||
}
|
||||
}
|
||||
if(biome.structures!=null)
|
||||
{
|
||||
for(BiomeStructureData data:biome.structures)
|
||||
{
|
||||
BiomeStructure structure;
|
||||
if(!structureDataMap.containsKey(data))
|
||||
{
|
||||
structureDataMap.put(data,new BiomeStructure(data,seed,biomeWidth,biomeHeight));
|
||||
}
|
||||
structure=structureDataMap.get(data);
|
||||
int structureIndex=structure.objectID(x-biomeXStart,y-biomeYStart);
|
||||
if(structureIndex>=0)
|
||||
terrainMap[x][y]=terrainCounter+structureIndex;
|
||||
|
||||
terrainCounter+=structure.structureObjectCount();
|
||||
}
|
||||
terrainCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,6 +467,9 @@ public class World implements Disposable, SaveFileContent {
|
||||
for (int y = (int) currentPoint.y - 1; y < currentPoint.y + 2; y++) {
|
||||
if(x<0||y<=0||x>=width||y>height)continue;
|
||||
biomeMap[x][height - y] |= (1L << biomeIndex);
|
||||
terrainMap[x][height-y]=0;
|
||||
|
||||
|
||||
pix.drawPixel(x, height-y);
|
||||
}
|
||||
}
|
||||
@@ -465,7 +503,9 @@ public class World implements Disposable, SaveFileContent {
|
||||
|
||||
if( (int)currentPoint.x<0|| (int)currentPoint.y<=0|| (int)currentPoint.x>=width|| (int)currentPoint.y>height)continue;
|
||||
biomeMap[(int) currentPoint.x][height - (int) currentPoint.y] |= (1L << biomeIndex);
|
||||
terrainMap[(int) currentPoint.x][height - (int) currentPoint.y]=0;
|
||||
pix.drawPixel((int) currentPoint.x, height - (int) currentPoint.y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -482,6 +522,8 @@ public class World implements Disposable, SaveFileContent {
|
||||
BiomeSpriteData sprite = data.GetBiomeSprites().getSpriteData(name);
|
||||
double spriteNoise = (noise.eval(x / (double) width * noiseZoom*sprite.resolution, y / (double) invertedHeight * noiseZoom*sprite.resolution) + 1) / 2;
|
||||
if (spriteNoise >= sprite.startArea && spriteNoise <= sprite.endArea) {
|
||||
if(terrainMap[x][invertedHeight]>biome.terrain.length)
|
||||
continue;
|
||||
if (random.nextFloat() <= sprite.density) {
|
||||
String spriteKey = sprite.key();
|
||||
int key;
|
||||
|
||||
@@ -58,6 +58,8 @@ public class WorldSave {
|
||||
static public boolean load(int currentSlot) {
|
||||
|
||||
String fileName = WorldSave.getSaveFile(currentSlot);
|
||||
if(!new File(fileName).exists())
|
||||
return false;
|
||||
new File(getSaveDir()).mkdirs();
|
||||
try {
|
||||
try(FileInputStream fos = new FileInputStream(fileName);
|
||||
|
||||
@@ -265,6 +265,14 @@ public class SplashScreen extends FContainer {
|
||||
add(btnHome);
|
||||
btnAdventure.setBounds(btn_x, btn_y + height + padding / 2, btn_w, height);
|
||||
add(btnAdventure);
|
||||
|
||||
if(Forge.createNewAdventureMap)
|
||||
{
|
||||
bgAnimation.progress = 1;
|
||||
bgAnimation.openAdventure = true;
|
||||
Forge.openAdventure();
|
||||
Forge.clearSplashScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
"resolution": 10
|
||||
}
|
||||
],
|
||||
"structures":[
|
||||
{
|
||||
"structureAtlasPath":"world/tilesets/forest.atlas",
|
||||
"x": 0.5,
|
||||
"y": 0.5,
|
||||
"size": 0.3
|
||||
}
|
||||
],
|
||||
"width": 0.7,
|
||||
"height": 0.7,
|
||||
"color": "59a650",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,20 @@
|
||||
|
||||
forest.png
|
||||
size: 96,64
|
||||
format: RGBA8888
|
||||
filter: Nearest,Nearest
|
||||
repeat: none
|
||||
Source
|
||||
rotate: false
|
||||
xy: 0, 0
|
||||
size: 16, 16
|
||||
orig: 0, 0
|
||||
offset: 0, 0
|
||||
index: 0
|
||||
structure_000000
|
||||
rotate: false
|
||||
xy: 48, 0
|
||||
size: 48, 64
|
||||
orig: 0, 0
|
||||
offset: 0, 0
|
||||
index: 0
|
||||
BIN
forge-gui/res/adventure/Shandalar/world/tilesets/forest.png
Normal file
BIN
forge-gui/res/adventure/Shandalar/world/tilesets/forest.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user