Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Added test for equipment_bonus blocks without 'instant=yes' #73

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0896deb
Added test for equipment_bonus blocks without 'instant=yes'
BlizzardOfOzy Jun 14, 2018
a5f2b07
Added checker for invalid ideology references
BlizzardOfOzy Jun 20, 2018
a2a7845
Significant refactoring, made both checkers much more resiliant
BlizzardOfOzy Jun 21, 2018
7e9bc33
Significant refactoring, made both checkers much more resiliant
BlizzardOfOzy Jun 21, 2018
129a1f3
Added new checks for Ai chance in events with only one option and eve…
BlizzardOfOzy Jun 21, 2018
5356d74
Significant refactoring, made extracting scopes and interpreting thei…
BlizzardOfOzy Jun 25, 2018
014ee5f
Made scope extractor much cleaner, moved around how scope bodys are h…
BlizzardOfOzy Jun 27, 2018
4e4a0c7
Minor touch-ups
BlizzardOfOzy Jun 27, 2018
ed583d4
Completed the hidden event validator, removed a nasty bug with the sc…
BlizzardOfOzy Jul 1, 2018
bb75ec0
Completed the hidden event validator, removed a nasty bug with the sc…
BlizzardOfOzy Jul 5, 2018
a45e863
restored buggy test
BlizzardOfOzy Jul 5, 2018
2ec7464
significant refactoring
BlizzardOfOzy Aug 8, 2018
bd88ece
added loads of testing, committing before major refactoring
BlizzardOfOzy Aug 8, 2018
046b16d
added loads of testing, committing before major refactoring
BlizzardOfOzy Aug 9, 2018
0089794
added timing decorators
BlizzardOfOzy Aug 13, 2018
46e5d7b
inlined some constructors
BlizzardOfOzy Aug 13, 2018
2474999
used os.walk for filename generation, deleted some useless files
BlizzardOfOzy Aug 13, 2018
1c54076
fixed usages of os.walk, minor checkGFX refactorings
BlizzardOfOzy Aug 14, 2018
84f9111
Merge branch 'master' of https://github.com/BlizzardOfOzy/PDS-Validator
BlizzardOfOzy Aug 15, 2018
73952ac
working scopeExtractor
BlizzardOfOzy Aug 15, 2018
005f049
untested refactored scope generator
BlizzardOfOzy Aug 15, 2018
03950a2
finally got a scope finder by type working
BlizzardOfOzy Aug 17, 2018
8d1acb0
updated main test files
BlizzardOfOzy Aug 17, 2018
16328b8
Initial parser work
Yard1 Jun 7, 2018
b064bb2
Add PDSScriptedEffect, PDSScriptedTrigger, PDSFocus, PDSFocusTree
Yard1 Jun 12, 2018
be0fe88
significant refactoring of finding and opening files
BlizzardOfOzy Aug 18, 2018
21c11d4
significant refactoring of finding and opening files
BlizzardOfOzy Aug 18, 2018
d258cfb
deleted some files from some other branch?
BlizzardOfOzy Aug 18, 2018
7ee83d8
updated executable
BlizzardOfOzy Aug 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

validator.txt
settings.txt
settings.txt
*.pyc
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added Scripts/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions Scripts/checkEquipmentBonus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from Scripts.openFile import open_file
from Scripts.scope import ScopeWithFilename
from Scripts.generateScopes import generate_scopes
from Scripts.generateScopeIndicesByType import generate_scope_indices_by_type
from Scripts.testGenerateTopLevelScopes import generate_top_level_scope_indices
from Scripts.timedFunction import timed_function
from Scripts.generateFilenames import generate_filenames


@timed_function
def check_equipment_bonus(path, output_file):
for equipment_bonus in find_next_equipment_bonus(path):
if 'instant' not in equipment_bonus.body:
output_file.write("\'instant \' field missing from equipment bonus starting at " + str(equipment_bonus.index) + ' in ' + equipment_bonus.filename + '\n')


def find_next_equipment_bonus(path):
subpath = '\\common\\ideas'
scope_type = 'equipment_bonus'
for file in generate_filenames(path, subpath):
string = open_file(file).read()
for equipment_bonus_scope in generate_scopes(string, generate_scope_indices_by_type, scope_type):
for scope in generate_scopes(equipment_bonus_scope.body, generate_top_level_scope_indices):
yield ScopeWithFilename(file, scope)
33 changes: 33 additions & 0 deletions Scripts/checkEvents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from Scripts.generateScopes import generate_scopes
from Scripts.generateScopeIndicesByType import generate_scope_indices_by_type
from Scripts.openFile import open_file
from Scripts.scope import ScopeWithFilename
from Scripts.timedFunction import timed_function
from Scripts.generateFilenames import generate_filenames


