mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-03-01 03:30:04 +00:00
Merge branch 'master' of https://github.com/badvision/lawless-legends
This commit is contained in:
commit
e2025a750f
@ -84,5 +84,12 @@
|
||||
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,12 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
To change this template, choose Tools | Templates
|
||||
and open the template in the editor.
|
||||
-->
|
||||
|
||||
<xs:schema version="1.0"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="qualified" targetNamespace="outlaw" xmlns:tns="outlaw">
|
||||
elementFormDefault="qualified" targetNamespace="outlaw" xmlns:tns="outlaw" attributeFormDefault="unqualified">
|
||||
<xs:complexType name="image">
|
||||
<xs:sequence>
|
||||
<xs:element name="category" type="xs:string" maxOccurs="unbounded" minOccurs="0"/>
|
||||
@ -35,7 +30,7 @@ and open the template in the editor.
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string"/>
|
||||
<xs:element name="description" type="xs:string" minOccurs="0"/>
|
||||
<xs:element name="script" type="xs:string"/>
|
||||
<xs:element name="block" type="tns:block"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="locationScript">
|
||||
@ -87,6 +82,55 @@ and open the template in the editor.
|
||||
<xs:attribute name="startX" type="xs:int" default="0"/>
|
||||
<xs:attribute name="startY" type="xs:int" default="0"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="block">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" name="next" type="tns:next"/>
|
||||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:element name="field" type="tns:field"/>
|
||||
<xs:element name="mutation" type="tns:mutation"/>
|
||||
<xs:element name="statement" type="tns:statement"/>
|
||||
<xs:element name="value" type="tns:value"/>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="inline" type="xs:boolean"/>
|
||||
<xs:attribute name="type" use="required" type="xs:NCName"/>
|
||||
<xs:attribute name="x" type="xs:integer"/>
|
||||
<xs:attribute name="y" type="xs:integer"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="next">
|
||||
<xs:sequence>
|
||||
<xs:element name="block" type="tns:block"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="field">
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:NMTOKEN">
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="mutation">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" name="arg" type="tns:arg"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" type="xs:NCName"/>
|
||||
<xs:anyAttribute/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="arg">
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="statement">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" name="block" type="tns:block"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="value">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" name="block" type="tns:block"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" use="required" type="xs:NCName"/>
|
||||
</xs:complexType>
|
||||
<xs:element name="gameData">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
@ -95,5 +139,5 @@ and open the template in the editor.
|
||||
<xs:element name="map" minOccurs="0" maxOccurs="unbounded" type="tns:map"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
|
53
OutlawEditor/src/main/resources/testData/blocklytest1.xml
Normal file
53
OutlawEditor/src/main/resources/testData/blocklytest1.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<gameData xmlns="outlaw">
|
||||
<map>
|
||||
<scripts>
|
||||
<enter>
|
||||
<name>name</name>
|
||||
<description>description</description>
|
||||
<block type="variables_set" inline="true" x="245" y="27">
|
||||
<field name="VAR">var1</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare" inline="true">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">var1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">WHILE</field>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">var1</field>
|
||||
<value name="TEXT">
|
||||
<block type="text">
|
||||
<field name="TEXT">blah</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</enter>
|
||||
</scripts>
|
||||
</map>
|
||||
</gameData>
|
118
OutlawEditor/src/main/resources/testData/blocklytest2.xml
Normal file
118
OutlawEditor/src/main/resources/testData/blocklytest2.xml
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<gameData xmlns="outlaw">
|
||||
<map>
|
||||
<scripts>
|
||||
<enter>
|
||||
<name>name</name>
|
||||
<description>description</description>
|
||||
<block type="procedures_defreturn" inline="false" x="213" y="27">
|
||||
<mutation>
|
||||
<arg name="x"></arg>
|
||||
<arg name="y"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">Procedure</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="true">
|
||||
<field name="VAR">var1</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_if" inline="false">
|
||||
<mutation elseif="1" else="1"></mutation>
|
||||
<value name="IF0">
|
||||
<block type="logic_compare" inline="true">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">var1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">WHILE</field>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">var1</field>
|
||||
<value name="TEXT">
|
||||
<block type="text">
|
||||
<field name="TEXT">blah</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</statement>
|
||||
<value name="IF1">
|
||||
<block type="logic_operation" inline="true">
|
||||
<field name="OP">OR</field>
|
||||
<value name="A">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="logic_negate" inline="false">
|
||||
<value name="BOOL">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO1">
|
||||
<block type="math_change" inline="true">
|
||||
<field name="VAR">x</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<statement name="ELSE">
|
||||
<block type="variables_set" inline="true">
|
||||
<field name="VAR">x</field>
|
||||
<value name="VALUE">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="Procedure">
|
||||
<arg name="x"></arg>
|
||||
<arg name="y"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ARG1">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">y</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<value name="RETURN">
|
||||
<block type="logic_null"></block>
|
||||
</value>
|
||||
</block>
|
||||
</enter>
|
||||
</scripts>
|
||||
</map>
|
||||
</gameData>
|
@ -0,0 +1,100 @@
|
||||
package org.badvision.outlaweditor.test;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import javax.xml.bind.JAXB;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.namespace.QName;
|
||||
import org.badvision.outlaweditor.data.xml.Block;
|
||||
import org.badvision.outlaweditor.data.xml.GameData;
|
||||
import org.badvision.outlaweditor.data.xml.Map;
|
||||
import org.badvision.outlaweditor.data.xml.Map.Scripts;
|
||||
import org.badvision.outlaweditor.data.xml.Script;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Various sanity checks of the Mythos script editing feature
|
||||
*
|
||||
* @author blurry
|
||||
*/
|
||||
public class TestMythosEditor {
|
||||
|
||||
static public final String[] testData = {"testData/blocklytest1.xml", "testData/blocklytest2.xml"};
|
||||
static public final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
|
||||
@Test
|
||||
public void deserializeTest() throws Exception {
|
||||
for (String path : testData) {
|
||||
System.out.println("testing " + path);
|
||||
Block theBlock = getBlock(path);
|
||||
assertNotNull(theBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundtripTest() throws Exception {
|
||||
JAXBContext context = JAXBContext.newInstance("org.badvision.outlaweditor.data.xml");
|
||||
Marshaller m = context.createMarshaller();
|
||||
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
for (String path : testData) {
|
||||
System.out.println("testing " + path);
|
||||
Block theBlock = getBlock(path);
|
||||
StringWriter testWriter = new StringWriter();
|
||||
|
||||
GameData d = new GameData();
|
||||
Map map = new Map();
|
||||
d.getMap().add(map);
|
||||
Script script = new Script();
|
||||
script.setName("name");
|
||||
script.setDescription("description");
|
||||
script.setBlock(theBlock);
|
||||
map.setScripts(new Scripts());
|
||||
map.getScripts().getEnterOrExitOrStepOn().add(new JAXBElement<Script>(new QName("outlaw", "enter"), Script.class, script));
|
||||
m.marshal(d, testWriter);
|
||||
String testOutput = testWriter.getBuffer().toString();
|
||||
assertNotNull(testOutput);
|
||||
// assertSimilar(XML_HEADER + testOutput, getFileContents(path));
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileContents(String path) throws IOException {
|
||||
BufferedInputStream data = (BufferedInputStream) getClass().getClassLoader().getResource(path).getContent();
|
||||
byte[] buf = new byte[1024];
|
||||
StringBuilder contents = new StringBuilder();
|
||||
while (data.available() > 0) {
|
||||
int len = data.read(buf);
|
||||
if (len > 0) {
|
||||
String append = new String(buf, 0, len);
|
||||
contents.append(append);
|
||||
}
|
||||
}
|
||||
return contents.toString();
|
||||
}
|
||||
|
||||
public void assertSimilar(String s1, String s2) {
|
||||
s1 = s1.replaceAll("\\s", "");
|
||||
s1 = s1.replaceAll("\\n", "");
|
||||
s2 = s2.replaceAll("\\s", "");
|
||||
s2 = s2.replaceAll("\\n", "");
|
||||
assertEquals(s1, s2);
|
||||
}
|
||||
|
||||
public Block getBlock(String resourcePath) throws IOException {
|
||||
BufferedInputStream data = (BufferedInputStream) getClass().getClassLoader().getResource(resourcePath).getContent();
|
||||
assertNotNull(data);
|
||||
GameData gd = JAXB.unmarshal(data, GameData.class);
|
||||
assertNotNull(gd);
|
||||
assertNotNull(gd.getMap());
|
||||
assertEquals(1, gd.getMap().size());
|
||||
Scripts s = gd.getMap().get(0).getScripts();
|
||||
assertNotNull(s);
|
||||
assertNotNull(s.getEnterOrExitOrStepOn());
|
||||
assertEquals(1, s.getEnterOrExitOrStepOn().size());
|
||||
Script scr = (Script) s.getEnterOrExitOrStepOn().get(0).getValue();
|
||||
return scr.getBlock();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user