Skip to content

Commit 702b5c4

Browse files
Ghabryrueter37
authored andcommitted
Add Terms::TermOrDefault
Generator: Support static functions
1 parent 5e6d826 commit 702b5c4

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ set(LCF_SOURCES
7272
src/reader_util.cpp
7373
src/reader_xml.cpp
7474
src/rpg_setup.cpp
75+
src/rpg_terms.cpp
7576
src/saveopt.cpp
7677
src/writer_lcf.cpp
7778
src/writer_xml.cpp

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ liblcf_la_SOURCES = \
6363
src/reader_util.cpp \
6464
src/reader_xml.cpp \
6565
src/rpg_setup.cpp \
66+
src/rpg_terms.cpp \
6667
src/saveopt.cpp \
6768
src/writer_lcf.cpp \
6869
src/writer_xml.cpp \

generator/csv/functions.csv

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
Structure,Method,Headers
2-
Actor,void Setup(bool is2k3),
3-
Parameters,void Setup(int final_level),
1+
Structure,Method,Static,Headers
2+
Actor,void Setup(bool is2k3),f,
3+
Parameters,void Setup(int final_level),f,
4+
Terms,"std::string TermOrDefault(const DBString& db_term, StringView default_term)",t,

generator/generate.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,22 @@ def get_flags(*filenames):
321321
return merge_dicts(results)
322322

323323
def get_functions(*filenames):
324-
results = list(map(lambda x: process_file(x, namedtuple("Function", "method headers")), filenames))
325-
return merge_dicts(results)
324+
Function = namedtuple("Function", "method static headers")
325+
326+
results = list(map(lambda x: process_file(x, Function), filenames))
327+
328+
processed_result = OrderedDict()
329+
330+
for k, field in merge_dicts(results).items():
331+
processed_result[k] = []
332+
for elem in field:
333+
elem = Function(
334+
elem.method,
335+
elem.static == 't',
336+
elem.headers)
337+
processed_result[k].append(elem)
338+
339+
return processed_result
326340

327341
def get_constants(filename='constants.csv'):
328342
return process_file(filename, namedtuple("Constant", "name type value comment"))

generator/templates/rpg_header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace rpg {
5656
{%- endfor %}
5757
{% endif %}
5858
{%- for func in functions[struct_name] %}
59-
{{ func.method }};
59+
{%+ if func.static %}static {% endif %}{{ func.method }};
6060
{%- endfor %}
6161
{%- if has_id %}
6262
int ID = 0;

src/generated/lcf/rpg/terms.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace rpg {
2828
// Sentinel name used to denote that the default hardcoded term should be used.
2929
static constexpr const char* kDefaultTerm = "default_term";
3030

31+
static std::string TermOrDefault(const DBString& db_term, StringView default_term);
3132
DBString encounter;
3233
DBString special_combat;
3334
DBString escape_success;

src/rpg_terms.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* This file is part of liblcf. Copyright (c) 2020 liblcf authors.
3+
* https://github.com/EasyRPG/liblcf - https://easyrpg.org
4+
*
5+
* liblcf is Free/Libre Open Source Software, released under the MIT License.
6+
* For the full copyright and license information, please view the COPYING
7+
* file that was distributed with this source code.
8+
*/
9+
10+
#include "lcf/rpg/terms.h"
11+
12+
namespace lcf {
13+
14+
std::string rpg::Terms::TermOrDefault(const DBString& db_term, StringView default_term) {
15+
if (db_term == kDefaultTerm) {
16+
return ToString(default_term);
17+
}
18+
return ToString(db_term);
19+
}
20+
21+
} // namespace lcf

0 commit comments

Comments
 (0)