mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
WaveFunctionCollapse editor
This commit is contained in:
@@ -888,6 +888,8 @@ public class Forge implements ApplicationListener {
|
||||
//check if sentry is enabled, if not it will call the gui interface but here we end the graphics so we only send it via sentry..
|
||||
if (BugReporter.isSentryEnabled())
|
||||
BugReporter.reportException(ex);
|
||||
else
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (showFPS)
|
||||
frameRate.render();
|
||||
|
||||
@@ -1,34 +1,62 @@
|
||||
package forge.adventure.data;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class BiomeStructureData {
|
||||
|
||||
static public class BiomeStructureDataMapping
|
||||
{
|
||||
public int getColor() {
|
||||
return 0xff000000 |(Integer.parseInt(color,16));
|
||||
}
|
||||
public String name;
|
||||
public String color;
|
||||
public boolean collision;
|
||||
|
||||
public BiomeStructureDataMapping() {
|
||||
|
||||
}
|
||||
public BiomeStructureDataMapping(BiomeStructureDataMapping biomeStructureDataMapping) {
|
||||
this.name=biomeStructureDataMapping.name;
|
||||
this.color=biomeStructureDataMapping.color;
|
||||
this.collision=biomeStructureDataMapping.collision;
|
||||
}
|
||||
}
|
||||
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 String sourcePath;
|
||||
public boolean periodicInput=true;
|
||||
public float height;
|
||||
public float width;
|
||||
public int ground;
|
||||
public int symmetry;
|
||||
public boolean periodicOutput;
|
||||
public int symmetry=2;
|
||||
public boolean periodicOutput=true;
|
||||
public BiomeStructureDataMapping[] mappingInfo;
|
||||
|
||||
public BiomeStructureData( )
|
||||
{
|
||||
public BiomeStructureData( ) {
|
||||
|
||||
}
|
||||
public BiomeStructureData(BiomeStructureData biomeStructureData) {
|
||||
this.structureAtlasPath=biomeStructureData.structureAtlasPath;
|
||||
this.sourcePath=biomeStructureData.sourcePath;
|
||||
this.x=biomeStructureData.x;
|
||||
this.y=biomeStructureData.y;
|
||||
this.size=biomeStructureData.size;
|
||||
this.width=biomeStructureData.width;
|
||||
this.height=biomeStructureData.height;
|
||||
this.randomPosition=biomeStructureData.randomPosition;
|
||||
this.collision=biomeStructureData.collision;
|
||||
if(biomeStructureData.mappingInfo!=null)
|
||||
{
|
||||
this.mappingInfo=new BiomeStructureDataMapping[ biomeStructureData.mappingInfo.length];
|
||||
for(int i=0;i<biomeStructureData.mappingInfo.length;i++)
|
||||
this.mappingInfo[i]=new BiomeStructureDataMapping(biomeStructureData.mappingInfo[i]);
|
||||
}
|
||||
else
|
||||
this.mappingInfo=null;
|
||||
}
|
||||
|
||||
public BufferedImage sourceImage() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.adventure.data;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.SerializationException;
|
||||
import forge.adventure.util.Config;
|
||||
import forge.adventure.util.Paths;
|
||||
import forge.adventure.world.BiomeSprites;
|
||||
@@ -80,10 +81,16 @@ public class WorldData implements Serializable {
|
||||
|
||||
public List<BiomeData> GetBiomes() {
|
||||
if (biomes == null) {
|
||||
biomes = new ArrayList<BiomeData>();
|
||||
Json json = new Json();
|
||||
for (String name : biomesNames) {
|
||||
biomes.add(json.fromJson(BiomeData.class, Config.instance().getFile(name)));
|
||||
try
|
||||
{
|
||||
biomes = new ArrayList<BiomeData>();
|
||||
Json json = new Json();
|
||||
for (String name : biomesNames) {
|
||||
biomes.add(json.fromJson(BiomeData.class, Config.instance().getFile(name)));
|
||||
}
|
||||
}
|
||||
catch (SerializationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return biomes;
|
||||
|
||||
@@ -20,6 +20,8 @@ public class BiomeStructure {
|
||||
private int dataMap[][];
|
||||
boolean init=false;
|
||||
private TextureAtlas structureAtlas;
|
||||
public BufferedImage image;
|
||||
|
||||
public BiomeStructure(BiomeStructureData data,long seed,int width,int height)
|
||||
{
|
||||
this.data=data;
|
||||
@@ -35,59 +37,42 @@ public class BiomeStructure {
|
||||
return structureAtlas;
|
||||
}
|
||||
public int structureObjectCount() {
|
||||
int count=0;
|
||||
for(TextureAtlas.AtlasRegion region:atlas ().getRegions())
|
||||
{
|
||||
if(region.name.startsWith("structure"))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
return data.mappingInfo.length;
|
||||
}
|
||||
|
||||
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)
|
||||
if(x>=dataMap.length||x<0||y<0||y>=dataMap[0].length)
|
||||
return -1;
|
||||
return dataMap[x][y];
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
public void initialize() {
|
||||
init=true;
|
||||
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())
|
||||
for(int i=0;i<data.mappingInfo.length;i++)
|
||||
{
|
||||
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++;
|
||||
}
|
||||
colorIdMap.put(Integer.parseInt(data.mappingInfo[i].color,16),i);
|
||||
}
|
||||
BufferedImage image=model.graphics();
|
||||
boolean suc=model.run((int) seed,0);
|
||||
if(!suc)
|
||||
{
|
||||
dataMap=new int[(int) (data.width* biomeWidth)][ (int) (data.height*biomeHeight)];
|
||||
return;
|
||||
}
|
||||
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);
|
||||
int rgb=image.getRGB(x,y) & 0xffffff;
|
||||
if(!colorIdMap.containsKey(rgb))
|
||||
{
|
||||
dataMap[x][y]=-1;
|
||||
@@ -101,14 +86,24 @@ public class BiomeStructure {
|
||||
}
|
||||
|
||||
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);
|
||||
return ImageIO.read(new File(Config.instance().getFilePath(data.sourcePath)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int x() {
|
||||
return (int) ((data.x*biomeWidth)-(data.width*biomeWidth)/2);
|
||||
}
|
||||
public int y() {
|
||||
return (int) ((data.y*biomeHeight)-(data.height*biomeHeight)/2);
|
||||
}
|
||||
|
||||
public BiomeStructureData.BiomeStructureDataMapping[] mapping() {
|
||||
return data.mappingInfo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -95,13 +95,12 @@ public class BiomeTexture implements Serializable {
|
||||
for(BiomeStructureData structureData:data.structures)
|
||||
{
|
||||
BiomeStructure structure=new BiomeStructure(structureData,0,0,0);
|
||||
for(TextureAtlas.AtlasRegion region:structure.atlas ().getRegions())
|
||||
TextureAtlas atlas=structure.atlas ();
|
||||
for(BiomeStructureData.BiomeStructureDataMapping mapping:structure.mapping())
|
||||
{
|
||||
if(region.name.startsWith("structure"))
|
||||
{
|
||||
regions.add(region);
|
||||
source.add(structure.atlas());
|
||||
}
|
||||
|
||||
regions.add(atlas.findRegion(mapping.name));
|
||||
source.add(atlas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,9 +327,15 @@ public class World implements Disposable, SaveFileContent {
|
||||
structureDataMap.put(data,new BiomeStructure(data,seed,biomeWidth,biomeHeight));
|
||||
}
|
||||
structure=structureDataMap.get(data);
|
||||
int structureIndex=structure.objectID(x-biomeXStart,y-biomeYStart);
|
||||
int structureXStart= structure.x()+beginX;
|
||||
int structureYStart= structure.y()+beginY;
|
||||
int structureIndex=structure.objectID(x-structureXStart,y-structureYStart);
|
||||
if(structureIndex>=0)
|
||||
{
|
||||
pix.setColor(data.mappingInfo[structureIndex].getColor());
|
||||
pix.drawPixel(x, y);
|
||||
terrainMap[x][y]=terrainCounter+structureIndex;
|
||||
}
|
||||
|
||||
terrainCounter+=structure.structureObjectCount();
|
||||
}
|
||||
@@ -395,6 +401,9 @@ public class World implements Disposable, SaveFileContent {
|
||||
foundSolution=true;
|
||||
x=x+xi*data.tileSize;
|
||||
y=y+yi*data.tileSize;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user