@timed_function
def check_events(path, output_file):
for event in find_next_country_event(path):
if 'ai_chance' in event.body and event.body.count('option =') == 1:
output_file.write("ai_chance present in event starting at " + str(event.starting_line) + ' in ' + event.filename + 'but there is only one option.\n')
if 'hidden = yes' not in event.body and 'picture =' not in event.body:
output_file.write("No picture for event starting at " + str(event.starting_line) + ' in ' + event.filename + '.\n')
if 'hidden = yes' in event.body:
if 'picture =' in event.body:
output_file.write("Hidden event at " + str(event.starting_line) + ' in ' + event.filename + ' has a picture.\n')
if 'title =' in event.body:
output_file.write("Hidden event at " + str(event.starting_line) + ' in ' + event.filename + ' has a title.\n')
if 'desc =' in event.body:
output_file.write("Hidden event at " + str(event.starting_line) + ' in ' + event.filename + ' has a description.\n')
if 'option =' in event.body:
output_file.write("Hidden event at " + str(event.starting_line) + ' in ' + event.filename + ' has options.\n')


def find_next_country_event(path):
subpath = '\\events'
scope = 'country_event'
for filename in generate_filenames(path, subpath):
string = open_file(filename).read()
for scope in generate_scopes(string, generate_scope_indices_by_type, scope):
yield ScopeWithFilename(filename, scope)
77 changes: 33 additions & 44 deletions Scripts/checkGFX.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from os import walk
from os import path
from codecs import open
import time

from Scripts.timedFunction import timed_function

@timed_function
def check_for_missing_gfx(file_path, output_file, hoi4_path):
t0 = time.time()

# C:\Users\Martijn\Documents\Paradox Interactive\Hearts of Iron IV\mod\KRBU
# this is going to be a mess
Expand Down Expand Up @@ -84,9 +84,6 @@ def check_for_missing_gfx(file_path, output_file, hoi4_path):
check_a_lot(event_path, event_gfx_path,interface_path, file_path, output_file, hoi4_path, leaders_gfx_path, country_history_path, decisions_path, tree_path)

focus_tree_icons(tree_path, hoi4_path, output_file, file_path, tree_gfx_path, interface_path)
t0 = time.time() - t0
print("GFX script Time: " + (t0*1000).__str__() + " ms")


def fill_tag_array(internal_path, cosmetics):
# 0 = just normal
Expand Down Expand Up @@ -127,19 +124,12 @@ def fill_tag_array(internal_path, cosmetics):
for string in lines:
if 'set_cosmetic_tag' in string and string.strip().startswith('#') is False and '{' not in string:
temp_string = string.split(' ')[2][:-2]
if finddup(tags, temp_string) is False:
if temp_string not in tags:
tags.append(temp_string)
#print("Found TAG: " + temp_string)
return tags


def finddup(array, string):
if string in array:
return True
else:
return False


def hasideo(string, idarray):
for ideos in idarray:
if ideos in string:
Expand Down Expand Up @@ -173,17 +163,17 @@ def check_flags( flag_path, output_file, file_path):
temp_string = file_name[:-4]
if hasideo(temp_string, ideos) is True:
temp_string = stripideo(temp_string, ideos)
if finddup(tag_array, temp_string) is False:
#print("No tag for " + file_name)
if temp_string not in tag_array:
# print("No tag for " + file_name)
output_file.write("No (cosmetic) tag for " + file_name + "\n")
if finddup(flagarr, temp_string) is False:
if temp_string not in flagarr:
flagarr.append(temp_string)
#print(temp_string)
# print(temp_string)
tag_array = fill_tag_array(file_path, 0)
for strings in tag_array:
if finddup(flagarr, strings) is False:
if strings not in flagarr:
output_file.write("No flag for " + strings + "\n")
#print("No flag for " + strings)
# print("No flag for " + strings)


