Skip to content

Commit

Permalink
Get game config and schema to use some common types
Browse files Browse the repository at this point in the history
This also fixes an invalid type issue in the GUI2 schema,
and allows types to be a direct alias for other types.
  • Loading branch information
CelticMinstrel committed Apr 12, 2018
1 parent a7072ef commit cfff037
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 81 deletions.
10 changes: 0 additions & 10 deletions data/schema/game_config.cfg
Expand Up @@ -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]
Expand Down
57 changes: 4 additions & 53 deletions 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)?$"
Expand All @@ -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$"
Expand All @@ -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$"
Expand All @@ -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$"
Expand Down Expand Up @@ -444,7 +395,7 @@
[/key]
[key]
name="text"
type="f_tstring"
type="f_t_string"
default=""
[/key]
[key]
Expand Down
33 changes: 31 additions & 2 deletions 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=".*"
Expand All @@ -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]
43 changes: 27 additions & 16 deletions 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}
2 changes: 2 additions & 0 deletions src/serialization/tag.cpp
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit cfff037

Please sign in to comment.