Skip to content

Commit

Permalink
first improvements to file readability
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaFiorini committed Jan 21, 2025
1 parent 5501008 commit ea83f78
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/order_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,30 @@ std::string Order::ToJSONString() const
if(this->extra.get() != nullptr){
auto& extraJson = json["extra"];

extraJson["cargo-type-flags"] = this->extra.get()->cargo_type_flags;
auto &cargo_type_flags = this->extra.get()->cargo_type_flags;

for (int i = 0; i < NUM_CARGO; i++) {
if (cargo_type_flags[i] != 0) {
extraJson["cargo-type-flags"] = cargo_type_flags;
break;
}
}

extraJson["colour"] = this->extra.get()->colour;
extraJson["dispatch-index"] = this->extra.get()->dispatch_index;
extraJson["xdata"] = this->extra.get()->xdata;
extraJson["xdata2"] = this->extra.get()->xdata2;
extraJson["xflags"] = this->extra.get()->xflags;

if (this->extra.get()->xdata != 0) {
extraJson["xdata"] = this->extra.get()->xdata;
}

if (this->extra.get()->xdata2 != 0) {
extraJson["xdata"] = this->extra.get()->xdata2;
}

if (this->extra.get()->xflags != 0) {
extraJson["xdata"] = this->extra.get()->xflags;
}

}

json["refit-cargo"] = this->GetRefitCargo();
Expand Down Expand Up @@ -345,10 +363,10 @@ Order Order::FromJSONString(std::string jsonSTR)
auto &extraJson = json["extra"];

new_order.AllocExtraInfo();

if (extraJson.contains("cargo-type-flags") && extraJson["cargo-type-flags"].is_array()) {

for (int i = 0; i < 64; i++) {
for (int i = 0; i < NUM_CARGO; i++) {

extraJson["cargo-type-flags"][i].get_to(new_order.extra->cargo_type_flags[i]);

Expand Down Expand Up @@ -879,7 +897,6 @@ void OrderList::MoveOrder(VehicleOrderID from, VehicleOrderID to)
std::string OrderList::ToJSONString()
{


nlohmann::json json;

json["version"] = ORDERLIST_JSON_OUTPUT_VERSION;
Expand Down

1 comment on commit ea83f78

@lucaFiorini
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: order import with specified cargo-type-flags needs fixing
Also todo add array length check

Please sign in to comment.