void EventManager::loadEvent(FileParser &infile, Event* evnt) { if (!evnt) return; // @CLASS EventManager|Description of events in maps/ and npcs/ if (infile.key == "type") { // @ATTR event.type|[on_trigger:on_mapexit:on_leave:on_load:on_clear]|Type of map event. std::string type = infile.val; evnt->type = type; if (type == "on_trigger"); else if (type == "on_mapexit"); // no need to set keep_after_trigger to false correctly, it's ignored anyway else if (type == "on_leave"); else if (type == "on_load") { evnt->keep_after_trigger = false; } else if (type == "on_clear") { evnt->keep_after_trigger = false; } else { infile.error("EventManager: Event type '%s' unknown, change to \"on_trigger\" to suppress this warning.", type.c_str()); } } else if (infile.key == "location") { // @ATTR event.location|[x,y,w,h]|Defines the location area for the event. evnt->location.x = toInt(infile.nextValue()); evnt->location.y = toInt(infile.nextValue()); evnt->location.w = toInt(infile.nextValue()); evnt->location.h = toInt(infile.nextValue()); if (evnt->center.x == -1 && evnt->center.y == -1) { evnt->center.x = static_cast<float>(evnt->location.x) + static_cast<float>(evnt->location.w)/2; evnt->center.y = static_cast<float>(evnt->location.y) + static_cast<float>(evnt->location.h)/2; } } else if (infile.key == "hotspot") { // @ATTR event.hotspot|[ [x, y, w, h] : location ]|Event uses location as hotspot or defined by rect. if (infile.val == "location") { evnt->hotspot.x = evnt->location.x; evnt->hotspot.y = evnt->location.y; evnt->hotspot.w = evnt->location.w; evnt->hotspot.h = evnt->location.h; } else { evnt->hotspot.x = toInt(infile.nextValue()); evnt->hotspot.y = toInt(infile.nextValue()); evnt->hotspot.w = toInt(infile.nextValue()); evnt->hotspot.h = toInt(infile.nextValue()); } evnt->center.x = static_cast<float>(evnt->hotspot.x) + static_cast<float>(evnt->hotspot.w)/2; evnt->center.y = static_cast<float>(evnt->hotspot.y) + static_cast<float>(evnt->hotspot.h)/2; } else if (infile.key == "cooldown") { // @ATTR event.cooldown|duration|Duration for event cooldown in 'ms' or 's'. evnt->cooldown = parse_duration(infile.val); } else if (infile.key == "reachable_from") { // @ATTR event.reachable_from|[x,y,w,h]|If the hero is inside this rectangle, they can activate the event. evnt->reachable_from.x = toInt(infile.nextValue()); evnt->reachable_from.y = toInt(infile.nextValue()); evnt->reachable_from.w = toInt(infile.nextValue()); evnt->reachable_from.h = toInt(infile.nextValue()); } else { loadEventComponent(infile, evnt, NULL); } }
void EventManager::loadEvent(FileParser &infile, Event* evnt) { if (!evnt) return; // @CLASS EventManager|Description of events in maps/ and npcs/ if (infile.key == "type") { // @ATTR event.type|string|(IGNORED BY ENGINE) The "type" field, as used by Tiled and other mapping tools. evnt->type = infile.val; } else if (infile.key == "activate") { // @ATTR event.activate|["on_trigger", "on_load", "on_leave", "on_mapexit", "on_clear", "static"]|Set the state in which the event will be activated (map events only). if (infile.val == "on_trigger") { evnt->activate_type = EVENT_ON_TRIGGER; } else if (infile.val == "on_mapexit") { // no need to set keep_after_trigger to false correctly, it's ignored anyway evnt->activate_type = EVENT_ON_MAPEXIT; } else if (infile.val == "on_leave") { evnt->activate_type = EVENT_ON_LEAVE; } else if (infile.val == "on_load") { evnt->activate_type = EVENT_ON_LOAD; evnt->keep_after_trigger = false; } else if (infile.val == "on_clear") { evnt->activate_type = EVENT_ON_CLEAR; evnt->keep_after_trigger = false; } else if (infile.val == "static") { evnt->activate_type = EVENT_STATIC; } else { infile.error("EventManager: Event activation type '%s' unknown, change to \"on_trigger\" to suppress this warning.", infile.val.c_str()); } } else if (infile.key == "location") { // @ATTR event.location|rectangle|Defines the location area for the event. evnt->location.x = popFirstInt(infile.val); evnt->location.y = popFirstInt(infile.val); evnt->location.w = popFirstInt(infile.val); evnt->location.h = popFirstInt(infile.val); if (evnt->center.x == -1 && evnt->center.y == -1) { evnt->center.x = static_cast<float>(evnt->location.x) + static_cast<float>(evnt->location.w)/2; evnt->center.y = static_cast<float>(evnt->location.y) + static_cast<float>(evnt->location.h)/2; } } else if (infile.key == "hotspot") { // @ATTR event.hotspot|["location", rectangle]|Event uses location as hotspot or defined by rect. if (infile.val == "location") { evnt->hotspot.x = evnt->location.x; evnt->hotspot.y = evnt->location.y; evnt->hotspot.w = evnt->location.w; evnt->hotspot.h = evnt->location.h; } else { evnt->hotspot.x = popFirstInt(infile.val); evnt->hotspot.y = popFirstInt(infile.val); evnt->hotspot.w = popFirstInt(infile.val); evnt->hotspot.h = popFirstInt(infile.val); } evnt->center.x = static_cast<float>(evnt->hotspot.x) + static_cast<float>(evnt->hotspot.w)/2; evnt->center.y = static_cast<float>(evnt->hotspot.y) + static_cast<float>(evnt->hotspot.h)/2; } else if (infile.key == "cooldown") { // @ATTR event.cooldown|duration|Duration for event cooldown in 'ms' or 's'. evnt->cooldown = parse_duration(infile.val); } else if (infile.key == "delay") { // @ATTR event.delay|duration|Event will execute after a specified duration. evnt->delay = parse_duration(infile.val); } else if (infile.key == "reachable_from") { // @ATTR event.reachable_from|rectangle|If the hero is inside this rectangle, they can activate the event. evnt->reachable_from.x = popFirstInt(infile.val); evnt->reachable_from.y = popFirstInt(infile.val); evnt->reachable_from.w = popFirstInt(infile.val); evnt->reachable_from.h = popFirstInt(infile.val); } else { loadEventComponent(infile, evnt, NULL); } }