From 69d1c61687407e7c9daf483c77722b2ad5d5e41f Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 5 Mar 2018 21:43:45 -0500 Subject: [PATCH] Get game config and schema to use some common types This also fixes an invalid type issue in the GUI2 schema, and allows types to be a direct alias for other types. --- data/schema/game_config.cfg | 10 ------ data/schema/gui.cfg | 57 +++-------------------------------- data/schema/types/basic.cfg | 33 ++++++++++++++++++-- data/schema/types/formula.cfg | 43 ++++++++++++++++---------- src/serialization/tag.cpp | 2 ++ 5 files changed, 64 insertions(+), 81 deletions(-) diff --git a/data/schema/game_config.cfg b/data/schema/game_config.cfg index e7196f883f0c..a4cde4224988 100644 --- a/data/schema/game_config.cfg +++ b/data/schema/game_config.cfg @@ -55,16 +55,6 @@ name="defeat_condition" value="no_leader_left|no_units_left|never|always" [/type] - [type] - name=point - [list] - min=1 - max=2 - [element] - link="int" - [/element] - [/list] - [/type] [type] name=range [list] diff --git a/data/schema/gui.cfg b/data/schema/gui.cfg index 79cb3529cff5..c338823a1e7f 100644 --- a/data/schema/gui.cfg +++ b/data/schema/gui.cfg @@ -1,40 +1,10 @@ [wml_schema] - [type] - name=bool - value="^true|false|yes|no$" - [/type] + {./types/basic.cfg} + {./types/formula.cfg} [type] name=border value="^(top|bottom|left|right|all)?(,\s*(top|bottom|left|right|all))*$" [/type] - [type] - name=color - value="^(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)$" - [/type] - [type] - name=f_bool - value="^.*$" - [/type] - [type] - name=f_h_align - value="^.*$" - [/type] - [type] - name=f_int - value="^.*$" - [/type] - [type] - name=f_string - value="^.*$" - [/type] - [type] - name=f_tstring - value="^_?.*$" - [/type] - [type] - name=f_unsigned - value="^.+$" - [/type] [type] name=font_family value="^(sans|monospace|light|script)?$" @@ -43,10 +13,6 @@ name=font_style value="^(normal|bold|italic|underline|light)?$" [/type] - [type] - name=function - value="^_?.*$" - [/type] [type] name=grow_direction value="^horizontal|vertical$" @@ -55,10 +21,7 @@ name=h_align value="^left|right|center$" [/type] - [type] - name=int - value="^-?\d+$" - [/type] + {FORMULA_TYPE h_align} [type] name=resize_mode value="^scale|stretch|tile|tile_center$" @@ -67,18 +30,6 @@ name=scrollbar_mode value="^always|never|auto|initial_auto$" [/type] - [type] - name=string - value="^.*$" - [/type] - [type] - name=t_string - value="^_?.*$" - [/type] - [type] - name=unsigned - value="^\d+$" - [/type] [type] name=v_align value="^top|bottom|center$" @@ -444,7 +395,7 @@ [/key] [key] name="text" - type="f_tstring" + type="f_t_string" default="" [/key] [key] diff --git a/data/schema/types/basic.cfg b/data/schema/types/basic.cfg index 85bc0cace67a..90248038e48f 100644 --- a/data/schema/types/basic.cfg +++ b/data/schema/types/basic.cfg @@ -1,12 +1,29 @@ +#define ALIAS_TYPE TYPE BASE +[type] + name={TYPE} + link={BASE} +[/type] +#enddef + [type] name=bool value="true|false|yes|no" [/type] + [type] name=int value="-?\d+" [/type] +[type] + name=unsigned + value="\d+" +[/type] +[type] + name=real + value="-?\d+(\.\d+)?" +[/type] + [type] name=string value=".*" @@ -15,7 +32,19 @@ name=t_string value="_?.*" [/type] + [type] - name=real - value="-?\d+(\.\d+)?" + name=color + value="(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)[.,]\s*(?:2[0-5][0-5]|[01]?\d?\d)" +[/type] + +[type] + name=point + [list] + min=1 + max=2 + [element] + link="int" + [/element] + [/list] [/type] diff --git a/data/schema/types/formula.cfg b/data/schema/types/formula.cfg index 35ce75759164..aadfeb8a1aea 100644 --- a/data/schema/types/formula.cfg +++ b/data/schema/types/formula.cfg @@ -1,19 +1,30 @@ -# The "formula" and "f_string" types are currently the same as "string" -# They're provided as separate types only for documentation purposes -[type] - name=formula - value=".*" -[/type] -[type] - name=f_string - value=".*" -[/type] -[type] - name=f_int - value="-?\d+|\(.*\)" -[/type] +# Note that basic.cfg must also be included for these to work! + +#define FORMULA_TYPE BASE [type] - name=f_real - value="(-?\d+(\.\d+))|\(.*\)?" + name=f_{BASE} + [union] + [type] + link={BASE} + [/type] + [type] + value="\(.*\)\s*" + [/type] + [/union] [/type] +#enddef + +# The "formula", "function", and "f_string" types are currently the same as "string" +# They're provided as separate types only for documentation purposes +{ALIAS_TYPE formula string} +{ALIAS_TYPE function string} +{ALIAS_TYPE f_string string} + +{FORMULA_TYPE bool} +{FORMULA_TYPE int} +{FORMULA_TYPE unsigned} +{FORMULA_TYPE real} +{FORMULA_TYPE color} +{FORMULA_TYPE point} +{FORMULA_TYPE t_string} diff --git a/src/serialization/tag.cpp b/src/serialization/tag.cpp index d48b0395018f..a7e11e097c1a 100644 --- a/src/serialization/tag.cpp +++ b/src/serialization/tag.cpp @@ -77,6 +77,8 @@ class_type::class_type(const config& cfg) } } else if(cfg.has_attribute("value")) { patterns_.emplace_back(cfg["value"].str()); + } else if(cfg.has_attribute("link")) { + links_.emplace_back(cfg["link"].str()); } }