Convert event JSON values by type
This commit is contained in:
parent
e2a31336c5
commit
75788ed3f9
2 changed files with 52 additions and 52 deletions
|
@ -38,6 +38,7 @@ void Event::setDefaultValues(Project *) {
|
|||
this->setElevation(3);
|
||||
}
|
||||
|
||||
// TODO: Don't assume string type
|
||||
void Event::readCustomValues(QJsonObject values) {
|
||||
this->customValues.clear();
|
||||
QSet<QString> expectedFields = this->getExpectedFields();
|
||||
|
@ -163,17 +164,17 @@ OrderedJson::object ObjectEvent::buildEventJson(Project *) {
|
|||
}
|
||||
|
||||
bool ObjectEvent::loadFromJson(QJsonObject json, Project *) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setGfx(json["graphics_id"].toString());
|
||||
this->setMovement(json["movement_type"].toString());
|
||||
this->setRadiusX(json["movement_range_x"].toInt());
|
||||
this->setRadiusY(json["movement_range_y"].toInt());
|
||||
this->setTrainerType(json["trainer_type"].toString());
|
||||
this->setSightRadiusBerryTreeID(json["trainer_sight_or_berry_tree_id"].toString());
|
||||
this->setScript(json["script"].toString());
|
||||
this->setFlag(json["flag"].toString());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setGfx(ParseUtil::jsonToQString(json["graphics_id"]));
|
||||
this->setMovement(ParseUtil::jsonToQString(json["movement_type"]));
|
||||
this->setRadiusX(ParseUtil::jsonToInt(json["movement_range_x"]));
|
||||
this->setRadiusY(ParseUtil::jsonToInt(json["movement_range_y"]));
|
||||
this->setTrainerType(ParseUtil::jsonToQString(json["trainer_type"]));
|
||||
this->setSightRadiusBerryTreeID(ParseUtil::jsonToQString(json["trainer_sight_or_berry_tree_id"]));
|
||||
this->setScript(ParseUtil::jsonToQString(json["script"]));
|
||||
this->setFlag(ParseUtil::jsonToQString(json["flag"]));
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
||||
|
@ -220,7 +221,7 @@ void ObjectEvent::loadPixmap(Project *project) {
|
|||
// Invalid gfx constant.
|
||||
// If this is a number, try to use that instead.
|
||||
bool ok;
|
||||
int altGfx = this->gfx.toInt(&ok);
|
||||
int altGfx = ParseUtil::gameStringToInt(this->gfx, &ok);
|
||||
if (ok && (altGfx < project->gfxDefines.count())) {
|
||||
eventGfx = project->eventGraphicsMap.value(project->gfxDefines.key(altGfx, "NULL"), nullptr);
|
||||
}
|
||||
|
@ -311,13 +312,13 @@ OrderedJson::object CloneObjectEvent::buildEventJson(Project *project) {
|
|||
}
|
||||
|
||||
bool CloneObjectEvent::loadFromJson(QJsonObject json, Project *project) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setGfx(json["graphics_id"].toString());
|
||||
this->setTargetID(json["target_local_id"].toInt());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setGfx(ParseUtil::jsonToQString(json["graphics_id"]));
|
||||
this->setTargetID(ParseUtil::jsonToInt(json["target_local_id"]));
|
||||
|
||||
// Ensure the target map constant is valid before adding it to the events.
|
||||
QString mapConstant = json["target_map"].toString();
|
||||
QString mapConstant = ParseUtil::jsonToQString(json["target_map"]);
|
||||
if (project->mapConstantsToMapNames.contains(mapConstant)) {
|
||||
this->setTargetMap(project->mapConstantsToMapNames.value(mapConstant));
|
||||
} else if (mapConstant == NONE_MAP_CONSTANT) {
|
||||
|
@ -421,13 +422,13 @@ OrderedJson::object WarpEvent::buildEventJson(Project *project) {
|
|||
}
|
||||
|
||||
bool WarpEvent::loadFromJson(QJsonObject json, Project *project) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setDestinationWarpID(json["dest_warp_id"].toInt());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setDestinationWarpID(ParseUtil::jsonToInt(json["dest_warp_id"]));
|
||||
|
||||
// Ensure the warp destination map constant is valid before adding it to the warps.
|
||||
QString mapConstant = json["dest_map"].toString();
|
||||
QString mapConstant = ParseUtil::jsonToQString(json["dest_map"]);
|
||||
if (project->mapConstantsToMapNames.contains(mapConstant)) {
|
||||
this->setDestinationMap(project->mapConstantsToMapNames.value(mapConstant));
|
||||
} else if (mapConstant == NONE_MAP_CONSTANT) {
|
||||
|
@ -515,12 +516,12 @@ OrderedJson::object TriggerEvent::buildEventJson(Project *) {
|
|||
}
|
||||
|
||||
bool TriggerEvent::loadFromJson(QJsonObject json, Project *) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setScriptVar(json["var"].toString());
|
||||
this->setScriptVarValue(json["var_value"].toString());
|
||||
this->setScriptLabel(json["script"].toString());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setScriptVar(ParseUtil::jsonToQString(json["var"]));
|
||||
this->setScriptVarValue(ParseUtil::jsonToQString(json["var_value"]));
|
||||
this->setScriptLabel(ParseUtil::jsonToQString(json["script"]));
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
||||
|
@ -589,10 +590,10 @@ OrderedJson::object WeatherTriggerEvent::buildEventJson(Project *) {
|
|||
}
|
||||
|
||||
bool WeatherTriggerEvent::loadFromJson(QJsonObject json, Project *) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setWeather(json["weather"].toString());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setWeather(ParseUtil::jsonToQString(json["weather"]));
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
||||
|
@ -665,11 +666,11 @@ OrderedJson::object SignEvent::buildEventJson(Project *) {
|
|||
}
|
||||
|
||||
bool SignEvent::loadFromJson(QJsonObject json, Project *) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setFacingDirection(json["player_facing_dir"].toString());
|
||||
this->setScriptLabel(json["script"].toString());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setFacingDirection(ParseUtil::jsonToQString(json["player_facing_dir"]));
|
||||
this->setScriptLabel(ParseUtil::jsonToQString(json["script"]));
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
||||
|
@ -746,16 +747,16 @@ OrderedJson::object HiddenItemEvent::buildEventJson(Project *) {
|
|||
}
|
||||
|
||||
bool HiddenItemEvent::loadFromJson(QJsonObject json, Project *) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setItem(json["item"].toString());
|
||||
this->setFlag(json["flag"].toString());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setItem(ParseUtil::jsonToQString(json["item"]));
|
||||
this->setFlag(ParseUtil::jsonToQString(json["flag"]));
|
||||
if (projectConfig.getHiddenItemQuantityEnabled()) {
|
||||
this->setQuantity(json["quantity"].toInt());
|
||||
this->setQuantity(ParseUtil::jsonToInt(json["quantity"]));
|
||||
}
|
||||
if (projectConfig.getHiddenItemRequiresItemfinderEnabled()) {
|
||||
this->setUnderfoot(json["underfoot"].toBool());
|
||||
this->setUnderfoot(ParseUtil::jsonToBool(json["underfoot"]));
|
||||
}
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
@ -834,10 +835,10 @@ OrderedJson::object SecretBaseEvent::buildEventJson(Project *) {
|
|||
}
|
||||
|
||||
bool SecretBaseEvent::loadFromJson(QJsonObject json, Project *) {
|
||||
this->setX(json["x"].toInt());
|
||||
this->setY(json["y"].toInt());
|
||||
this->setElevation(json["elevation"].toInt());
|
||||
this->setBaseID(json["secret_base_id"].toString());
|
||||
this->setX(ParseUtil::jsonToInt(json["x"]));
|
||||
this->setY(ParseUtil::jsonToInt(json["y"]));
|
||||
this->setElevation(ParseUtil::jsonToInt(json["elevation"]));
|
||||
this->setBaseID(ParseUtil::jsonToQString(json["secret_base_id"]));
|
||||
|
||||
this->readCustomValues(json);
|
||||
|
||||
|
|
|
@ -160,7 +160,6 @@ const QSet<QString> defaultTopLevelMapFields = {
|
|||
"bg_events",
|
||||
"shared_events_map",
|
||||
"shared_scripts_map",
|
||||
"test",
|
||||
};
|
||||
|
||||
QSet<QString> Project::getTopLevelMapFields() {
|
||||
|
@ -218,7 +217,7 @@ bool Project::loadMapData(Map* map) {
|
|||
for (int i = 0; i < objectEventsArr.size(); i++) {
|
||||
QJsonObject event = objectEventsArr[i].toObject();
|
||||
// If clone objects are not enabled then no type field is present
|
||||
QString type = hasCloneObjects ? event["type"].toString() : "object";
|
||||
QString type = hasCloneObjects ? ParseUtil::jsonToQString(event["type"]) : "object";
|
||||
if (type.isEmpty() || type == "object") {
|
||||
ObjectEvent *object = new ObjectEvent();
|
||||
object->loadFromJson(event, this);
|
||||
|
@ -253,7 +252,7 @@ bool Project::loadMapData(Map* map) {
|
|||
QJsonArray coordEventsArr = mapObj["coord_events"].toArray();
|
||||
for (int i = 0; i < coordEventsArr.size(); i++) {
|
||||
QJsonObject event = coordEventsArr[i].toObject();
|
||||
QString type = event["type"].toString();
|
||||
QString type = ParseUtil::jsonToQString(event["type"]);
|
||||
if (type == "trigger") {
|
||||
TriggerEvent *coord = new TriggerEvent();
|
||||
coord->loadFromJson(event, this);
|
||||
|
@ -271,7 +270,7 @@ bool Project::loadMapData(Map* map) {
|
|||
QJsonArray bgEventsArr = mapObj["bg_events"].toArray();
|
||||
for (int i = 0; i < bgEventsArr.size(); i++) {
|
||||
QJsonObject event = bgEventsArr[i].toObject();
|
||||
QString type = event["type"].toString();
|
||||
QString type = ParseUtil::jsonToQString(event["type"]);
|
||||
if (type == "sign") {
|
||||
SignEvent *bg = new SignEvent();
|
||||
bg->loadFromJson(event, this);
|
||||
|
|
Loading…
Reference in a new issue