Add Terms::TermOrDefault
Generator: Support static functions
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -72,6 +72,7 @@ set(LCF_SOURCES
src/reader_util.cpp
src/reader_xml.cpp
src/rpg_setup.cpp
+ src/rpg_terms.cpp
src/saveopt.cpp
src/writer_lcf.cpp
src/writer_xml.cpp

MODIFY
Makefile.am
Makefile.am
@@ -63,6 +63,7 @@ liblcf_la_SOURCES = \
src/reader_util.cpp \
src/reader_xml.cpp \
src/rpg_setup.cpp \
+ src/rpg_terms.cpp \
src/saveopt.cpp \
src/writer_lcf.cpp \
src/writer_xml.cpp \

MODIFY
generator/csv/functions.csv
generator/csv/functions.csv
-Structure,Method,Headers
-Actor,void Setup(bool is2k3),
-Parameters,void Setup(int final_level),
+Structure,Method,Static,Headers
+Actor,void Setup(bool is2k3),f,
+Parameters,void Setup(int final_level),f,
+Terms,"std::string TermOrDefault(const DBString& db_term, StringView default_term)",t,

MODIFY
generator/generate.py
generator/generate.py
@@ -321,8 +321,22 @@ def get_flags(*filenames):
return merge_dicts(results)
def get_functions(*filenames):
- results = list(map(lambda x: process_file(x, namedtuple("Function", "method headers")), filenames))
- return merge_dicts(results)
+ Function = namedtuple("Function", "method static headers")
+
+ results = list(map(lambda x: process_file(x, Function), filenames))
+
+ processed_result = OrderedDict()
+
+ for k, field in merge_dicts(results).items():
+ processed_result[k] = []
+ for elem in field:
+ elem = Function(
+ elem.method,
+ elem.static == 't',
+ elem.headers)
+ processed_result[k].append(elem)
+
+ return processed_result
def get_constants(filename='constants.csv'):
return process_file(filename, namedtuple("Constant", "name type value comment"))

MODIFY
generator/templates/rpg_header.tmpl
generator/templates/rpg_header.tmpl
@@ -56,7 +56,7 @@ namespace rpg {
{%- endfor %}
{% endif %}
{%- for func in functions[struct_name] %}
- {{ func.method }};
+ {%+ if func.static %}static {% endif %}{{ func.method }};
{%- endfor %}
{%- if has_id %}
int ID = 0;

MODIFY
src/generated/lcf/rpg/terms.h
src/generated/lcf/rpg/terms.h
Binary files a/src/generated/lcf/rpg/terms.h and b/src/generated/lcf/rpg/terms.h differ

ADD
src/rpg_terms.cpp
+/*
+ * This file is part of liblcf. Copyright (c) 2020 liblcf authors.
+ * https://github.com/EasyRPG/liblcf - https://easyrpg.org
+ *
+ * liblcf is Free/Libre Open Source Software, released under the MIT License.
+ * For the full copyright and license information, please view the COPYING
+ * file that was distributed with this source code.
+ */
+
+#include "lcf/rpg/terms.h"
+
+namespace lcf {
+
+std::string rpg::Terms::TermOrDefault(const DBString& db_term, StringView default_term) {
+ if (db_term == kDefaultTerm) {
+ return ToString(default_term);
+ }
+ return ToString(db_term);
+}
+
+} // namespace lcf

Add Terms::TermOrDefault

Generator: Support static functions