Store custom graphics classifications as symbols instead of integers
This commit is contained in:
@@ -10,6 +10,24 @@
|
||||
</xs:simpleType>
|
||||
</xs:union>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="picClass">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="terrain"/>
|
||||
<xs:enumeration value="terrain-anim"/>
|
||||
<xs:enumeration value="terrain-map"/
|
||||
<xs:enumeration value="monster-small"/>
|
||||
<xs:enumeration value="monster-wide"/>
|
||||
<xs:enumeration value="monster-tall"/>
|
||||
<xs:enumeration value="monster-large"/>
|
||||
<xs:enumeration value="dialog"/>
|
||||
<xs:enumeration value="dialog-large"/>
|
||||
<xs:enumeration value="talk"/>
|
||||
<xs:enumeration value="item"/>
|
||||
<xs:enumeration value="boom"/>
|
||||
<xs:enumeration value="missile"/>
|
||||
<xs:enumeration value="none"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:complexType mixed="true" name="scenIcon">
|
||||
<xs:attribute name="custom" type="bool" default="false"/>
|
||||
<xs:attribute name="split" type="bool" default="false"/>
|
||||
@@ -252,7 +270,7 @@
|
||||
<xs:element name="string" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:extension base="picClass">
|
||||
<xs:attribute name="id" type="xs:integer" use="required"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
|
||||
@@ -575,7 +575,7 @@ std::string cPict::parse(ticpp::Element& who, std::string fname) {
|
||||
void cPict::recalcRect() {
|
||||
rectangle bounds = getBounds();
|
||||
switch(picType) {
|
||||
case NUM_PIC_TYPES: break;
|
||||
case NUM_PIC_TYPES: case PIC_NONE: break;
|
||||
case PIC_TER: case PIC_CUSTOM_TER:
|
||||
case PIC_TER_ANIM: case PIC_CUSTOM_TER_ANIM:
|
||||
case PIC_MONST: case PIC_CUSTOM_MONST: case PIC_PARTY_MONST:
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
/// Specifies an icon type.
|
||||
enum ePicType {
|
||||
PIC_NONE = 0, ///< Mostly unused, means just show a black square
|
||||
PIC_TER = 1, ///< 28x36 terrain graphic from the preset sheets
|
||||
PIC_TER_ANIM = 2, ///< 28x36 terrain graphic from the preset animated terrain sheet
|
||||
PIC_MONST = 3, ///< 28x36 monster graphic from the preset sheets
|
||||
@@ -137,4 +138,7 @@ ePicType&operator -=(ePicType&lhs, ePicTypeMod rhs);
|
||||
/// @return true if the modifier is present.
|
||||
bool operator& (ePicType lhs, ePicTypeMod rhs);
|
||||
|
||||
std::ostream& operator<< (std::ostream& out, ePicType pic);
|
||||
std::istream& operator>> (std::istream& in, ePicType& pic);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -705,3 +705,26 @@ std::istream& operator>> (std::istream& in, eSpellPat& pat) {
|
||||
in.setstate(std::ios::failbit);
|
||||
return in;
|
||||
}
|
||||
|
||||
// MARK: ePicType
|
||||
|
||||
cEnumLookup pic_type_strs = {
|
||||
"none", "terrain", "terrain-anim", "monster-small", "dialog", "talk", "scenario", "item", "player", "field",
|
||||
"boom", "sheet", "missile", "dialog-large", "scenario-large", "terrain-map", "status", "item-small", "", "",
|
||||
"", "", "", "monster-wide", "", "", "", "", "", "",
|
||||
"", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "monster-tall", "", "", "", "", "", "",
|
||||
"", "", "", "", "", "", "", "", "", "",
|
||||
"", "", "", "monster-large",
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& out, ePicType pic) {
|
||||
writeEnum(out, pic, pic_type_strs, "none");
|
||||
return out;
|
||||
}
|
||||
|
||||
std::istream& operator>> (std::istream& in, ePicType& pic) {
|
||||
if(!readEnum(in, pic, pic_type_strs, PIC_NONE))
|
||||
in.setstate(std::ios::failbit);
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -881,30 +881,38 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
|
||||
scenario.snd_names.resize(sndnum + 1);
|
||||
edit->GetText(&scenario.snd_names[sndnum], false);
|
||||
} else if(type == "graphics") {
|
||||
static const std::set<int> valid_pictypes = {1,2,3,4,5,7,10,11,12,13,15,16,23,43,63};
|
||||
static const std::set<ePicType> valid_pictypes = {
|
||||
PIC_TER, PIC_TER_ANIM, PIC_TER_MAP,
|
||||
PIC_MONST, PIC_MONST_WIDE, PIC_MONST_TALL, PIC_MONST_LG,
|
||||
PIC_DLOG, PIC_DLOG_LG, PIC_ITEM,
|
||||
PIC_TALK, PIC_BOOM, PIC_MISSILE, PIC_NONE
|
||||
};
|
||||
if(num_pics > 0)
|
||||
throw xBadNode(type, edit->Row(), edit->Column(), fname);
|
||||
scenario.custom_graphics.clear();
|
||||
Iterator<Element> pic;
|
||||
for(pic = pic.begin(edit.Get()); pic != pic.end(); pic++) {
|
||||
pic->GetValue(&type);
|
||||
if(type != "pic")
|
||||
throw xBadNode(type, pic->Row(), pic->Column(), fname);
|
||||
int i = -1, pictype;
|
||||
int i = -1;
|
||||
ePicType pictype;
|
||||
pic->GetText(&pictype);
|
||||
if(pictype == 0) continue; // As a special case, treat 0 as equivalent to 11 (ie, unclassified)
|
||||
if(pictype == PIC_FULL) pictype = PIC_NONE; // As a special case, treat FULL as equivalent to NONE
|
||||
if(pictype == PIC_NONE) continue;
|
||||
for(attr = attr.begin(pic.Get()); attr != attr.end(); attr++) {
|
||||
attr->GetName(&name);
|
||||
if(name != "index")
|
||||
throw xBadAttr(type, name, attr->Row(), attr->Column(), fname);
|
||||
attr->GetValue(&i);
|
||||
if(i >= scenario.custom_graphics.size())
|
||||
scenario.custom_graphics.resize(i + 1);
|
||||
scenario.custom_graphics.resize(i + 1, PIC_FULL);
|
||||
}
|
||||
if(i < 0)
|
||||
throw xMissingAttr(type, "index", pic->Row(), pic->Column(), fname);
|
||||
if(!valid_pictypes.count(pictype))
|
||||
throw xBadVal(type, xBadVal::CONTENT, std::to_string(pictype), pic->Row(), pic->Column(), fname);
|
||||
scenario.custom_graphics[i] = ePicType(pictype);
|
||||
throw xBadVal(type, xBadVal::CONTENT, pic->GetText(), pic->Row(), pic->Column(), fname);
|
||||
scenario.custom_graphics[i] = pictype;
|
||||
num_pics++;
|
||||
}
|
||||
} else if(type == "storage") {
|
||||
|
||||
@@ -3152,7 +3152,7 @@ void edit_scenario_events() {
|
||||
|
||||
static void fill_custom_pics_types(cDialog& me, std::vector<ePicType>& pics, pic_num_t first) {
|
||||
pic_num_t last = first + 9;
|
||||
if(last >= pics.size()) pics.resize(last + 1, PIC_FULL);
|
||||
if(last >= pics.size()) pics.resize(last + 1, PIC_NONE);
|
||||
me["num0"].setTextToNum(first);
|
||||
for(pic_num_t i = first; i <= last; i++) {
|
||||
std::string id = std::to_string(i - first + 1);
|
||||
@@ -3209,8 +3209,8 @@ static void fill_custom_pics_types(cDialog& me, std::vector<ePicType>& pics, pic
|
||||
case PIC_STATUS: // Not currently supported, but reserve for later
|
||||
break;
|
||||
default: // Fix any potential errors
|
||||
pics[i] = PIC_FULL;
|
||||
case PIC_FULL:
|
||||
pics[i] = PIC_NONE;
|
||||
case PIC_NONE:
|
||||
grp.setSelected("none" + id);
|
||||
break;
|
||||
}
|
||||
@@ -3256,7 +3256,7 @@ static bool set_custom_pic_type(cDialog& me, std::string hit, std::vector<ePicTy
|
||||
} else if(hit == "miss") {
|
||||
pics[pic] = PIC_MISSILE;
|
||||
} else if(hit == "none") {
|
||||
pics[pic] = PIC_FULL;
|
||||
pics[pic] = PIC_NONE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user