WIP minetest <-> laby import/export

- currently possible to export a laby into minetest
- start of a lua content parser to import .we into lab
This commit is contained in:
philippe lhardy
2020-11-03 23:21:29 +01:00
parent 41067707bc
commit 9355fd8b6d
11 changed files with 424 additions and 10 deletions

View File

@@ -2,15 +2,17 @@ package org.artisanlogiciel.games.maze.persist;
import org.artisanlogiciel.games.maze.Brick;
import org.artisanlogiciel.games.maze.LabyModel;
import org.artisanlogiciel.games.minetest.Material;
import org.artisanlogiciel.games.minetest.Node;
import org.artisanlogiciel.games.minetest.WorlEditGenerator;
import java.io.*;
import static org.artisanlogiciel.games.minetest.Material.GRASS_MATERIAL;
public class MazePersistWorldEdit {
private LabyModel model;
private WorlEditGenerator generator;
private static final String GRASS_MATERIAL = "default:dirt_with_grass";
public MazePersistWorldEdit(LabyModel model) {
this.model = model;
@@ -24,6 +26,12 @@ public class MazePersistWorldEdit {
}
}
private Node newNode(int x, int y, String material)
{
// x,y,z => x,z,y in minetest
return new Node(x,0, y, Material.getMaterialByName(material));
}
void addWalls(int pX, int pY) {
short walls = model.getWalls(pX, pY);
short wdrawn = 0;
@@ -36,14 +44,14 @@ public class MazePersistWorldEdit {
String material = GRASS_MATERIAL;
int x = ox + (int) (pX * w);
int y = oy + (int) (pY * h);
int x = ox + (pX * w);
int y = oy + (pY * h);
// copied from drawing, where order did matter, might not be the case here...
//if ((pY == 0) && LabyModel.isFlagSet(walls, Brick.UP)) {
if (LabyModel.isFlagSet(walls, Brick.UP)) {
for ( int dx = 0; dx < w; dx++) {
addNode(new Node(x + dx, y, z, material));
addNode(newNode(x + dx, y,material));
}
wdrawn |= Brick.UP;
}
@@ -66,7 +74,7 @@ public class MazePersistWorldEdit {
//if ((pX == 0) && LabyModel.isFlagSet(walls, Brick.LEFT)) {
if (LabyModel.isFlagSet(walls, Brick.LEFT)) {
for (int dy = 0; dy < h; dy ++) {
addNode(new Node(x, y + dy, z, material));
addNode(newNode(x, y + dy, material));
}
wdrawn |= Brick.LEFT;
}
@@ -77,7 +85,7 @@ public class MazePersistWorldEdit {
// WIP using WorldEditGenerator
if ((pFormat == null) || (pFormat.equals("we"))) {
Node refNode = new Node(0,0,0,"default:dirt_with_grass");
Node refNode = new Node(0,0,0);
StringBuilder builder = new StringBuilder();
generator = new WorlEditGenerator(builder,refNode);
generator.writeStart();

View File

@@ -0,0 +1,24 @@
package org.artisanlogiciel.games.minetest;
public class Material {
public static final String GRASS_MATERIAL = "default:dirt_with_grass";
public static Material DEFAULT = new Material(GRASS_MATERIAL);
private String name;
public Material(String name) {
this.name = name;
}
public static Material getMaterialByName(String name)
{
return DEFAULT;
}
@Override
public String toString() {
return "name";
}
}

View File

@@ -4,15 +4,22 @@ public class Node {
int x;
int y;
int z;
String material;
Material material;
public Node(int x, int y, int z, String material) {
public Node(int x, int y, int z, Material material) {
this.x = x;
this.y = y;
this.z = z;
this.material = material;
}
public Node(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
this.material = Material.DEFAULT;
}
public int getX() {
return x;
}
@@ -25,7 +32,7 @@ public class Node {
return z;
}
public String getMaterial() {
public Material getMaterial() {
return material;
}
}

View File

@@ -51,7 +51,7 @@ public class WorlEditGenerator
addIntMember("x", node.getX() - refNode.getX());
addIntMember("y", node.getY() - refNode.getY());
addIntMember("z", node.getZ() - refNode.getZ());
addStringMember("name",node.getMaterial());
addStringMember("name",node.getMaterial().toString() );
luaNode.append("}");
start=false;
}

View File

@@ -0,0 +1,32 @@
package org.artisanlogiciel.lua;
public class CharProvider {
String input;
int current;
public CharProvider(String input) {
this.input = input;
current = 0;
}
public char getNextchar()
{
int i = current;
if ( input.length() > current) {
current++;
return input.charAt(i);
}
else
{
return 0;
}
}
public void pushBackChar(char c)
{
System.out.print('*');
current--;
}
}

View File

@@ -0,0 +1,17 @@
package org.artisanlogiciel.lua;
public class LuaNumber
extends LuaObject {
int number;
LuaNumber(int number)
{
this.number = number;
}
@Override
public String toString() {
return "" + number ;
}
}

View File

@@ -0,0 +1,4 @@
package org.artisanlogiciel.lua;
public class LuaObject {
}

View File

@@ -0,0 +1,43 @@
package org.artisanlogiciel.lua;
import java.util.ArrayList;
import java.util.List;
public class LuaSequence
extends LuaObject{
List<LuaObject> items;
public LuaSequence()
{
items = new ArrayList<>();
}
void addObject(LuaObject object)
{
if ( object == null )
{
System.err.println("adding null tuple");
}
items.add(object);
}
@Override
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append('{');
if (items.size() > 0) {
buffer.append(items.get(0).toString());
if (items.size() > 1) {
for (int i = 1; i < items.size(); i ++)
{
buffer.append(',');
buffer.append(items.get(i).toString());
}
}
}
buffer.append('}');
return buffer.toString();
}
}

View File

@@ -0,0 +1,17 @@
package org.artisanlogiciel.lua;
public class LuaString
extends LuaObject
{
String string;
public LuaString(StringBuffer stringBuffer)
{
string = stringBuffer.toString();
}
@Override
public String toString() {
return '"' + string + '"' ;
}
}

View File

@@ -0,0 +1,32 @@
package org.artisanlogiciel.lua;
import java.util.ArrayList;
import java.util.List;
public class LuaTuple
extends LuaObject
{
List<LuaObject> items;
public LuaTuple() {
this.items = new ArrayList<>(2);
}
public LuaObject addItem(LuaObject item)
{
items.add(item);
return item;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append('[');
buffer.append(items.get(0).toString());
buffer.append("]");
buffer.append('=');
buffer.append(items.get(1).toString());
return buffer.toString();
}
}

File diff suppressed because one or more lines are too long