mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
export ActorValue into JSON
Former-commit-id: 9a5f09cf124a0e26baa9c671c2097351b906cb62 Former-commit-id: 76853a50c9491e7ee147a5d48727bb33b4323ebf
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -84,6 +84,9 @@ public class ActorWithBody implements Actor, Visible, Glowing {
|
||||
|
||||
long referenceID;
|
||||
|
||||
/**
|
||||
* Give new random ReferenceID and initialise ActorValue
|
||||
*/
|
||||
public ActorWithBody() {
|
||||
referenceID = new HQRNG(0x7E22A211AAL).nextLong();
|
||||
actorValue = new ActorValue();
|
||||
|
||||
@@ -26,6 +26,7 @@ public class CommandDict {
|
||||
dict.put("zoom", new Zoom());
|
||||
dict.put("teleport", new TeleportPlayer());
|
||||
dict.put("cat", new CatStdout());
|
||||
dict.put("exportav", new ExportAV());
|
||||
}
|
||||
|
||||
public static ConsoleCommand getCommand(String commandName) {
|
||||
|
||||
47
src/com/Torvald/Terrarum/ConsoleCommand/ExportAV.java
Normal file
47
src/com/Torvald/Terrarum/ConsoleCommand/ExportAV.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.Torvald.Terrarum.ConsoleCommand;
|
||||
|
||||
import com.Torvald.Terrarum.Terrarum;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-10.
|
||||
*/
|
||||
public class ExportAV implements ConsoleCommand {
|
||||
@Override
|
||||
public void execute(String[] args) {
|
||||
if (args.length == 2) {
|
||||
JsonElement avelem = new Gson().toJsonTree(Terrarum.game.getPlayer().getActorValue());
|
||||
String jsonString = avelem.toString();
|
||||
|
||||
FileWriter writer;
|
||||
try {
|
||||
writer = new FileWriter(Terrarum.defaultDir + "/Exports/" + args[1] + ".json");
|
||||
writer.write(jsonString);
|
||||
writer.close();
|
||||
|
||||
new Echo().execute("ExportAV: exported to " + args[1] + ".json");
|
||||
}
|
||||
catch (IOException e) {
|
||||
new Echo().execute("ExportAV: IOException raised.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
printUsage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printUsage() {
|
||||
Echo echo = new Echo();
|
||||
echo.execute("Export ActorValue as JSON format.");
|
||||
echo.execute("Usage: exportav (id) filename-without-extension");
|
||||
echo.execute("blank ID for player");
|
||||
}
|
||||
}
|
||||
@@ -93,8 +93,11 @@ public class ExportMap implements ConsoleCommand {
|
||||
|
||||
ImageIO.write(image, "PNG", new File(dir + args[1] + ".png"));
|
||||
|
||||
new Echo().execute("ExportMap: exported to " + args[1] + ".png");
|
||||
|
||||
} catch (IOException e) {
|
||||
new Echo().execute("ExportMap: IOException raised.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mapData = null;
|
||||
@@ -102,8 +105,6 @@ public class ExportMap implements ConsoleCommand {
|
||||
|
||||
// Free up some memory
|
||||
System.gc();
|
||||
|
||||
new Echo().execute("ExportMap: exported to " + args[1] + ".png");
|
||||
}
|
||||
else{
|
||||
printUsage();
|
||||
|
||||
@@ -27,11 +27,11 @@ public class MapGenerator {
|
||||
private static final int HILL_WIDTH = 256; // power of two!
|
||||
private static final int MAX_HILL_HEIGHT = 100;
|
||||
|
||||
private static final int OCEAN_WIDTH = 400;
|
||||
private static final int SHORE_WIDTH = 120;
|
||||
private static final int MAX_OCEAN_DEPTH = 200;
|
||||
private static int OCEAN_WIDTH = 400;
|
||||
private static int SHORE_WIDTH = 120;
|
||||
private static int MAX_OCEAN_DEPTH = 200;
|
||||
|
||||
private static int GLACIER_MOUNTAIN_WIDTH;
|
||||
private static int GLACIER_MOUNTAIN_WIDTH = 900;
|
||||
private static final int GLACIER_MOUNTAIN_HEIGHT = 300;
|
||||
|
||||
private static final byte AIR = 0;
|
||||
@@ -79,10 +79,15 @@ public class MapGenerator {
|
||||
width = map.width;
|
||||
height = map.height;
|
||||
|
||||
float widthMulFactor = (width / 8192f);
|
||||
|
||||
dirtThickness = (int) (100 * height / 1024f);
|
||||
minimumFloatingIsleHeight = (int) (25 * (height / 1024f));
|
||||
TERRAIN_AVERAGE_HEIGHT = height / 4;
|
||||
GLACIER_MOUNTAIN_WIDTH = Math.round(900 * (width / 8192f));
|
||||
|
||||
OCEAN_WIDTH = Math.round(OCEAN_WIDTH * widthMulFactor);
|
||||
SHORE_WIDTH = Math.round(SHORE_WIDTH * widthMulFactor);
|
||||
GLACIER_MOUNTAIN_WIDTH = Math.round(GLACIER_MOUNTAIN_WIDTH * widthMulFactor);
|
||||
}
|
||||
|
||||
public static void setSeed(long seed) {
|
||||
@@ -878,11 +883,13 @@ public class MapGenerator {
|
||||
float k = (width) / FastMath.sqrt(height);
|
||||
|
||||
if (y < height) {
|
||||
// ground
|
||||
return width;
|
||||
}
|
||||
else {
|
||||
// underground
|
||||
return Math.round(
|
||||
k * FastMath.sqrt(y)
|
||||
k * FastMath.sqrt(y) + (random.nextInt(3) - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user