void widget::set_value(const std::string& key, const variant& v) { if(key == "width") { w_ = v.as_int(); } else if(key == "height") { h_ = v.as_int(); } else if(key == "rect" || key == "draw_area") { std::vector<int> r = v.as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } else if(key == "xy" || key == "left_top") { std::vector<int> xy = v.as_list_int(); ASSERT_LOG(xy.size() == 2, "Two values must be supplied to the X, Y attribute"); set_loc(xy[0], xy[1]); } else if(key == "wh") { std::vector<int> wh = v.as_list_int(); ASSERT_LOG(wh.size() == 2, "Two values must be supplied to the W, H attribute"); set_dim(wh[0], wh[1]); } else if(key == "right_bottom") { std::vector<int> rb = v.as_list_int(); ASSERT_LOG(rb.size() == 2, "Two values must be supplied to the R, B attribute"); set_dim(rb[0] - x(), rb[1] - y()); } else if(key == "left") { x_ = v.as_int(); } else if(key == "top") { y_ = v.as_int(); } else if(key == "right") { w_ = v.as_int() - x(); } else if(key == "bottom") { h_ = v.as_int() - y(); } else if(key == "visible") { visible_ = v.as_bool(); } else if(key == "id") { id_ = v.as_string(); } else if(key == "disable") { disabled_ = v.as_bool(); } else if(key == "enable") { disabled_ = !v.as_bool(); } else if(key == "disabled_opacity") { int opa = v.as_int(); disabled_opacity_ = (opa > 255) ? 255 : (opa < 0) ? 0 : opa; } }
void playable_custom_object::set_player_value_by_slot(int slot, const variant& value) { switch(slot) { case CUSTOM_OBJECT_PLAYER_DIFFICULTY: difficulty_ = value.as_int(); break; case CUSTOM_OBJECT_PLAYER_CAN_INTERACT: can_interact_ = value.as_int(); break; case CUSTOM_OBJECT_PLAYER_UNDERWATER_CONTROLS: underwater_controls_ = value.as_bool(); break; case CUSTOM_OBJECT_PLAYER_VERTICAL_LOOK: vertical_look_ = value.as_int(); break; case CUSTOM_OBJECT_PLAYER_CONTROL_LOCK: if(value.is_null()) { control_lock_.reset(); } else if(value.is_list()) { unsigned char state = 0; for(int n = 0; n != value.num_elements(); ++n) { ASSERT_LOG(value[n].is_string(), "MEMBER OF control_lock LIST NOT A STRING"); const std::string& str = value[n].as_string(); int control_key = -1; for(int m = 0; m != sizeof(ctrl)/sizeof(*ctrl); ++m) { if(ctrl[m] == str) { control_key = m; break; } } ASSERT_LOG(control_key != -1, "ILLEGAL STRING SET FOR control_lock: '" << str << "' LEGAL KEYS ARE ctrl_(up|down|left|right|attack|jump)"); state |= 1 << control_key; } //destroy the old one before creating a new control_lock, //since control_lock objects must be constructed and destroyed //in FIFO order. control_lock_.reset(); control_lock_.reset(new controls::local_controls_lock(state)); } else { ASSERT_LOG(false, "BAD VALUE WHEN SETTING control_lock KEY. A LIST OR NULL IS REQUIRED: " << value.to_debug_string()); } break; } }
variant operator ! ( const variant& a ) { return !a.as_bool(); }
static void variant_to_value(const variant &var, bool &value) { value = var.as_bool(); }
void from_variant( const variant& var, bool& vo ) { vo = var.as_bool(); }