Skip to content

Commit

Permalink
Added almost the attributes of the [side]
Browse files Browse the repository at this point in the history
Added the optional parameter "limit-lower(number)"
Improved the optional parameter "need-file-in(dir)"
  • Loading branch information
macabeus authored and Elvish-Hunter committed Mar 22, 2016
1 parent a0c882b commit 58e8bc7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
47 changes: 46 additions & 1 deletion data/schema.cfg
Expand Up @@ -8,6 +8,7 @@
boolean="enum true,false,yes,no,on,off"
pathimage="re ^([a-zA-Z0-9_\-.+]+/)*[a-zA-Z0-9_\-.+]+(~(TC|RC|PAL|FL|GS|CS|CROP|SCALE|BL|O|R|G|B|NOP|RIGHT)\(.*\))*$" # TODO: Some 'path' must be changed to 'pathimage'
path="re ^[a-zA-Z0-9_\-.+\/]*[a-zA-Z0-9_\-.+]$"
direction="enum n,ne,se,s,sw,nw"
[root]
# All possible root elements
_about="repeated about"
Expand Down Expand Up @@ -389,7 +390,7 @@
# TODO: _item=...
# TODO: _time...
# TODO: _time_area=...
# TODO: _side=...
_side="repeated side"
# TODO: _event=...
# TODO: _generator=...

Expand Down Expand Up @@ -435,6 +436,50 @@
music="optional string" # TODO: Can be improved to check if the music file really exists
sound="optional string list"
[/part]
typescontroller="enum ai,human,null"
[side]
# TODO: _fog_override=...
# TODO: _ai=...
# TODO: _village=...
# TODO: _unit=...
# TODO: _leader=...

side="optional integer limit-lower(1)" # TODO: If it is multiplay, then 'limit(1,9)'
controller="optional typescontroller"
no_leader="optional boolean"
canrecruit="optional boolean"
type="optional string" # TODO: Can be improved be verified that the unit exists or not | TODO: Required if have a leader
id="optional string"
name="optional string translatable"
unrenamable="optional boolean"
profile="optional string need-file-in(../images)"
recruit="optional string list" # TODO: Can be improved be verified that the unit exists or not
gold="optional integer"
income="optional integer"
hidden="optional boolean"
fog="optional boolean"
fog_data="optional string" # TODO: Complex case
shroud="optional boolean"
shroud_data="optional string" # TODO: Complex case
persistent="optional boolean" # TODO: Required 'save_id'
save_id="optional integer"
previous_save_id="optional string" # TODO: Only multiplay
team_name="optional string"
user_team_name="optional string translatable"
current_player="optional string translatable"
color="optional string" # TODO: Can be improved be verified if the value exists in data/core/team_colors.cfg
flag="optional string" # TODO: Complex case
flag_image="optional string need-file-in(../images)"
village_gold="optional integer"
village_support="optional integer"
recall_cost="optional integer"
share_maps="optional boolean"
share_view="optional boolean"
scroll_to_leader="optional boolean"
suppress_end_turn_confirmation="optional boolean"
facing="optional direction"
# TODO: And attributes for multiplayer?
[/side]
[/schema]

## Things that still need to be converted, in a similar format.
Expand Down
27 changes: 24 additions & 3 deletions data/tools/wmlvalidator
Expand Up @@ -100,22 +100,43 @@ class Validator:
if float(value) > float(number_max) or float(value) < float(number_min):
self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "Value must be between %s and %s, found : %s" % (number_min, number_max, value))

regex_limit_lower = re.compile(ur'^limit-lower\((\d+.\d+|\d+)\)$')
check_limit_lower = [i for i in attribute.optionals if regex_limit_lower.search(i)]
if len(check_limit_lower):
check_limit_lower = check_limit_lower[0]
number = regex_limit_lower.search(check_limit_lower).group(1)

if float(value) < float(number):
self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "Value needs to be at least %s, found : %s" % (number, value))

regex_file_exist = re.compile(ur'^need-file-in\(([\w.\-\/]+)\)$')
check_file_exist = [i for i in attribute.optionals if regex_file_exist.search(i)]
if len(check_file_exist):
check_file_exist = check_file_exist[0]
directory = regex_file_exist.search(check_file_exist).group(1)

value_directory, value_file = re.search(re.compile(ur'(?:(.*)?\/)?(.+)'), value).groups()

import glob
if directory == '.':
sub_directory = os.path.dirname(node.file) + '/'
else:
sub_directory = os.path.dirname(node.file) + '/' + directory + '/'

if not value_directory is None:
sub_directory += value_directory + '/'

files_from_sub_directory = glob.glob(sub_directory + '*')
files_from_sub_directory = [re.sub(re.compile(r'^.*\/(.*)\..*'), r'\1', i) for i in files_from_sub_directory]
if not value in files_from_sub_directory:
self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "The file %s not exist in directory %s" % (value, sub_directory))

# We just want the names of the files from directory, but...
if os.path.splitext(value_file)[1] == '':
# ... if without extension in the value_file, then it is implied. In this case, we do want extensions
files_from_sub_directory = [re.sub(re.compile(r'^.*\/(.*)\..*'), r'\1', i) for i in files_from_sub_directory]
else:
files_from_sub_directory = [re.sub(re.compile(r'^.*\/(.*)'), r'\1', i) for i in files_from_sub_directory]

if not value_file in files_from_sub_directory:
self.validate_result_add(node.file, node.line, "Attribute [%s] %s%s" % (verbosename, attribute.name, gerate_message_with_pos()), "The file %s not exist in directory %s" % (value_file, sub_directory))

if 'list' in attribute.optionals:
pos = 1
Expand Down

0 comments on commit 58e8bc7

Please sign in to comment.