Correctly write database version field
MODIFY
generator/csv/fields.csv
generator/csv/fields.csv
@@ -590,7 +590,7 @@ Database,system,f,System,0x16,,1,0,RPG::System
Database,switches,f,Array<Switch>,0x17,,1,0,RPG::Switchs
Database,variables,f,Array<Variable>,0x18,,1,0,RPG::Variables
Database,commonevents,f,Array<CommonEvent>,0x19,,1,0,RPG::CommonEvent
-Database,version,f,Int32,0x1A,0,0,0,Indicates version of database. When 1 the database was converted to RPG Maker 2000 v1.61
+Database,version,f,DatabaseVersion,0x1A,0,0,0,Indicates version of database. When 1 the database was converted to RPG Maker 2000 v1.61
Database,commoneventD2,f,,0x1B,,0,1,Duplicated? - Not used - RPG2003
Database,commoneventD3,f,,0x1C,,0,1,Duplicated? - Not used - RPG2003
Database,battlecommands,f,BattleCommands,0x1D,,1,1,RPG::BattleCommand - RPG2003

MODIFY
generator/generate.py
generator/generate.py
@@ -36,10 +36,20 @@ cpp_types = {
}
# Additional Jinja 2 functions
+def lcf_type(field, prefix=True):
+ if field.size == True:
+ return "SIZE"
+ if field.type == "DatabaseVersion":
+ return "DATABASE_VERSION"
+ return "TYPED"
+
def cpp_type(ty, prefix=True):
if ty in cpp_types:
return cpp_types[ty]
+ if ty == "DatabaseVersion":
+ return 'int32_t'
+
m = re.match(r'Array<(.*):(.*)>', ty)
if m:
return 'std::vector<%s>' % cpp_type(m.group(1), prefix)
@@ -131,7 +141,7 @@ def struct_headers(ty, header_map):
if ty == 'String':
return ['<string>']
- if ty in int_types:
+ if ty in int_types or ty == "DatabaseVersion":
return ['<stdint.h>']
if ty in cpp_types:
@@ -353,6 +363,7 @@ def main(argv):
headers = get_headers()
# Setup Jinja
+ env.filters["lcf_type"] = lcf_type
env.filters["cpp_type"] = cpp_type
env.filters["pod_default"] = pod_default
env.filters["struct_has_code"] = filter_structs_without_codes

MODIFY
generator/templates/reader.tmpl
generator/templates/reader.tmpl
LCF_STRUCT_FIELDS_BEGIN()
{%- for field in fields[struct_name]|field_is_used %}
- LCF_STRUCT_{% if field.size %}SIZE{% else %}TYPED{% endif %}_FIELD({{ field.type|cpp_type }}, {{ field.name }}, {{field.presentifdefault}}, {{field.is2k3}}),
+ LCF_STRUCT_{{ field|lcf_type }}_FIELD({{ field.type|cpp_type }}, {{ field.name }}, {{field.presentifdefault}}, {{field.is2k3}}),
{%- endfor %}
LCF_STRUCT_FIELDS_END()

MODIFY
src/generated/ldb_database.cpp
src/generated/ldb_database.cpp
Binary files a/src/generated/ldb_database.cpp and b/src/generated/ldb_database.cpp differ

MODIFY
src/reader_struct.h
src/reader_struct.h
#include "rpg_treemap.h"
#include "rpg_rect.h"
#include "rpg_savepicture.h"
+#include "data.h"
// Forward declarations
@@ -427,6 +428,32 @@ struct TypedField : public Field<S> {
Field<S>(id, name, present_if_default, is2k3), ref(ref) {}
};
+/**
+ * DatabaseVersionField class template.
+ */
+
+template <typename S, typename T>
+struct DatabaseVersionField : public TypedField<S,T> {
+
+ using TypedField<S,T>::TypedField;
+
+ int LcfSize(const S& obj, LcfWriter& stream) const {
+ //If db version is 0, it's like a "version block" is not present.
+ if ((obj.*(this->ref)) == 0) {
+ return 0;
+ }
+ return TypedField<S,T>::LcfSize(obj, stream);
+ }
+ bool IsDefault(const S& a, const S& b) const {
+ if (Data::system.ldb_id == 2003) {
+ //DB Version always present in 2k3 db
+ return false;
+ }
+ //Only present if not 0 in 2k db.
+ return TypedField<S,T>::IsDefault(a, b);
+ }
+};
+
/**
* SizeField class template.
*/
@@ -745,6 +772,15 @@ private:
, IS2K3 \
) \
+#define LCF_STRUCT_DATABASE_VERSION_FIELD(T, REF, PRESENTIFDEFAULT, IS2K3) \
+ new DatabaseVersionField<RPG::LCF_CURRENT_STRUCT, T>( \
+ &RPG::LCF_CURRENT_STRUCT::REF \
+ , LCF_CHUNK_SUFFIX::BOOST_PP_CAT(Chunk, LCF_CURRENT_STRUCT)::REF \
+ , BOOST_PP_STRINGIZE(REF) \
+ , PRESENTIFDEFAULT \
+ , IS2K3 \
+ ) \
+
#define LCF_STRUCT_SIZE_FIELD(T, REF, PRESENTIFDEFAULT, IS2K3) \
new SizeField<RPG::LCF_CURRENT_STRUCT, T>( \
&RPG::LCF_CURRENT_STRUCT::REF \

Correctly write database version field