From 6a23a1c35373b953c0d614830edd352cec642588 Mon Sep 17 00:00:00 2001 From: Pelmen323 Date: Tue, 25 Jun 2024 21:00:19 +0400 Subject: [PATCH 1/6] Add MIO variables, mitigate @scope[Country_tags] not working in variables --- Config/variables.cwt | 94 ++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/Config/variables.cwt b/Config/variables.cwt index f86c0b53..0d4ae636 100644 --- a/Config/variables.cwt +++ b/Config/variables.cwt @@ -24,34 +24,34 @@ values = { # ========================= ### Weight for an AI attitude attitude_allied against country. Example: GER.ai_attitude_allied_weight@ENG. - ai_attitude_allied_weight@scope[country] + ai_attitude_allied_weight@enum[country_scope_enum] ai_attitude_allied_weight@enum[country_tags] ### Weight for an AI attitude attitude_friendly against country. Example: GER.ai_attitude_friendly_weight@ENG. - ai_attitude_friendly_weight@scope[country] + ai_attitude_friendly_weight@enum[country_scope_enum] ai_attitude_friendly_weight@enum[country_tags] ### Weight for an AI attitude attitude_hostile against country. Example: GER.ai_attitude_hostile_weight@ENG. - ai_attitude_hostile_weight@scope[country] + ai_attitude_hostile_weight@enum[country_scope_enum] ai_attitude_hostile_weight@enum[country_tags] ### Returns 1 if AI is threatened. ai_attitude_is_threatened ### Weight for an AI attitude attitude_neutral against country. Example: GER.ai_attitude_neutral_weight@ENG. - ai_attitude_neutral_weight@scope[country] + ai_attitude_neutral_weight@enum[country_scope_enum] ai_attitude_neutral_weight@enum[country_tags] ### Weight for an AI attitude attitude_outraged against country. Example: GER.ai_attitude_outraged_weight@ENG. - ai_attitude_outraged_weight@scope[country] + ai_attitude_outraged_weight@enum[country_scope_enum] ai_attitude_outraged_weight@enum[country_tags] ### Weight for an AI attitude attitude_protective against country. Example: GER.ai_attitude_protective_weight@ENG. - ai_attitude_protective_weight@scope[country] + ai_attitude_protective_weight@enum[country_scope_enum] ai_attitude_protective_weight@enum[country_tags] ### Weight for an AI attitude attitude_threatened against country. Example: GER.ai_attitude_threatened_weight@ENG. - ai_attitude_threatened_weight@scope[country] + ai_attitude_threatened_weight@enum[country_scope_enum] ai_attitude_threatened_weight@enum[country_tags] ### Returns 1 if AI wants ally. @@ -73,87 +73,87 @@ values = { ai_desire_ ### AI strategy value activate_crypto against country. Example: GER.ai_strategy_activate_crypto@ENG. - ai_strategy_activate_crypto@scope[country] + ai_strategy_activate_crypto@enum[country_scope_enum] ai_strategy_activate_crypto@enum[country_tags] ### AI strategy value alliance against country. Example: GER.ai_strategy_alliance@ENG. - ai_strategy_alliance@scope[country] + ai_strategy_alliance@enum[country_scope_enum] ai_strategy_alliance@enum[country_tags] ### AI strategy value antagonize against country. Example: GER.ai_strategy_antagonize@ENG. - ai_strategy_antagonize@scope[country] + ai_strategy_antagonize@enum[country_scope_enum] ai_strategy_antagonize@enum[country_tags] ### AI strategy value befriend against country. Example: GER.ai_strategy_befriend@ENG. - ai_strategy_befriend@scope[country] + ai_strategy_befriend@enum[country_scope_enum] ai_strategy_befriend@enum[country_tags] ### AI strategy value conquer against country. Example: GER.ai_strategy_conquer@ENG. - ai_strategy_conquer@scope[country] + ai_strategy_conquer@enum[country_scope_enum] ai_strategy_conquer@enum[country_tags] ### AI strategy value consider_weak against country. Example: GER.ai_strategy_consider_weak@ENG. - ai_strategy_consider_weak@scope[country] + ai_strategy_consider_weak@enum[country_scope_enum] ai_strategy_consider_weak@enum[country_tags] ### AI strategy value contain against country. Example: GER.ai_strategy_contain@ENG. - ai_strategy_contain@scope[country] + ai_strategy_contain@enum[country_scope_enum] ai_strategy_contain@enum[country_tags] ### AI strategy value declare_war against country. Example: GER.ai_strategy_declare_war@ENG. - ai_strategy_declare_war@scope[country] + ai_strategy_declare_war@enum[country_scope_enum] ai_strategy_declare_war@enum[country_tags] ### AI strategy value decrypt_target against country. Example: GER.ai_strategy_decrypt_target@ENG. - ai_strategy_decrypt_target@scope[country] + ai_strategy_decrypt_target@enum[country_scope_enum] ai_strategy_decrypt_target@enum[country_tags] ### AI strategy value dont_defend_ally_borders against country. Example: GER.ai_strategy_dont_defend_ally_borders@ENG. - ai_strategy_dont_defend_ally_borders@scope[country] + ai_strategy_dont_defend_ally_borders@enum[country_scope_enum] ai_strategy_dont_defend_ally_borders@enum[country_tags] ### AI strategy value force_defend_ally_borders against country. Example: GER.ai_strategy_force_defend_ally_borders@ENG. - ai_strategy_force_defend_ally_borders@scope[country] + ai_strategy_force_defend_ally_borders@enum[country_scope_enum] ai_strategy_force_defend_ally_borders@enum[country_tags] ### AI strategy value ignore against country. Example: GER.ai_strategy_ignore@ENG. - ai_strategy_ignore@scope[country] + ai_strategy_ignore@enum[country_scope_enum] ai_strategy_ignore@enum[country_tags] ### AI strategy value ignore_claim against country. Example: GER.ai_strategy_ignore_claim@ENG. - ai_strategy_ignore_claim@scope[country] + ai_strategy_ignore_claim@enum[country_scope_enum] ai_strategy_ignore_claim@enum[country_tags] ### AI strategy value influence against country. Example: GER.ai_strategy_influence@ENG. - ai_strategy_influence@scope[country] + ai_strategy_influence@enum[country_scope_enum] ai_strategy_influence@enum[country_tags] ### AI strategy value invade against country. Example: GER.ai_strategy_invade@ENG. - ai_strategy_invade@scope[country] + ai_strategy_invade@enum[country_scope_enum] ai_strategy_invade@enum[country_tags] ### AI strategy value occupation_policy against country. Example: GER.ai_strategy_occupation_policy@ENG. - ai_strategy_occupation_policy@scope[country] + ai_strategy_occupation_policy@enum[country_scope_enum] ai_strategy_occupation_policy@enum[country_tags] ### AI strategy value prepare_for_war against country. Example: GER.ai_strategy_prepare_for_war@ENG. - ai_strategy_prepare_for_war@scope[country] + ai_strategy_prepare_for_war@enum[country_scope_enum] ai_strategy_prepare_for_war@enum[country_tags] ### AI strategy value protect against country. Example: GER.ai_strategy_protect@ENG. - ai_strategy_protect@scope[country] + ai_strategy_protect@enum[country_scope_enum] ai_strategy_protect@enum[country_tags] ### AI strategy value send_volunteers_desire against country. Example: GER.ai_strategy_send_volunteers_desire@ENG. - ai_strategy_send_volunteers_desire@scope[country] + ai_strategy_send_volunteers_desire@enum[country_scope_enum] ai_strategy_send_volunteers_desire@enum[country_tags] ### AI strategy value support against country. Example: GER.ai_strategy_support@ENG. - ai_strategy_support@scope[country] + ai_strategy_support@enum[country_scope_enum] ai_strategy_support@enum[country_tags] ### Air intel against a target country. example GER.air_intel@ENG. - air_intel@scope[country] + air_intel@enum[country_scope_enum] air_intel@enum[country_tags] ### KR-specific variable to manage tag ambition areas @@ -163,7 +163,7 @@ values = { army_experience ### Army intel against a target country. example GER.army_intel@ENG. - army_intel@scope[country] + army_intel@enum[country_scope_enum] army_intel@enum[country_tags] # Country-scope @@ -175,7 +175,7 @@ values = { historical_capital_for_country ### Civilian intel against a target country. example GER.civilian_intel@ENG. - civilian_intel@scope[country] + civilian_intel@enum[country_scope_enum] civilian_intel@enum[country_tags] ### Total command power of country. @@ -270,7 +270,7 @@ values = { navy_experience ### Navy intel against a target country. example GER.navy_intel@ENG. - navy_intel@scope[country] + navy_intel@enum[country_scope_enum] navy_intel@enum[country_tags] ### Number of armies. @@ -417,7 +417,7 @@ values = { days_since_capitulated ### (Trigger) Checks decryption ratio against a country. Example: decryption_progress@GER. - decryption_progress@scope[country] + decryption_progress@enum[country_scope_enum] decryption_progress@enum[country_tags] ### (Trigger) Compares the estimated navy strength between the scope country and all its enemies. @@ -439,7 +439,7 @@ values = { has_added_tension_amount ### (Trigger) Checks the collaboration in a target country with our currently scoped country. Example has_collaboration@GER. - has_collaboration@scope[country] + has_collaboration@enum[country_scope_enum] has_collaboration@enum[country_tags] ### (Trigger) Check scope country legitimacy 0-100: Example has_legitimacy < 60. @@ -467,7 +467,7 @@ values = { mine_threat ### (Trigger) Will compare towards the amount of divisions a country has control over, if strength matters use has_army_size. - network_national_coverage@scope[country] + network_national_coverage@enum[country_scope_enum] network_national_coverage@enum[country_tags] ### (Trigger) Will compare towards the amount of divisions a country has control over, if strength matters use has_army_size. @@ -1083,11 +1083,11 @@ values = { subjects ### Array of subjects of a tag. - subject_countries@scope[country] + subject_countries@enum[country_scope_enum] subject_countries@enum[country_tags] ### Array of states onwned by subjects of a tag. - subject_states@scope[country] + subject_states@enum[country_scope_enum] subject_states@enum[country_tags] ### Array with country list scores @@ -1127,10 +1127,28 @@ values = { # ======================== # MIO VARIABLES # ======================== - ### How faster is tech researching with mio assigned + ### Value of the modifier stored in the military industrial organization. ex: modifier@military_industrial_organization_research_bonus + modifier + + ### Research bonus of the military industrial organization when assigned to a research slot research_bonus - ### Current number of funds MIO has access to + ### Size of the military industrial organization + size + + ### Number of tasks the military industrial organization is currently assigned to + number_of_currently_assigned_tasks + + ### Funds of the military industrial organization funds + + ### Maximum task capacity of the military industrial organization + max_task_capacity + + ### Number of unlocked traits of the military industrial organization + number_of_unlocked_traits + + ### Number of unused trait points of the military industrial organization + number_of_unused_trait_points } } From db65bf0e3a042f4170d28554eb34f7ba71ba65f7 Mon Sep 17 00:00:00 2001 From: Pelmen323 Date: Tue, 25 Jun 2024 21:02:02 +0400 Subject: [PATCH 2/6] MIO fixes - triggers and effects to iterate over MIOs plus misc fixes --- .../military_industrial_organizations.cwt | 2 +- Config/effects_aat.cwt | 48 +++++++++++++++++++ Config/modifiers.cwt | 2 + Config/shared_enums.cwt | 9 ++++ Config/triggers_aat.cwt | 38 ++++++++++++++- 5 files changed, 96 insertions(+), 3 deletions(-) diff --git a/Config/common/military_industrial_organizations.cwt b/Config/common/military_industrial_organizations.cwt index cfff7629..f3954b1c 100644 --- a/Config/common/military_industrial_organizations.cwt +++ b/Config/common/military_industrial_organizations.cwt @@ -239,7 +239,7 @@ military_industrial_organization = { ### Defines where the trait will be positioned in the tree grid. x=0 y=0 is the top left position. ### Do not reuse the same position twice. position = { - x = float[-9..9] + x = float y = float } ### By default position is the absolute coordinate in the tree grid. diff --git a/Config/effects_aat.cwt b/Config/effects_aat.cwt index 63c5859b..bcba7b9f 100644 --- a/Config/effects_aat.cwt +++ b/Config/effects_aat.cwt @@ -247,6 +247,54 @@ alias[effect:set_mio_task_capacity] = int_variable_field[0..inf] ## scope = military_industrial_organization alias[effect:add_mio_task_capacity] = int_variable_field +### Executes children effects on a random Military Industrial Organisation of the country in scope, that fulfills the "limit" trigger. tooltip=key can be added to override tooltip title +## scope = country +## push_scope = military_industrial_organization +alias[effect:random_military_industrial_organization] = { + ## cardinality = 0..1 + limit = { + alias_name[trigger] = alias_match_left[trigger] + } + ## cardinality = 0..1 + tooltip = localisation + ## error_if_only_match = This is the default value and can be omitted + ## severity = info + ## cardinality = 0..1 + include_invisible = no + ## cardinality = 0..1 + include_invisible = yes + alias_name[effect] = alias_match_left[effect] +} + +### Executes children effects on every Military Industrial Organisation (or "random_select_amount" of random MIOs if specified) of the country in scope, that fulfills the "limit" trigger. tooltip=key can be added to override tooltip title. By default the effects are only displayed once, you may display them for each matching MIO with display_individual_scopes. +## scope = country +## push_scope = military_industrial_organization +alias[effect:every_military_industrial_organization] = { + ## cardinality = 0..1 + limit = { + alias_name[trigger] = alias_match_left[trigger] + } + ## cardinality = 0..1 + tooltip = localisation + ## cardinality = 0..1 + random_select_amount = int + ## error_if_only_match = This is the default value and can be omitted + ## severity = info + ## cardinality = 0..1 + include_invisible = no + ## cardinality = 0..1 + include_invisible = yes + ## error_if_only_match = This is the default value and can be omitted + ## severity = info + ## cardinality = 0..1 + display_individual_scopes = no + ## cardinality = 0..1 + display_individual_scopes = yes + alias_name[effect] = alias_match_left[effect] +} + + + ### Give market access to x ## scope = country alias[effect:give_market_access] = enum[country_tags] diff --git a/Config/modifiers.cwt b/Config/modifiers.cwt index 00d376c6..71971f85 100644 --- a/Config/modifiers.cwt +++ b/Config/modifiers.cwt @@ -1012,4 +1012,6 @@ modifiers = { military_industrial_organization_task_capacity = military_industrial_organization military_industrial_organization_size_up_requirement = military_industrial_organization military_industrial_organization_funds_gain = military_industrial_organization + military_industrial_organization_policy_cost = military_industrial_organization + military_industrial_organization_policy_cooldown = military_industrial_organization } diff --git a/Config/shared_enums.cwt b/Config/shared_enums.cwt index c078f09e..bc8d78cf 100644 --- a/Config/shared_enums.cwt +++ b/Config/shared_enums.cwt @@ -300,4 +300,13 @@ enums = { large_plane_cas_airframe_3 large_plane_cas_airframe_4 } + + enum[country_scope_enum] = { + THIS + ROOT + FROM + PREV + FROM.FROM + FROM.FROM.FROM + } } diff --git a/Config/triggers_aat.cwt b/Config/triggers_aat.cwt index da986ff9..2f38fd8e 100644 --- a/Config/triggers_aat.cwt +++ b/Config/triggers_aat.cwt @@ -3,7 +3,7 @@ ## scope = state alias[trigger:is_one_state_island] = bool -### Checks if current MIO is the provided one +### Checks if the Military Industrial Organisation in scope matches the input token ## scope = military_industrial_organization alias[trigger:is_military_industrial_organization] = @@ -23,10 +23,14 @@ alias[trigger:has_mio_equipment_type] = ## scope = military_industrial_organization alias[trigger:has_mio_equipment_type] = -### Checks if tag has specific MIO +### Checks if the Country in scope has a Military Industrial Organisation matching the input token. Can use variable as input ## scope = country alias[trigger:has_military_industrial_organization] = +### Checks if the Country in scope has a Military Industrial Organisation matching the input token. Can use variable as input +## scope = country +alias[trigger:has_military_industrial_organization] = value[variable] + ### Checks if MIO is available AND visible ## scope = military_industrial_organization alias[trigger:is_mio_available] = bool @@ -120,3 +124,33 @@ alias[trigger:has_mio_research_category] = ### Checks if the Military Industrial Organisation in scope has an allowed matching the input token, which is currently attached to the MIO ## scope = military_industrial_organization alias[trigger:has_mio_policy_active] = + +### Checks if all Military Industrial Organisations of the Country in scope match the triggers. tooltip=key can be defined to override title +## scope = country +## push_scope = military_industrial_organization +alias[trigger:all_military_industrial_organization] = { + ## cardinality = 0..1 + tooltip = localisation + ## error_if_only_match = This is the default value and can be omitted + ## severity = info + ## cardinality = 0..1 + include_invisible = no + ## cardinality = 0..1 + include_invisible = yes + alias_name[trigger] = alias_match_left[trigger] +} + +### Checks if at least one Military Industrial Organisation of the Country in scope matches the triggers. tooltip=key can be defined to override title +## scope = country +## push_scope = military_industrial_organization +alias[trigger:any_military_industrial_organization] = { + ## cardinality = 0..1 + tooltip = localisation + ## error_if_only_match = This is the default value and can be omitted + ## severity = info + ## cardinality = 0..1 + include_invisible = no + ## cardinality = 0..1 + include_invisible = yes + alias_name[trigger] = alias_match_left[trigger] +} From 9ed306a1a6a46125f5e0025ed1d9d6d1ad1bc2a1 Mon Sep 17 00:00:00 2001 From: Pelmen323 Date: Wed, 26 Jun 2024 03:21:14 +0400 Subject: [PATCH 3/6] Add unit medals support --- Config/common/unit_medals.cwt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Config/common/unit_medals.cwt diff --git a/Config/common/unit_medals.cwt b/Config/common/unit_medals.cwt new file mode 100644 index 00000000..889990fe --- /dev/null +++ b/Config/common/unit_medals.cwt @@ -0,0 +1,32 @@ +types = { + type[unit_medal] = { + skip_root_key = unit_medals + path = "game/common/unit_medals" + path_strict = yes + } +} + +## replace_scope = { root = country this = country } +unit_medal = { + ## cardinality = 0..1 + available = { + ## cardinality = ~1..inf + alias_name[trigger] = alias_match_left[trigger] + } + + frame = int + icon = + + cost = @cost + cost = int + + ## cardinality = 0..1 + unit_modifiers = { + alias_name[modifier] = alias_match_left[modifier] + } + + ## cardinality = 0..1 + one_time_effect = { + alias_name[effect] = alias_match_left[effect] + } +} \ No newline at end of file From c5a71b2a879280b06b119eb6729b2c81a6f2ca5b Mon Sep 17 00:00:00 2001 From: Pelmen323 Date: Wed, 26 Jun 2024 03:22:18 +0400 Subject: [PATCH 4/6] Add the ability to compare ideology popularity using other ideologies --- Config/triggers.cwt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Config/triggers.cwt b/Config/triggers.cwt index b8d9189b..84d3279a 100644 --- a/Config/triggers.cwt +++ b/Config/triggers.cwt @@ -2304,6 +2304,10 @@ alias[trigger:] = int_variable_field ## scope = country alias[trigger:] = variable_field +### Checks ideology popularity. +## scope = country +alias[trigger:] = + ### Changes scope to opposing army/navy. ## scope = { unit_leader combat } alias[trigger:opponent] = { alias_name[trigger] = alias_match_left[trigger] } From 1de306c3d87934fa33aafcb205100e3f94dd3580 Mon Sep 17 00:00:00 2001 From: Pelmen323 Date: Wed, 26 Jun 2024 03:23:48 +0400 Subject: [PATCH 5/6] Add some missing unit-related triggers and effects --- Config/effects_aat.cwt | 2 -- Config/effects_bba.cwt | 15 +++++++++++++++ Config/triggers_bba.cwt | 10 +++++++++- Config/triggers_nsb.cwt | 4 ++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Config/effects_aat.cwt b/Config/effects_aat.cwt index bcba7b9f..483ed8b3 100644 --- a/Config/effects_aat.cwt +++ b/Config/effects_aat.cwt @@ -293,8 +293,6 @@ alias[effect:every_military_industrial_organization] = { alias_name[effect] = alias_match_left[effect] } - - ### Give market access to x ## scope = country alias[effect:give_market_access] = enum[country_tags] diff --git a/Config/effects_bba.cwt b/Config/effects_bba.cwt index 49139b61..c0cd2e23 100644 --- a/Config/effects_bba.cwt +++ b/Config/effects_bba.cwt @@ -166,3 +166,18 @@ alias[effect:remove_civil_war_target] = enum[country_tags] ### Destroys the currently-scoped division. ## scope = unit alias[effect:destroy_unit] = bool + +### Add history entry to a unit in scope +## scope = unit +alias[effect:add_history_entry] = { + key = localisation + subject = localisation + ### Allow medal award + allow = bool +} + +### Add a medal to latest history entry of a unit in scope. Check 'add_history_entry' to create a new entry +## scope = unit +alias[effect:add_unit_medal_to_latest_entry] = { + unit_medals = +} diff --git a/Config/triggers_bba.cwt b/Config/triggers_bba.cwt index ced6785d..79837181 100644 --- a/Config/triggers_bba.cwt +++ b/Config/triggers_bba.cwt @@ -189,4 +189,12 @@ alias[trigger:pc_is_state_outside_influence_for_winner] = enum[country_tags] ### Compares the amount of turns that have passed during the peace conference with a number. ## scope = any -alias[trigger:pc_turn] = int \ No newline at end of file +alias[trigger:pc_turn] = int + +### Check scope unit strength status 0-1: Example unit_strength < 1 +## scope = unit +alias[trigger:unit_strength] = variable_field[0..1] + +### Check scope unit organization status 0-1: Example unit_organization < 1 +## scope = unit +alias[trigger:unit_organization] = variable_field[0..1] diff --git a/Config/triggers_nsb.cwt b/Config/triggers_nsb.cwt index 5cb81a60..5c603c36 100644 --- a/Config/triggers_nsb.cwt +++ b/Config/triggers_nsb.cwt @@ -389,3 +389,7 @@ alias[trigger:any_country_with_core] = { ### Check if character has specific advisor role ## scope = { character unit_leader } alias[trigger:has_advisor_role] = enum[allowed_advisor_role] + +### Check amount of supply nodes +## scope = country +alias[trigger:num_of_supply_nodes] = int_variable_field From 552f2ead2719579d30a9088ce205603a038e6ade Mon Sep 17 00:00:00 2001 From: Pelmen323 Date: Wed, 26 Jun 2024 03:24:15 +0400 Subject: [PATCH 6/6] Add python scripts for checking missing triggers and effects --- tests/test_check_missing_effects.py | 33 ++++++++++++++++++++++++++++ tests/test_check_missing_triggers.py | 33 ++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/test_check_missing_effects.py create mode 100644 tests/test_check_missing_triggers.py diff --git a/tests/test_check_missing_effects.py b/tests/test_check_missing_effects.py new file mode 100644 index 00000000..e2ccf8be --- /dev/null +++ b/tests/test_check_missing_effects.py @@ -0,0 +1,33 @@ +import re +import glob +import json + +path_to_config = "Config\\" +path_to_documentation = "Config\\script_documentation.json" + +# 1 Extract effects from documentation +documentation_dict = json.load(open(path_to_documentation)) +list_with_effects_documentation = [i for i in documentation_dict['effects'].keys()] + + +# 2 Extract effects from config files +list_with_effects_config = [] +effect_pattern = r'alias\[effect:(.*?)\]' +for filename in glob.iglob(path_to_config + "**/*.cwt", recursive=True): + with open(filename, 'r') as text_file: + config_file = text_file.read() + + if 'alias[effect:' in config_file: + pattern_matches = re.findall(effect_pattern, config_file) + if len(pattern_matches) > 0: + for match in pattern_matches: + list_with_effects_config.append(match) + +# 3 Perform a comparison +list_with_effects_config = set(list_with_effects_config) +results_missing_effects = [i for i in list_with_effects_documentation if i not in list_with_effects_config] + +if len(results_missing_effects) > 0: + for i in results_missing_effects: + print(f'- [] - {i}') + raise Exception("There are effects in documentation file that are not present in .cwt files") diff --git a/tests/test_check_missing_triggers.py b/tests/test_check_missing_triggers.py new file mode 100644 index 00000000..18930bd2 --- /dev/null +++ b/tests/test_check_missing_triggers.py @@ -0,0 +1,33 @@ +import re +import glob +import json + +path_to_config = "Config\\" +path_to_documentation = "Config\\script_documentation.json" + +# 1 Extract triggers from documentation +documentation_dict = json.load(open(path_to_documentation)) +list_with_triggers_documentation = [i for i in documentation_dict['triggers'].keys()] + + +# 2 Extract triggers from config files +list_with_triggers_config = [] +effect_pattern = r'alias\[trigger:(.*?)\]' +for filename in glob.iglob(path_to_config + "**/*.cwt", recursive=True): + with open(filename, 'r') as text_file: + config_file = text_file.read() + + if 'alias[trigger:' in config_file: + pattern_matches = re.findall(effect_pattern, config_file) + if len(pattern_matches) > 0: + for match in pattern_matches: + list_with_triggers_config.append(match) + +# 3 Perform a comparison +list_with_triggers_config = set(list_with_triggers_config) +results_missing_triggers = [i for i in list_with_triggers_documentation if i not in list_with_triggers_config] + +if len(results_missing_triggers) > 0: + for i in results_missing_triggers: + print(f'- [] - {i}') + raise Exception("There are triggers in documentation file that are not present in .cwt files")