def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_file, hoi4path, leaders_gfx_path, country_history_path, decisions_path, tree_path):
Expand All @@ -196,7 +186,7 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
for filename in filenames:
#temp_string = path.join(root, filename)[len(file_path)+1:].replace('\\','/')
temp_string = filename
if finddup(actual_found_portrait_gfx, temp_string) is False:
if temp_string not in actual_found_portrait_gfx:
actual_found_portrait_gfx.append(temp_string)
actual_found_portrait_gfx_lower.append((temp_string.lower()))
actual_amount.append(1)
Expand All @@ -211,7 +201,7 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
for filename in filenames:
#temp_string = path.join(root, filename)[len(file_path)+1:].replace('\\','/')
temp_string = filename
if finddup(actual_found_portrait_gfx, temp_string) is False:
if temp_string not in actual_found_portrait_gfx:
#print("Found Leader Portrait: " + temp_string)
actual_found_portrait_gfx.append(temp_string)
actual_found_portrait_gfx_lower.append((temp_string.lower()))
Expand Down Expand Up @@ -243,7 +233,7 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
temp_string = line.strip()
if '.tga' in temp_string or '.dds' in temp_string:
temp_string = temp_string.split('=')[1].replace('"', '')
if finddup(leader_picture, temp_string) is False:
if temp_string not in leader_picture:
temp_string = strip_and_clean(temp_string)
#print(temp_string)
leader_picture.append(temp_string)
Expand All @@ -252,24 +242,23 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
index = leader_picture.index(temp_string)
amount = amountarr[index] + 1
amountarr[index] = amount
if finddup(actual_found_portrait_gfx, temp_string) is False:
if finddup(actual_found_portrait_gfx_lower, temp_string.lower()) is True:
if temp_string not in actual_found_portrait_gfx:
if temp_string.lower() in actual_found_portrait_gfx_lower:
#print("Wrongly spelled portrait: " + temp_string + " in file " + dir.split('\\')[len(dir.split('\\'))-1] + "\\" + file_name + " at line " + line_number.__str__())
output_file.write("Wrongly spelled portrait: " + temp_string + " in file " + dir.split('\\')[len(dir.split( '\\')) - 1] + "\\" + file_name + " at line " + line_number.__str__() + "\n")
else:
#print("Didnt find portrait: " + temp_string + " in file " + dir.split('\\')[len(dir.split('\\'))-1] + "\\" + file_name + " at line " + line_number.__str__())
output_file.write("Didnt find portrait: " + temp_string + " in file " + dir.split('\\')[len(dir.split('\\')) - 1] + "\\" + file_name + " at line " + line_number.__str__() + "\n")
elif '"' not in temp_string:
temp_string = temp_string.split(' ')[2]
if finddup(event_picture, temp_string) is False:
if temp_string not in event_picture:
event_picture.append(temp_string)
else:
temp_string = temp_string.split('=')[1].replace('"', '').strip()
if temp_string != "" and "." not in temp_string:
#print("Incorrect or false negative gfx key of " + temp_string + " at line " + line_number.__str__() + " in file " + file_name)
output_file.write("Incorrect or false negative gfx key of " + temp_string + " at line " + line_number.__str__() + " in file " + file_name + "\n")


#GFX Keys that arent used
event_gfx_key = []
event_gfx_file_names_in_gfx_file = []
Expand All @@ -291,12 +280,12 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
if '#' in line:
line = line.split('#')[0].strip()
temp_string = line.split('"')[1].strip()
if finddup(event_gfx_key, temp_string) is True:
if temp_string in event_gfx_key:
#print("Duplicated gfx key " + temp_string +" in file " + file_name + " at line " + line_number.__str__())
output_file.write("Duplicated gfx key " + temp_string +" in file " + file_name + " at line " + line_number.__str__() + "\n")
else:
event_gfx_key.append(temp_string)
if finddup(event_picture, temp_string) is False and vanilla == 0:
if temp_string not in event_picture and vanilla == 0:
#print("Unused Gfx: " + temp_string + " at line " + line_number.__str__() + " in file " + file_name)
output_file.write("Unused event Gfx: " + temp_string + " at line " + line_number.__str__() + " in file " + file_name + "\n")
if "texturefile" in line and line.strip().startswith('#') is False:
Expand All @@ -321,7 +310,7 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
temp_string.replace(' ', ' ')
temp_string = temp_string.split(' ')[2]
#print(temp_string)
if finddup(event_gfx_key, temp_string) is False:
if temp_string not in event_gfx_key:
output_file.write("GFX event key not found: " + temp_string + " at line " + line_number.__str__() + " in file " + file_name + "\n")
#print("GFX key not found: " + temp_string + " at line " + line_number.__str__() + " in file " + file_name)

Expand All @@ -330,12 +319,12 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
for root, directories, filenames in walk(event_gfx_path):
for filename in filenames:
temp_string = path.join(root, filename)[len(file_path)+1:].replace('\\','/')
if finddup(actual_found_event_gfx, temp_string) is True:
if temp_string in actual_found_event_gfx:
#print("Duplicate event gfx: " + filename)
output_file.write("Duplicate event gfx: " + temp_string + "\n")
else:
actual_found_event_gfx.append(temp_string)
if finddup(event_gfx_file_names_in_gfx_file, temp_string) is False:
if temp_string not in event_gfx_file_names_in_gfx_file:
output_file.write("GFX not used in any .gfx file: " + temp_string + "\n")
#print("GFX not used in any .gfx file: " + temp_string)

