mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-10-04 16:50:40 +00:00
specialized exceptions for param errors
This commit is contained in:
parent
888a34dea6
commit
f445d02707
20
config.cpp
20
config.cpp
@ -28,6 +28,12 @@ EX void non_editable_reaction() {
|
|||||||
|
|
||||||
#if HDR
|
#if HDR
|
||||||
|
|
||||||
|
struct param_exception : hr_exception {
|
||||||
|
struct parameter *which;
|
||||||
|
param_exception() : hr_exception("param_exception"), which(nullptr) {}
|
||||||
|
param_exception(const std::string &s, parameter *p) : hr_exception(s), which(p) {}
|
||||||
|
};
|
||||||
|
|
||||||
struct parameter_names {
|
struct parameter_names {
|
||||||
string name;
|
string name;
|
||||||
string legacy_config_name;
|
string legacy_config_name;
|
||||||
@ -73,8 +79,8 @@ struct parameter : public std::enable_shared_from_this<parameter> {
|
|||||||
}
|
}
|
||||||
virtual bool anim_unchanged() { return true; }
|
virtual bool anim_unchanged() { return true; }
|
||||||
virtual void anim_restore() { }
|
virtual void anim_restore() { }
|
||||||
virtual cld get_cld() { throw hr_exception("parameter has no complex value"); }
|
virtual cld get_cld() { throw param_exception("parameter has no complex value", this); }
|
||||||
virtual void set_cld_raw(cld x) { throw hr_exception("parameter has no complex value"); }
|
virtual void set_cld_raw(cld x) { throw param_exception("parameter has no complex value", this); }
|
||||||
virtual void set_cld(cld value) {
|
virtual void set_cld(cld value) {
|
||||||
auto bak = get_cld();
|
auto bak = get_cld();
|
||||||
set_cld_raw(value);
|
set_cld_raw(value);
|
||||||
@ -83,14 +89,13 @@ struct parameter : public std::enable_shared_from_this<parameter> {
|
|||||||
|
|
||||||
virtual string save() = 0;
|
virtual string save() = 0;
|
||||||
virtual void load(const string& s) {
|
virtual void load(const string& s) {
|
||||||
println(hlog, "cannot load parameter: ", name, " from: ", s);
|
throw param_exception("parameter cannot be loaded", this);
|
||||||
throw hr_exception("parameter cannot be loaded");
|
|
||||||
}
|
}
|
||||||
virtual bool dosave() = 0;
|
virtual bool dosave() = 0;
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
virtual void swap_with(parameter*) = 0;
|
virtual void swap_with(parameter*) = 0;
|
||||||
|
|
||||||
virtual shared_ptr<parameter> clone(struct local_parameter_set& lps, void *value) { println(hlog, "parameter not cloneable: ", name); throw hr_exception("not cloneable"); }
|
virtual shared_ptr<parameter> clone(struct local_parameter_set& lps, void *value) { throw param_exception("not cloneable", this); }
|
||||||
|
|
||||||
void setup(const parameter_names& s);
|
void setup(const parameter_names& s);
|
||||||
};
|
};
|
||||||
@ -215,7 +220,7 @@ template<class T> struct val_parameter : public parameter {
|
|||||||
bool anim_unchanged() override { return *value == anim_value; }
|
bool anim_unchanged() override { return *value == anim_value; }
|
||||||
void anim_restore() override { *value = anim_value; if(reaction) reaction(); }
|
void anim_restore() override { *value = anim_value; if(reaction) reaction(); }
|
||||||
|
|
||||||
virtual void load_from_raw(const string& s) { throw hr_exception("load_from_raw not defined"); }
|
virtual void load_from_raw(const string& s) { throw param_exception("load_from_raw not defined", this); }
|
||||||
|
|
||||||
void load(const string& s) override {
|
void load(const string& s) override {
|
||||||
auto bak = *value;
|
auto bak = *value;
|
||||||
@ -423,8 +428,7 @@ struct custom_parameter : public parameter {
|
|||||||
}
|
}
|
||||||
virtual void load_from_raw(const string& s) {
|
virtual void load_from_raw(const string& s) {
|
||||||
if(!custom_load) {
|
if(!custom_load) {
|
||||||
println(hlog, "cannot load parameter: ", name, " from: ", s);
|
throw param_exception("parameter cannot be loaded", this);
|
||||||
throw hr_exception("parameter cannot be loaded");
|
|
||||||
}
|
}
|
||||||
custom_load(s);
|
custom_load(s);
|
||||||
}
|
}
|
||||||
|
@ -1227,6 +1227,7 @@ EX namespace dialog {
|
|||||||
if(p) p->load_as_animation(formula);
|
if(p) p->load_as_animation(formula);
|
||||||
}
|
}
|
||||||
catch(hr_parse_exception&) { }
|
catch(hr_parse_exception&) { }
|
||||||
|
catch(param_exception&) { }
|
||||||
};
|
};
|
||||||
dialog::get_di().dialogflags |= dialogflags;
|
dialog::get_di().dialogflags |= dialogflags;
|
||||||
});
|
});
|
||||||
@ -1298,6 +1299,7 @@ EX namespace dialog {
|
|||||||
}
|
}
|
||||||
catch(const hr_parse_exception&) {
|
catch(const hr_parse_exception&) {
|
||||||
}
|
}
|
||||||
|
catch(param_exception&) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
EX void bound_low(ld val) {
|
EX void bound_low(ld val) {
|
||||||
|
Loading…
Reference in New Issue
Block a user