Skip to content

Commit

Permalink
Support RPG::Terms 0x3 defaulting semantics
Browse files Browse the repository at this point in the history
RPG::Terms 0x3 if empty string will be present in a 2k database
but not a 2k3 database. This appears a one-off situation so it
is hacked in for now..
  • Loading branch information
fmatthew5876 committed Sep 30, 2018
1 parent 2443c96 commit 22dcc27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/reader_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void Struct<S>::WriteLcf(const S& obj, LcfWriter& stream) {
<< " after " << last
<< " in struct " << name
<< std::endl;
if (!field->present_if_default && field->IsDefault(obj, ref)) {
if (!field->isPresentIfDefault(db_is2k3) && field->IsDefault(obj, ref)) {
continue;
}
stream.WriteInt(field->id);
Expand All @@ -135,7 +135,7 @@ int Struct<S>::LcfSize(const S& obj, LcfWriter& stream) {
continue;
}
//printf("%s\n", field->name);
if (!field->present_if_default && field->IsDefault(obj, ref)) {
if (!field->isPresentIfDefault(db_is2k3) && field->IsDefault(obj, ref)) {
continue;
}
result += LcfReader::IntSize(field->id);
Expand Down
10 changes: 10 additions & 0 deletions src/reader_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "rpg_treemap.h"
#include "rpg_rect.h"
#include "rpg_savepicture.h"
#include "rpg_terms.h"

// Forward declarations

Expand Down Expand Up @@ -304,6 +305,15 @@ struct Field {
virtual void BeginXml(S& obj, XmlReader& stream) const = 0;
virtual void ParseXml(S& obj, const std::string& data) const = 0;

bool isPresentIfDefault(bool db_is2k3) const {
if (std::is_same<S,RPG::Terms>::value && db_is2k3 && id == 0x3) {
//Special case - only known field that is 2k specific and not
//written to a 2k3 db if defaulted.
return false;
}
return present_if_default;
}

Field(int id, const char* name, bool present_if_default, bool is2k3) :
name(name), id(id), present_if_default(present_if_default), is2k3(is2k3) {}
};
Expand Down

0 comments on commit 22dcc27

Please sign in to comment.