Expand Down Expand Up @@ -387,8 +376,8 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
line = line.split('#')[0].strip()
temp_string = line.split('=')[1].strip()
decisions_found.append(temp_string)
if finddup(decisions_keys, temp_string) is False:
if finddup(decisions_keys_full, temp_string) is False:
if temp_string not in decisions_keys:
if temp_string not in decisions_keys_full:
output_file.write("Didn't find icon decisions " + temp_string + " in file " + filename + " at " + line_number.__str__() + "\n")
else:
output_file.write("Key for decisions wronly written (did you add or remove GFX_categories/GFX decisions)" + temp_string + " in file " + filename + " at " + line_number.__str__() + "\n")
Expand All @@ -407,8 +396,8 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
line = line.split('#')[0].strip()
temp_string = line.split('=')[1].strip()
decisions_found.append(temp_string)
if finddup(decisions_keys, temp_string) is False:
if finddup(decisions_keys_full, temp_string) is False:
if temp_string not in decisions_keys:
if temp_string not in decisions_keys_full:
output_file.write("Didn't find icon decisions/ Wrong type used " + temp_string + " in file " + filename + " at " + line_number.__str__() + ". Did you forget to add categories_ to the icon name?\n")
#print("Didn't find icon decisions " + temp_string + " in file " + filename + " at " + line_number.__str__())
if 'picture' in line:
Expand All @@ -417,7 +406,7 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
line = line.split('#')[0].strip()
temp_string = line.split('=')[1].strip()
decisions_found.append(temp_string)
if finddup(decisions_keys_full, temp_string) is False:
if temp_string not in decisions_keys_full:
output_file.write("Didn't find icon decisions/ Wrong type used " + temp_string + " in file " + filename + " at " + line_number.__str__() + ". Did you forget to add categories_ to the icon name?\n")
#print("Didn't find picture decisions " + temp_string + " in file " + filename + " at " + line_number.__str__())

Expand All @@ -434,8 +423,8 @@ def check_a_lot(event_path, event_gfx_path, interface_path, file_path, output_fi
if line.strip().startswith('#') is False:
temp_string = line.split('\"')[1].strip()
#temp_string = temp_string[13:]
if finddup(decisions_found, temp_string) is False:
if finddup(decisions_found, temp_string[13:]) is False:
if temp_string not in decisions_found:
if temp_string[13:] not in decisions_found:
#print("Found Unused KR Decision GFX " + temp_string + " in " + filenames)
output_file.write("Found Unused KR Decision GFX " + temp_string + " in " + filenames + "\n")

Expand Down Expand Up @@ -478,18 +467,18 @@ def focus_tree_icons(tree_path, hoi4_path, output_file, mod_path, tree_gfx, gfx_
continue
temp_string = temp_string.split('/')[len(temp_string.split('/'))-1]
goals_files_needed.append(temp_string[:len(temp_string)-4])
if finddup(tree_gfx_files, temp_string) is False:
if temp_string not in tree_gfx_files:
if 'tga' in temp_string:
if finddup(tree_gfx_files, temp_string.replace('tga', 'dds')) is False:
if temp_string.replace('tga', 'dds') not in tree_gfx_files:
#print("Could not find " + temp_string + " in the gfx/interface/goals folder")
output_file.write("Could not find " + temp_string + " in the gfx/interface/goals folder\n")
elif 'dds' in temp_string:
if finddup(tree_gfx_files, temp_string.replace('dds', 'tga')) is False:
if temp_string.replace('dds', 'tga') not in tree_gfx_files:
#print("Could not find " + temp_string + " in the gfx/interface/goals folder")
output_file.write("Could not find " + temp_string + " in the gfx/interface/goals folder\n")

for filename in tree_gfx_files:
if finddup(goals_files_needed, filename[:len(filename)-4]) is False:
if filename[:len(filename)-4] not in goals_files_needed:
#print("Found focus texture not used " + filename[:len(filename)-4])
output_file.write("Found focus texture not used " + filename[:len(filename)-4] + "\n")

Expand Down Expand Up @@ -530,9 +519,9 @@ def focus_tree_icons(tree_path, hoi4_path, output_file, mod_path, tree_gfx, gfx_
if line.strip() is not "":
line = line.split('=')[1].strip()
found_gfx_in_tree.append(line)
if finddup(gfx_names, line) is False:
if gfx_names not in line:
output_file.write("Found focus icon \"" + line + "\" not declared in " + filename + " in line: " + line_number.__str__() +"\n")

for string in kr_gfx_names:
if finddup(found_gfx_in_tree, string) is False:
if string not in found_gfx_in_tree:
output_file.write("Found focus icon never used in any focus tree: " + string + "\n")
Loading