Tweak scenario output and schema so that they match; write script to XML-validate a whole scenario

This commit is contained in:
2015-02-05 21:37:13 -05:00
parent 9cf65fab35
commit 1778cd9a61
9 changed files with 78 additions and 31 deletions

View File

@@ -60,6 +60,14 @@
<xs:enumeration value="luck"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="useFlag">
<xs:restriction base="xs:token">
<xs:enumeration value="help-one"/>
<xs:enumeration value="harm-one"/>
<xs:enumeration value="help-all"/>
<xs:enumeration value="harm-all"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="item">
<xs:complexType>
<xs:all>
@@ -85,7 +93,7 @@
<xs:element name="type" type="xs:integer"/>
<xs:element name="strength" type="xs:integer"/>
<xs:element name="data" type="xs:integer"/>
<xs:element name="use-flag" type="xs:integer" minOccurs="0"/>
<xs:element name="use-flag" type="useFlag" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@@ -33,6 +33,8 @@
<xs:enumeration value="magic"/>
<xs:enumeration value="plant"/>
<xs:enumeration value="bird"/>
<xs:enumeration value="goblin"/>
<xs:enumeration value="skeletal"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="permille">

View File

@@ -164,8 +164,4 @@
For example, this states that the fourth graphic is an item. -->
<graphics><pic index='3'>7</pic></graphics>
</editor>
<!-- All the scenario strings go here -->
<strings/>
<!-- And the journal strings here -->
<journal/>
</scenario>

View File

@@ -293,6 +293,8 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="journal" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -356,20 +358,6 @@
<xs:element ref="creator"/>
<xs:element ref="game"/>
<xs:element ref="editor"/>
<xs:element name="strings">
<xs:complexType>
<xs:sequence>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="journal">
<xs:complexType>
<xs:sequence>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="boes" type="xs:string"/>
</xs:complexType>

View File

@@ -109,6 +109,15 @@
<xs:enumeration value="city"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="stepSound">
<xs:restriction base="xs:token">
<xs:enumeration value="step"/>
<xs:enumeration value="crunch"/>
<xs:enumeration value="squish"/>
<xs:enumeration value="splash"/>
<xs:enumeration value="none"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="editor">
<xs:complexType>
<xs:all>
@@ -147,7 +156,7 @@
<xs:element name="boat" minOccurs="0" type="bool"/>
<xs:element name="ride" minOccurs="0" type="bool"/>
<xs:element name="light" minOccurs="0" type="xs:integer"/>
<xs:element name="step-sound" minOccurs="0" type="xs:integer"/>
<xs:element name="step-sound" minOccurs="0" type="stepSound"/>
<xs:element name="trim" type="terTrim"/>
<xs:element name="arena" type="xs:integer"/>
<xs:element ref="editor" minOccurs="0"/>

View File

@@ -113,7 +113,7 @@
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="wandering" minOccurs="0">
<xs:element name="wandering" minOccurs="0" maxOccurs="4">
<xs:complexType>
<xs:sequence>
<xs:element name="monster" maxOccurs="4">

48
rsrc/boes/validate-scen.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
function invalid {
echo "$1 is not a valid Blades of Exile scenario."
echo $2
rm "$1.temp"
exit 1
}
BOE_SCHEMAS_DIR=${BOE_SCHEMAS_DIR:-`git rev-parse --show-toplevel`/rsrc/boes}
if [[ -d $1 ]]; then
SCEN_PATH=$1
elif [[ -f $1 ]]; then
gzip -S .boes -dck "$1" > "$1.temp"
if [[ $? > 0 ]]; then invalid "$1" "(Not valid GZIP data.)"; fi
tar -xf "$1.temp"
if [[ $? > 0 ]]; then invalid "$1" "(Not valid TAR archive.)"; fi
rm "$1.temp"
SCEN_PATH=scenario
else invalid "$1" "(Not a file or directory.)"; fi
function check-file {
xmllint --nonet --noout --schema "$BOE_SCHEMAS_DIR/$1.xsd" "$2"
}
check-file scenario "$SCEN_PATH/scenario.xml"
check-file terrain "$SCEN_PATH/terrain.xml"
check-file items "$SCEN_PATH/items.xml"
check-file monsters "$SCEN_PATH/monsters.xml"
shopt -s nullglob
for sector in $SCEN_PATH/out/out*.xml; do
check-file outdoor "$sector"
done
for town in $SCEN_PATH/towns/town*.xml; do
check-file town "$town"
done
for speech in $SCEN_PATH/towns/talk*.xml; do
check-file dialogue "$speech"
done
if [[ $SCEN_PATH = scenario ]]; then
rm -rf scenario
fi

View File

@@ -48,7 +48,7 @@ template<> inline void ticpp::Printer::PushAttribute(std::string attrName, bool
}
template<> inline void ticpp::Printer::PushElement(std::string attrName, bool attrVal) {
PushAttribute(attrName, attrVal ? "true" : "false");
PushElement(attrName, attrVal ? "true" : "false");
}
template<> inline void ticpp::Printer::PushText(bool textVal) {

View File

@@ -291,6 +291,10 @@ static void writeScenarioToXml(ticpp::Printer&& data) {
data.CloseElement("timer");
}
}
for(size_t i = 0; i < scenario.spec_strs.size(); i++)
data.PushElement("string", scenario.spec_strs[i]);
for(size_t i = 0; i < scenario.journal_strs.size(); i++)
data.PushElement("journal", scenario.journal_strs[i]);
data.CloseElement("game");
data.OpenElement("editor");
data.PushElement("default-ground", scenario.default_ground);
@@ -325,14 +329,6 @@ static void writeScenarioToXml(ticpp::Printer&& data) {
}
}
data.CloseElement("editor");
data.OpenElement("strings");
for(size_t i = 0; i < scenario.spec_strs.size(); i++)
data.PushElement("string", scenario.spec_strs[i]);
data.CloseElement("strings");
data.OpenElement("journal");
for(size_t i = 0; i < scenario.journal_strs.size(); i++)
data.PushElement("string", scenario.journal_strs[i]);
data.CloseElement("journal");
data.CloseElement("scenario");
}
@@ -934,7 +930,7 @@ void save_scenario(fs::path toFile) {
// And finally, the towns.
for(size_t i = 0; i < scenario.towns.size(); i++) {
std::string file_basename = 't' + std::to_string(i);
std::string file_basename = "town" + std::to_string(i);
// First the main data.
std::ostream& town = scen_file.newFile("scenario/towns/" + file_basename + ".xml");
writeTownToXml(ticpp::Printer(file_basename + ".xml", town), *scenario.towns[i]);