Move special node category into the node properties struct

This commit is contained in:
2017-04-14 00:40:05 -04:00
parent 791c2a27d4
commit e98f9381fe
5 changed files with 12 additions and 10 deletions

View File

@@ -121,7 +121,7 @@ static void init_specials_parse() {
using underlying = unsigned short;
for(underlying i = 1; i < std::numeric_limits<underlying>::max(); i++) {
eSpecType check = (eSpecType) i;
eSpecCat category = getNodeCategory(check);
eSpecCat category = (*check).cat;
if(category == eSpecCat::INVALID) continue;
if((*check).opcode().empty())
warn_missing_opcode(i);

View File

@@ -2059,7 +2059,7 @@ void run_special(eSpecCtx which_mode,short which_type,short start_spec,location
special_in_progress = false;
return;
}
switch(getNodeCategory(cur_node.type)) {
switch((*cur_node.type).cat) {
case eSpecCat::GENERAL:
if(cur_node.type == eSpecType::NONE && univ.debug_mode) {
std::string type("???");

View File

@@ -656,7 +656,7 @@ static int offsets[] = {
int(eSpecType::OUT_MAKE_WANDER),
};
eSpecCat getNodeCategory(eSpecType node) {
static eSpecCat getNodeCategory(eSpecType node) {
int code = (int) node;
if(code >= 0 && code <= 47)
return eSpecCat::GENERAL;
@@ -688,6 +688,7 @@ static std::map<eSpecType, node_properties_t> loadProps() {
if(category == eSpecCat::INVALID) continue;
node_properties_t props;
props.self = check;
props.cat = category;
int j = int(category), k = i - offsets[j];
props.m1_btn = button_dict[j][0][k];
props.m2_btn = button_dict[j][1][k];
@@ -716,8 +717,10 @@ static std::map<eSpecType, node_properties_t> loadProps() {
}
const node_properties_t& operator* (eSpecType t) {
static node_properties_t invalid;
static std::map<eSpecType, node_properties_t> allNodeProps = loadProps();
return allNodeProps.at(t);
auto iter = allNodeProps.find(t);
return iter == allNodeProps.end() ? invalid : iter->second;
}
std::string node_properties_t::opcode() const {

View File

@@ -120,6 +120,7 @@ enum class eSpecCat {
struct node_properties_t {
eSpecType self;
eSpecCat cat;
std::string opcode() const;
std::string name() const, descr() const;
std::string sdf1_lbl() const, sdf2_lbl() const, sdf1_hlp() const, sdf2_hlp() const;
@@ -130,11 +131,10 @@ struct node_properties_t {
std::string jmp_lbl() const, jmp_hlp() const;
char sd1_btn, sd2_btn, m1_btn, m2_btn, m3_btn, p_btn, pt_btn;
char x1a_btn, x1b_btn, x1c_btn, x2a_btn, x2b_btn, x2c_btn;
node_properties_t() {}
node_properties_t() : self(eSpecType::INVALID), cat(eSpecCat::INVALID) {}
node_properties_t(std::initializer_list<std::function<void(node_properties_t)>>);
};
const node_properties_t& operator* (eSpecType t);
eSpecCat getNodeCategory(eSpecType node);
#endif

View File

@@ -657,12 +657,11 @@ static bool edit_spec_enc_type(cDialog& me, std::string item_hit, node_stack_t&
else if(item_hit == "rect") category = eSpecCat::RECT;
int start = -1, finish = -1, current = int(edit_stack.top().node.type);
for(int i = 0; i < std::numeric_limits<unsigned short>::max(); i++) {
eSpecType check = eSpecType(i);
eSpecCat checkCat = getNodeCategory(check);
if(start >= 0 && checkCat == eSpecCat::INVALID) {
eSpecCat check = (*eSpecType(i)).cat;
if(start >= 0 && check == eSpecCat::INVALID) {
finish = i - 1;
break;
} else if(checkCat == category && start < 0)
} else if(check == category && start < 0)
start = i;
}
if(start < 0 || finish < 0) return true;