A few more scenario read tests
- Introduce enum for scenario content rating
This commit is contained in:
@@ -1398,7 +1398,6 @@ void tip_of_day() {
|
||||
static void put_scen_info(cDialog& me) {
|
||||
unsigned int i;
|
||||
std::ostringstream sout;
|
||||
const char *ratings[] = {"G","PG","R","NC-17"};
|
||||
const char *difficulty[] = {"Low","Medium","High","Very High"};
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
@@ -1415,7 +1414,7 @@ static void put_scen_info(cDialog& me) {
|
||||
sout << '.' << int(scen_headers[store_scen_page_on * 3 + i].ver[1]);
|
||||
sout << '.' << int(scen_headers[store_scen_page_on * 3 + i].ver[2]);
|
||||
sout << " - | Difficulty: " << difficulty[scen_headers[store_scen_page_on * 3 + i].difficulty];
|
||||
sout << ", Rating: " << ratings[scen_headers[store_scen_page_on * 3 + i].rating];
|
||||
sout << ", Rating: " << scen_headers[store_scen_page_on * 3 + i].rating;
|
||||
sout << " |" << scen_headers[store_scen_page_on * 3 + i].who1;
|
||||
sout << " |" << scen_headers[store_scen_page_on * 3 + i].who2;
|
||||
me["desc" + n].setText(sout.str());
|
||||
|
@@ -631,3 +631,18 @@ std::istream& operator>> (std::istream& in, eAttitude& att) {
|
||||
in.setstate(std::ios::failbit);
|
||||
return in;
|
||||
}
|
||||
|
||||
// MARK: eContentRating
|
||||
|
||||
cEnumLookup rating_strs = {"G", "PG", "R", "NC-17"};
|
||||
|
||||
std::ostream& operator<< (std::ostream& out, eContentRating rating) {
|
||||
writeEnum(out, rating, rating_strs, "docile");
|
||||
return out;
|
||||
}
|
||||
|
||||
std::istream& operator>> (std::istream& in, eContentRating& rating) {
|
||||
if(!readEnum(in, rating, rating_strs, eContentRating::G))
|
||||
in.setstate(std::ios::failbit);
|
||||
return in;
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ cScenario::cScenario() {
|
||||
where_start.x = 24;
|
||||
where_start.y = 24;
|
||||
out_start = where_start;
|
||||
rating = 0;
|
||||
rating = eContentRating::G;
|
||||
difficulty = 0;
|
||||
intro_pic = intro_mess_pic = 0;
|
||||
adjust_diff = true;
|
||||
@@ -133,7 +133,7 @@ void cScenario::append(legacy::scenario_data_type& old){
|
||||
special_items[i].flags = old.special_items[i];
|
||||
special_items[i].special = old.special_item_special[i];
|
||||
}
|
||||
rating = old.rating;
|
||||
rating = eContentRating(old.rating);
|
||||
// TODO: Is this used anywhere?
|
||||
uses_custom_graphics = old.uses_custom_graphics;
|
||||
for(i = 0; i < 30; i++) {
|
||||
|
@@ -72,7 +72,8 @@ public:
|
||||
std::vector<cSpecItem> special_items;
|
||||
std::vector<cQuest> quests;
|
||||
std::vector<cShop> shops;
|
||||
short rating,uses_custom_graphics;
|
||||
short uses_custom_graphics;
|
||||
eContentRating rating;
|
||||
std::vector<ePicType> custom_graphics;
|
||||
std::vector<cMonster> scen_monsters;
|
||||
std::array<cVehicle,30> boats;
|
||||
@@ -122,4 +123,7 @@ public:
|
||||
~cScenario();
|
||||
};
|
||||
|
||||
std::istream& operator>> (std::istream& in, eContentRating& rating);
|
||||
std::ostream& operator<< (std::ostream& out, eContentRating rating);
|
||||
|
||||
#endif
|
||||
|
@@ -38,6 +38,8 @@ inline eDirection& operator++ (eDirection& me, int) {
|
||||
else return me = (eDirection)(1 + (int)me);
|
||||
}
|
||||
|
||||
enum eContentRating {G, PG, R, NC17};
|
||||
|
||||
enum class eQuestStatus {AVAILABLE, STARTED, COMPLETED, FAILED};
|
||||
|
||||
enum class eMainStatus {
|
||||
|
@@ -138,12 +138,7 @@ void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
}
|
||||
data.CloseElement("text");
|
||||
data.OpenElement("ratings");
|
||||
switch(scenario.rating) {
|
||||
case 0: data.PushElement("content", "g"); break;
|
||||
case 1: data.PushElement("content", "pg"); break;
|
||||
case 2: data.PushElement("content", "r"); break;
|
||||
case 3: data.PushElement("content", "nc17"); break;
|
||||
}
|
||||
data.PushElement("content", scenario.rating);
|
||||
data.PushElement("difficulty", scenario.difficulty + 1);
|
||||
data.CloseElement("ratings");
|
||||
data.OpenElement("flags");
|
||||
|
@@ -653,6 +653,7 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
|
||||
} else if(type == "icon") {
|
||||
// TODO: This element can have some attributes on it.
|
||||
elem->GetText(&scenario.intro_pic);
|
||||
scenario.intro_mess_pic = scenario.intro_pic;
|
||||
} else if(type == "id") {
|
||||
elem->GetText(&scenario.campaign_id, false);
|
||||
} else if(type == "version") {
|
||||
@@ -689,12 +690,7 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
|
||||
} else if(type == "ratings") {
|
||||
Element* content = elem->FirstChildElement("content");
|
||||
Element* difficulty = elem->FirstChildElement("difficulty");
|
||||
content->GetText(&val);
|
||||
if(val == "g") scenario.rating = 0;
|
||||
else if(val == "pg") scenario.rating = 1;
|
||||
else if(val == "r") scenario.rating = 2;
|
||||
else if(val == "nc17") scenario.rating = 3;
|
||||
else throw xBadVal("content", xBadVal::CONTENT, val, content->Row(), content->Column(), fname);
|
||||
content->GetText(&scenario.rating);
|
||||
difficulty->GetText(&scenario.difficulty);
|
||||
if(scenario.difficulty < 1 || scenario.difficulty > 4)
|
||||
throw xBadVal("difficulty", xBadVal::CONTENT, std::to_string(scenario.difficulty), difficulty->Row(),difficulty->Column(), fname);
|
||||
|
Reference in New Issue
Block a user