Esempio n. 1
0
def fill_tag_array(internal_path, cosmetics):
    # 0 = just normal
    # 1 = just cosmetic
    # 2 = both

    tags = []
    common_path = path.join(internal_path, "common")
    event_path = path.join(internal_path, 'events')
    tree_path = path.join(common_path, "national_focus")
    decisions_path = path.join(common_path, 'decisions')
    scripted_triggers_path = path.join(common_path, "scripted_effects")

    cosmetic_tag_dirs = [
        event_path, decisions_path, tree_path, scripted_triggers_path
    ]

    #Find Normal Tags
    tags_path = path.join(path.join(common_path, 'country_tags'),
                          '00_countries.txt')
    file = open_file(tags_path)
    #print("Reading: " + file.name)
    lines = file.readlines()

    if cosmetics != 1:
        for string in lines:
            temp_string = string[:3]
            if '#' in string:
                string = string.split('#')[0]
            if '#' not in temp_string and '\r\n' != string:
                tags.append(string[:3])
                #print("Found TAG: " + tags[counter])

    #Find Cosmetic Tags
    if cosmetics != 0:
        for dirs in cosmetic_tag_dirs:
            for filename in listdir(dirs):
                if 'categories' in filename:
                    continue
                file = open_file(path.join(dirs, filename))
                lines = file.readlines()
                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:
                            tags.append(temp_string)
                            #print("Found TAG: " + temp_string)
    return tags
def files_as_strings_from_path_gen(path):
    for directory, subdirs, files in os.walk(path):
        for file in files:
            current_file = open_file(directory + '/' + file)
            contents = current_file.read()
            contents = remove_comments(contents)
            yield contents, file
Esempio n. 3
0
def create_state_dict(path, statedict, output_file):
    returndict = statedict
    path = os.path.join(path, 'history', 'states')
    for filename in os.listdir(path):
        idname = True
        try:
            fileid = int(filename.split("-")[0])
        except:
            idname = False
        file = open_file(os.path.join(path, filename))
        line = file.readline()
        while line:
            if ('id = ') in line:
                try:
                    id = int(line.split(' = ')[1].strip().split(" ")[0])
                except:
                    id = int(line.split(' = ')[1].strip())
                break
            line = file.readline()
        if idname:
            if id != fileid:
                result = "In " + filename + " the state id is " + str(
                    id) + " instead of " + str(fileid)
                #print(result)
                output_file.write(result)
        returndict[str(id)] = True
    return returndict
Esempio n. 4
0
def check(path, output_file, sub_path, encoding):
    path += sub_path
    for filename in listdir(path):
        current_line = 0
        file = open_file(path + '\\' + filename)
        line = file.readline()
        current_line += 1
        ok = 0
        is_in_general = 0
        while line:
            if 'create_corps_commander' in line or 'create_field_marshal' in line:
                is_in_general = 1
            if "#mw thinks this is a land commander" in line:
                output_file.write(
                    sub_path + '\\' + filename +
                    " there's an unchanged KR general around line " +
                    str(current_line) + '\n')
            if "skill =" in line and "#" not in line and is_in_general == 1:
                ok = 1
            if "attack_skill" in line or "defense_skill" in line \
                    or "planning_skill" in line or "logistics_skill" in line and ok == 1:
                ok = 0
                is_in_general = 0
            if "}" in line and ok == 1:
                output_file.write(sub_path + '\\' + filename +
                                  " there's an old general around line " +
                                  str(current_line) + '\n')
                is_in_general = 0
                ok = 0
            line = file.readline()
            current_line += 1
Esempio n. 5
0
def check_for_missing_cores(path, output_file):
    path += "\\history\\states"
    filelist = []
    for filename in listdir(path):
        #this loops through all the states
        hascore = False
        current_line = 0
        file = open_file(path + '\\' + filename)
        line = file.readline()
        current_line += 1
        while line:
            if ('add_core_of = ' in line):
                #this means there is a core in the state
                hascore = True
            line = file.readline()
            current_line += 1
        if hascore == False:
            #all states without cores are added to the list
            filelist.append(filename)
    i = 0
    while (i < len(filelist)):
        result = "The state in " + filelist[i] + " does not have any cores\n"
        print(result)
        output_file.write(result)
        i += 1
def check_ideologies(path, usesvanilla, output_file):
    debug = False
    ideologydict = {}
    linedict = {}
    filedict = {}
    defaultideologies = ['democratic', 'communism', 'fascism', 'neutrality']
    filterstrings = []
    thingstripped = 'ideology'
    searchstrings = ['ideology = ', 'has_government =', 'ruling_party = ']
    ideologydict, linedict, filedict = search_effects(ideologydict, linedict,
                                                      filedict, path,
                                                      searchstrings,
                                                      filterstrings,
                                                      thingstripped)
    ideologypath = os.path.join(path, 'common', 'ideologies')
    file = open_file(os.path.join(ideologypath, '00_ideologies.txt'))
    line = file.readline()
    depth = 0
    istypes = False
    ideologydict['ROOT'] = True
    if usesvanilla:
        for each in defaultideologies:
            ideologydict[each] = True
    while line:
        line = file.readline()
        if depth == 1 and '= {' in line:
            ideology = line.split(' = {')[0].strip()
            if debug is True:
                print(ideology)
            if ideology in ideologydict:
                ideologydict[ideology] = True
        if depth == 2 and 'types = {' in line:
            istypes = True
        if depth == 3 and '= {}' in line and istypes:
            ideology = line.split('= {}')[0].strip()
            if debug is True:
                print(ideology)
            if ideology in ideologydict:
                ideologydict[ideology] = True

        if '{' in line:
            depth = depth + 1
        if '}' in line:
            depth = depth - 1
        if depth == 2 and istypes:
            istypes = False
    for item in ideologydict:
        if ideologydict[item] is False:
            result = "The ideology " + item + " referenced in " + filedict[
                item] + " on line " + str(linedict[item]) + " is not defined"
            if debug is True:
                print(result)
            output_file.write(result)
Esempio n. 7
0
def check_for_double_locs(path,
                          output_file,
                          check_double_loc=True,
                          check_double_spaces=True):
    path = os.path.join(path, "localisation")
    list_loc = {}
    subfolderlist = []
    for filename in os.listdir(path):
        if '.yml' in filename:
            file = open_file(os.path.join(path, filename))
            list_loc = linecheck(file, output_file, filename, list_loc, '',
                                 check_double_loc, check_double_spaces)
        else:
            subfolderlist.append(filename)
    for subfolder in subfolderlist:
        newpath = os.path.join(path, subfolder)
        for filename in os.listdir(newpath):
            if '.yml' in filename:
                file = open_file(os.path.join(newpath, filename))
                list_loc = linecheck(file, output_file, filename, list_loc,
                                     subfolder, check_double_loc,
                                     check_double_spaces)
Esempio n. 8
0
def create_search_dict(maindict, linedict, filedict, path, searchstrings,
                       filterstrings, thingstripped):
    filterstrings.append('#')  #ignore comments
    for filename in listdir(path):
        if ".txt" in filename:  #this makes sure it's not a folder
            current_line = 0
            file = open_file(path + '\\' + filename)
            line = file.readline()
            current_line += 1
            while line:
                i = 0
                isin = False
                while i < len(searchstrings):
                    if searchstrings[i] in line:
                        isin = True  #checking to see if it has stuff that means it should be checked
                    i = i + 1
                i = 0
                while i < len(filterstrings):
                    if filterstrings[i] in line:
                        isin = False  #checking to see if it's being filtered for one reason or another
                    i = i + 1
                if isin:
                    #this means line is oob being called, so we need to add it to the dictionary
                    if thingstripped == 'oob':
                        maintext = stripOOB(line)
                        if maintext != 'empty' and maintext != "" and (
                                maintext in maindict) == False:
                            maindict, linedict, filedict = insertdict(
                                maindict, linedict, filedict, maintext,
                                current_line, filename)
                    elif thingstripped == 'focus':
                        if 'has_completed_focus' in line:
                            maintext = strip_focus(line, 1,
                                                   'has_completed_focus =')
                            if (maintext
                                    in maindict) == False and maintext != "":
                                maindict, linedict, filedict = insertdict(
                                    maindict, linedict, filedict, maintext,
                                    current_line, filename)
                        else:
                            linelist = line.split(' focus =')
                            for posfocus in linelist:
                                maintext = strip_focus(posfocus, 0, '=')
                                if (maintext in maindict
                                    ) == False and maintext != "":
                                    maindict, linedict, filedict = insertdict(
                                        maindict, linedict, filedict, maintext,
                                        current_line, filename)
                line = file.readline()
                current_line += 1
    return maindict, linedict, filedict
Esempio n. 9
0
def actually_check_for_missing_focus(path, focusdict):
    #this heads through the files. Every time it sees a focus, it sets that focus's value in returndict to true
    returndict = focusdict
    for filename in listdir(path):
        file = open_file(os.path.join(path, filename))
        line = file.readline()
        while line:
            if 'id = ' in line and ('event'
                                    in line) == False and ('.'
                                                           in line) == False:
                focustext = strip_focus(line, 1, '=')
                returndict[focustext] = True
            line = file.readline()
    return returndict
Esempio n. 10
0
def find_locs(path):
    path = os.path.join(path, "localisation")
    locset = {}
    #print("finding scripted triggers")
    for filename in os.listdir(path):
        #print(filename)
        if '.yml' in filename:
            file = open_file(os.path.join(path, filename))
            for line in file:
                if ':0' in line:
                    loc = line.split(':0')[0].strip()
                    loc = loc.strip()
                    #print(loc)
                    locset.add(loc)
    return locset
Esempio n. 11
0
def create_general_list(originalpath, output_file):
    commonpath = os.path.join(originalpath, 'common')
    print("Printing general list")
    #this heads through the files. Every time it sees a general, it prints that general's ID and the file the general was found in in order to produce that list I was asked for earlier
    pathlist = [
        os.path.join(originalpath, 'history', "countries"),
        os.path.join(originalpath, "events"),
        os.path.join(commonpath, "national_focus"),
        os.path.join(commonpath, "scripted_effects"),
        os.path.join(commonpath, "decisions")
    ]
    allgeneraldict = {}
    SettingTraits = False
    for path in pathlist:
        for filename in os.listdir(path):
            if ".txt" in filename:
                file = open_file(os.path.join(path, filename))
                line = file.readline()
                ingeneral = False
                while line:
                    if ingeneral == False:
                        if 'create_corps_commander' in line or 'create_field_marshal' in line or 'create_navy_leader' in line:
                            ingeneral = True
                    else:
                        if 'traits =' in line:
                            SettingTraits = True
                        if '}' in line:
                            if SettingTraits == False:
                                ingeneral = False
                            else:
                                SettingTraits = False
                        if 'id =' in line:
                            generalid = strip_created_general(line)
                            if generalid != '':
                                #print(ingeneral)
                                if (generalid in allgeneraldict) == False:
                                    splittext = originalpath
                                    printtext = path + "\\" + filename + " uses general id " + generalid + '\n'
                                    result = printtext.split(splittext)[1]
                                    if '\n' in result == False:
                                        result += '\n'
                                    #print(result)
                                    output_file.write(result)
                                    allgeneraldict[generalid] = True
                    line = file.readline()
Esempio n. 12
0
def check(path, output_file, sub_path):
    original_path = path
    path += sub_path
    for filename in listdir(path):
        if (isdir(path + '\\' + filename)):
            check(original_path, output_file, sub_path + '\\' + filename)
            continue
        current_line = 0
        file = open_file(path + '\\' + filename)
        line = file.readline()
        current_line += 1
        stack = []
        while line:
            for letter in line:
                if letter == '#':
                    break
                elif letter == '(':
                    stack.append(')')
                elif letter == '[':
                    stack.append(']')
                elif letter == '{':
                    stack.append('}')
                elif letter == ')' or letter == ']' or letter == '}':
                    if (len(stack) == 0):
                        output_file.write(sub_path + '\\' + filename +
                                          " Brackets: Not expected '" +
                                          letter + "' around line " +
                                          str(current_line) + '\n')
                    else:
                        letterPop = stack.pop()
                        if (letterPop != letter):
                            output_file.write(sub_path + '\\' + filename +
                                              " Brackets: Expecting: '" +
                                              letterPop + "' but found '" +
                                              letter + "' around line " +
                                              str(current_line) + '\n')
            line = file.readline()
            current_line += 1
        if len(stack) > 0:
            output_file.write(
                sub_path + '\\' + filename + " Brackets: there are " +
                str(len(stack)) +
                " opening bracket(s) without closing bracket(s)\n")
Esempio n. 13
0
def find_scripted_triggers(path):
    path = os.path.join(path, "common", 'scripted_triggers')
    triggerlist = []
    #print("finding scripted triggers")
    for filename in os.listdir(path):
        #print(filename)
        if '.txt' in filename:
            file = open_file(os.path.join(path, filename))
            depth = 0
            for line in file:
                if depth == 0 and '=' in line:
                    trigger = line.split('=')[0].strip()
                    if ("#" in trigger) == False:
                        #print(trigger)
                        triggerlist.append(trigger)
                if '{' in line:
                    depth = depth + 1
                if '}' in line:
                    depth = depth - 1
    return triggerlist
Esempio n. 14
0
def actually_check_for_missing_general(originalpath, generaldict):
    commonpath = os.path.join(originalpath, 'common')
    #this heads through the files. Every time it sees a general, it sets that general's value in returndict to true
    pathlist = [
        os.path.join(originalpath, 'history', "countries"),
        os.path.join(originalpath, "events"),
        os.path.join(commonpath, "national_focus"),
        os.path.join(commonpath, "scripted_effects"),
        os.path.join(commonpath, "decisions")
    ]
    returndict = generaldict
    SettingTraits = False
    for path in pathlist:
        for filename in os.listdir(path):
            if ".txt" in filename:
                file = open_file(os.path.join(path, filename))
                line = file.readline()
                ingeneral = False
                while line:
                    if ingeneral == False:
                        if 'create_corps_commander' in line or 'create_field_marshal' in line or 'create_navy_leader' in line:
                            ingeneral = True
                    else:
                        if 'traits =' in line:
                            SettingTraits = True
                        if '}' in line:
                            if SettingTraits == False:
                                ingeneral = False
                            else:
                                SettingTraits = False
                        if 'id =' in line:
                            generalid = strip_created_general(line)
                            if generalid != '':
                                #print(ingeneral)
                                #print(path + '\\' + filename)
                                #print(generalid)
                                returndict[generalid] = True
                            ingeneral = False
                    line = file.readline()
    return returndict
def check_for_double_locs(path, output_file):
    t0 = time.time()
    path += "\\localisation"
    list_loc = {}
    for filename in listdir(path):
        current_line = 0
        file = open_file(path + '\\' + filename)
        line = file.readline()
        current_line += 1
        if "l_english" in line:
            line = file.readline()
            current_line += 1
            while line:
                line = line.strip()
                i = line.find(':')
                if i != -1 and line[0] != '#':
                    loc = line[:i]
                    if loc in list_loc:
                        output_file.write("Duplicated Loc: '" + loc +
                                          "' in: " + list_loc[loc] +
                                          " and in: '\\localisation\\" +
                                          filename + "' at line " +
                                          str(current_line) + "\n")
                    else:
                        list_loc[
                            loc] = "'\\localisation\\" + filename + "' at line " + str(
                                current_line)
                    #if "  " in line[i+1:]:
                    if check_and_strip(line, i) is True:
                        #print("Double Spaces in Loc: '" + loc + "' in: '\\localisation\\" + filename + "' at line " + str(current_line))
                        output_file.write("Double Spaces in Loc: '" + loc +
                                          "' in: '\\localisation\\" +
                                          filename + "' at line " +
                                          str(current_line) + "\n")
                line = file.readline()
                current_line += 1
    t0 = time.time() - t0
    print("Time taken for Locs script: " + (t0 * 1000).__str__() + " ms")
Esempio n. 16
0
def check_for_naval_aviation_tech(path, output_file):
    debug = False
    path = os.path.join(path, 'history', 'countries')

    for filename in os.listdir(path):
        #this creates dicts of tags that use various techs and sees if they have the prereqs for them
        if ".txt" in filename:
            #this is the most bullshit name for a dictionary ever, but in my defense, f**k you
            array = {
                'nav_av_one': False,
                'nav_av_two': False,
                'nav_av_three': False,
                'nav_infra_one': False,
                'nav_infra_two': False,
                'nav_infra_three': False,
                'carrier_one': False,
                'carrier_two': False,
                'carrier_three': False,
                'heavy_carrier_one': False,
                'heavy_cruiser_one': False,
                'heavy_cruiser_three': False,
                'heavy_cruiser_five': False,
                'dreadnought_one': False,
                'dreadnought_four': False,
                'battleship_four': False
            }
            file = open_file(os.path.join(path, filename))
            line = file.readline()
            while line:
                for key in array:
                    if key in line:
                        array[key] = True
                line = file.readline()
            result = ""
            navavresult = True
            if array['nav_av_one'] is False and (
                    array['carrier_one'] == True or array['carrier_two']
                    or array['carrier_three'] or array['heavy_carrier_one']):
                result = filename + ' does not have nav_av_one but does have some form of naval aviation.\n'
            elif array['nav_av_two'] is False and (array['carrier_two']
                                                   or array['carrier_three'] or
                                                   array['heavy_carrier_one']):
                result = filename + ' does not have nav_av_two but does have carrier 2 or higher, or heavy carriers\n'
            elif array['nav_av_three'] is False and (
                    array['carrier_three'] or array['heavy_carrier_one']):
                result = filename + ' does not have nav_av_three but does have carrier 3 or higher, or heavy carriers\n'
            else:
                navavresult = False
            if navavresult:
                if debug:
                    print(result)
                output_file.write(result)

            infresult = True
            if array['nav_infra_one'] is False and (
                    array['carrier_two'] or array['carrier_three']
                    or array['heavy_carrier_one'] or array['heavy_cruiser_one']
                    or array['heavy_cruiser_three']
                    or array['heavy_cruiser_five'] or array['dreadnought_one']
                    or array['dreadnought_four'] or array['battleship_four']):
                result = filename + ' does not have nav_infra_one but does have naval tech that requires it.\n'
            elif array['nav_infra_two'] is False and (
                    array['carrier_three'] or array['heavy_carrier_one']
                    or array['heavy_cruiser_three']
                    or array['heavy_cruiser_five'] or array['dreadnought_one']
                    or array['dreadnought_four'] or array['battleship_four']):
                result = filename + ' does not have nav_infra_two but does have naval tech that requires it.\n'
            elif array['nav_infra_three'] is False and (
                    array['heavy_carrier_one'] or array['heavy_cruiser_five']
                    or array['dreadnought_four'] or array['battleship_four']):
                result = filename + ' does not have nav_infra_three but does have naval tech that requires it.\n'
            else:
                infresult = False
            if infresult:
                if debug:
                    print(result)
                output_file.write(result)
Esempio n. 17
0
def create_search_dict(maindict, linedict, filedict, path, searchstrings,
                       filterstrings, thingstripped, **kwargs):
    filterstrings.append('#')  #ignore comments
    debug = False
    focussearch = False
    eventsearch = False
    techsearch = False
    needdepth = False
    decisionsearch = False
    skipfiles = []
    try:
        skipfiles = kwargs.get('skipfiles')
        for name in skipfiles:
            break
        filterfiles = True
    except:
        filterfiles = False
    if thingstripped == 'lockey':
        if "id =" in searchstrings:
            focussearch = True
        elif 'events' in path:
            eventsearch = True
        elif 'technologies' in path:
            techsearch = True
        elif 'decisions' in path:
            decisionsearch = True
    if focussearch == True or techsearch == True or decisionsearch == True:
        needdepth = True
    for filename in os.listdir(path):
        shouldcontinue = False
        if ".txt" in filename:  #this makes sure it's not a folder
            if filterfiles:  #checking to make sure it's not in a file we're not supposed to check
                for name in skipfiles:
                    if name == filename:
                        #print("in should continue for " + filename)
                        shouldcontinue = True
            if shouldcontinue == True:
                continue
            hasoccured = False
            eventyes = False
            current_line = 0
            file = open_file(os.path.join(path, filename))
            line = file.readline()
            current_line += 1
            eventdeep = 0
            nextline = False
            while line:
                i = 0
                foundstring = 0
                isin = False
                while i < len(searchstrings):
                    if needdepth:
                        if 'event' in line:
                            eventyes = True
                        if '{' in line:
                            eventdeep = eventdeep + line.count('{')
                    if searchstrings[i] in line:
                        try:
                            searchstrings2 = kwargs.get('searchstrings2')
                            for item in searchstrings2:
                                if item in line:
                                    isin = True
                                    foundstring = i
                        except TypeError:
                            foundstring = i
                            isin = True  #checking to see if it has stuff that means it should be checked
                    if needdepth:
                        if '}' in line:
                            eventdeep = eventdeep - line.count('}')
                        if focussearch == True:
                            if eventyes == True:
                                isin = False
                            if eventdeep == 0:
                                eventyes = False
                        elif techsearch == True:
                            if eventdeep != 3:
                                isin = False
                            if nextline == True:
                                isin = True
                                foundstring = i
                        elif decisionsearch == True:
                            if eventdeep != 2:
                                isin = False
                    i = i + 1
                i = 0
                while i < len(filterstrings):
                    if filterstrings[i] in line:
                        isin = False  #checking to see if it's being filtered for one reason or another
                    i = i + 1
                if isin:
                    #this means line is a thing being called, so we need to add it to the dictionary
                    if thingstripped == 'lockey':
                        if focussearch == True:
                            if hasoccured == True:
                                maintext = eventlocstrip(line)
                                if (
                                        maintext in maindict
                                ) == False and maintext != 'yes' and maintext != 'no':
                                    #print(maintext)
                                    maindict, linedict, filedict = insertdict(
                                        maindict,
                                        linedict,
                                        filedict,
                                        maintext,
                                        current_line,
                                        filename,
                                        path,
                                        desc=True)
                            else:
                                hasoccured = True
                        elif eventsearch == True:
                            maintext = line.split(' = ')[1].strip()
                            maindict, linedict, filedict = insertdict(
                                maindict, linedict, filedict, maintext,
                                current_line, filename, path)
                        elif techsearch == True:
                            if nextline == False:
                                #print("nextline to true")
                                nextline = True
                            else:
                                maintext = line.strip()
                                #print(maintext)
                                maindict, linedict, filedict = insertdict(
                                    maindict,
                                    linedict,
                                    filedict,
                                    maintext,
                                    current_line,
                                    filename,
                                    path,
                                    desc=True)
                                nextline = False
                        elif decisionsearch == True:
                            maintext = line.split(' = {')[0].strip()
                            #print(maintext)
                            maindict, linedict, filedict = insertdict(
                                maindict,
                                linedict,
                                filedict,
                                maintext,
                                current_line,
                                filename,
                                path,
                                desc=True)
                    elif thingstripped == 'oob':
                        maintext = stripOOB(line)
                        #print(maintext)
                        if maintext != 'empty' and maintext != "" and (
                                maintext in maindict) == False:
                            maindict, linedict, filedict = insertdict(
                                maindict, linedict, filedict, maintext,
                                current_line, filename, path)
                    elif thingstripped == 'states':
                        maintext = line.split(' = ')[1].strip()
                        if maintext.isdigit():
                            maindict, linedict, filedict = insertdict(
                                maindict, linedict, filedict, maintext,
                                current_line, filename, path)
                    elif thingstripped == 'general':
                        maintext = stripGeneral(line)
                        if maintext != 'empty' and maintext != "" and (
                                maintext in maindict) == False:
                            #print(maintext)
                            maindict, linedict, filedict = insertdict(
                                maindict, linedict, filedict, maintext,
                                current_line, filename, path)
                    elif thingstripped == '=no':
                        maindict, linedict, filedict = insertdict(
                            maindict, linedict, filedict, line, current_line,
                            filename, path)
                    elif thingstripped == 'focus':
                        if 'has_completed_focus' in line:
                            maintext = strip_focus(line, 1,
                                                   'has_completed_focus =')
                            if (maintext
                                    in maindict) == False and maintext != "":
                                maindict, linedict, filedict = insertdict(
                                    maindict, linedict, filedict, maintext,
                                    current_line, filename, path)
                        else:
                            linelist = line.split(' focus =')
                            for posfocus in linelist:
                                maintext = strip_focus(posfocus, 0, '=')
                                if (maintext in maindict
                                    ) == False and maintext != "":
                                    maindict, linedict, filedict = insertdict(
                                        maindict, linedict, filedict, maintext,
                                        current_line, filename, path)
                    elif thingstripped == 'ideology':
                        if debug:
                            print("line is " + line + " foundstring is " +
                                  str(foundstring))
                        text = line.split(
                            searchstrings[foundstring])[1].split()[0].split(
                                '}')[0]
                        if debug:
                            print(text)
                        maindict, linedict, filedict = insertdict(
                            maindict, linedict, filedict, text, current_line,
                            filename, path)

                line = file.readline()
                current_line += 1
    return maindict, linedict, filedict
Esempio n. 18
0
def check_for_name_lists(file_path, output_file):
    unit_types = [
        "light_armor", "medium_armor", "heavy_armor", "modern_armor",
        "paratrooper", "marine", "mountaineers", "infantry", "cavalry",
        "motorized", "mechanized"
    ]
    tags = list()

    # Step 1: Read the custom battalion types

    aux_path = file_path + "\\common\\units"

    for filename in listdir(aux_path):
        if path.isfile(path.join(aux_path, filename)):
            file = open_file(path.join(aux_path, filename))
            line = file.readline()
            level = 0
            unitnameset = False
            while line:

                if level == 1:
                    split_line = re.split(' |\t', line)
                    for word in split_line:
                        if word.isalpha():
                            unit_name = word
                            unitnameset = True
                            break

                if level == 2 and "group =" in line and unitnameset:
                    if "support" not in line and unit_name not in unit_types:
                        unit_types.append(unit_name)

                if '{' in line:
                    level = level + 1

                if '}' in line:
                    level = level - 1

                line = file.readline()

    # Step 2: read ALL THE TAGS
    commonpath = path.join(file_path, "common")
    aux_path = path.join(commonpath, "country_tags")

    file = open_file(path.join(aux_path, "00_countries.txt"))
    line = file.readline()

    while line:
        split_line = re.split(' |\t', line)
        if '#' not in split_line[0]:
            if split_line[0].isalpha():
                tags.append(split_line[0])
        line = file.readline()

    # Step 3: create shadow name lists for all tags to be removed when found

    tag_name_lists = {}

    for tag in tags:
        tag_name_lists[tag] = {}
        for unit_type in unit_types:
            tag_name_lists[tag][unit_type] = 1

    # Step 4: Start reading namelist files, to remove unit types as needed

    aux_path = path.join(commonpath, 'units', 'names_divisions')
    for filename in listdir(aux_path):
        level = 0
        file = open_file(path.join(aux_path, filename))
        line = file.readline()
        current_tags = list()
        current_unit_types = list()

        while line:
            if 'division_types' in line:
                for unit_type in unit_types:
                    if unit_type in line:
                        current_unit_types.append(unit_type)

            if 'for_countries' in line:
                for tag in tags:
                    if tag in line:
                        current_tags.append(tag)

            if '{' in line:
                level = level + 1

            if '}' in line:
                level = level - 1

            if level == 0:
                for tag in current_tags:
                    for unit_type in current_unit_types:
                        tag_name_lists[tag][unit_type] = 0
                current_tags.clear()
            line = file.readline()

    for tag in tags:
        for unit_type in unit_types:
            if tag_name_lists[tag][unit_type] == 1:
                output_file.write(tag + " has no " + unit_type + " namelist\n")
Esempio n. 19
0
def check_OOB_Contents(path, output_file, optionsdict):
    checktemplate = optionsdict["check_oob_templates"]
    checknamegroup = optionsdict["check_template_namegroup"]
    checknames = optionsdict["check_template_names"]
    checkafter = optionsdict["check_OOB_order"]
    path = os.path.join(path, 'history', 'units')
    afterset = set()
    checktemplateresult = ""
    checknamegroupresult = ""
    checknamesresult = ""
    debug = False
    for filename in os.listdir(path):
        if 'unlock' in filename:
            continue
        if debug:
            print("looking at " + filename)
        forgotname = set()
        file = open_file(os.path.join(path, filename))
        line = file.readline()
        templatenamegroup = set()
        calledtemplates = {}
        templatenames = {}
        inunits = False
        innavy = False
        lineno = 1
        templateno = 0
        name = ""
        depth = 0
        while line:
            if '{' in line:
                depth = depth + 1
            if '}' in line:
                depth = depth - 1
            if inunits == False and innavy == False:
                if 'units = {' in line:
                    inunits = True
                if 'navy = {' in line:
                    innavy = True
                if 'division_template = {' in line:
                    name = ""
                    templateno = templateno + 1
                    forgotname.add(templateno)
                    templatenamegroup.add(templateno)
                if 'name = ' in line:
                    if debug and filename == "OMA.txt":
                        print(line)
                    name = ' '.join(line.split()).split('name = "')[1].split(
                        "\"")[0].strip()
                    templatenames[templateno] = name
                    forgotname.remove(templateno)
                if 'division_names_group' in line and checknamegroup:
                    templatenamegroup.remove(templateno)
            elif inunits:
                if 'division_template = ' in line:
                    if '{' not in line:
                        if checktemplate:
                            name = ' '.join(line.split()).split(
                                'division_template = "')[1].split(
                                    "\"")[0].strip()
                            if (name in templatenames.values()
                                ) is False and checktemplate is True:
                                calledtemplates[name] = filename
                    elif checkafter == True:
                        afterset.add(filename)
            else:
                if depth == 0:
                    innavy = False
            lineno = lineno + 1
            line = file.readline()
        if checktemplate:
            for item in calledtemplates:
                checktemplateresult = checktemplateresult + "The division template " + item + " called in file " + calledtemplates[
                    item] + " does not exist.\n"
        if checknamegroup:
            for item in templatenamegroup:
                checknamegroupresult = checknamegroupresult + templatenames[
                    item].replace("\"", "") + " the " + number(
                        item
                    ) + " division template in " + filename + " has no namegroup \n"
        if checknames:
            for item in forgotname:
                checknamesresult = checknamesresult + "The " + number(
                    item) + "rd template in file " + filename + "has no name"
        if debug:
            print(templatenames.values())
    if checktemplate:
        if debug:
            print(checktemplateresult)
        output_file.write(checktemplateresult)
    if checknamegroup:
        if debug:
            print(checknamegroupresult)
        output_file.write(checknamegroupresult)
    if checknames:
        if debug:
            print(checknamesresult)
        output_file.write(checknamesresult)
    if checkafter:
        for item in afterset:
            result = "File " + item + " has division templates defined after the unit definitions.\n"
            if debug:
                print(result)
            output_file.write(result)
Esempio n. 20
0
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):

    #Scrub for leader gfx
    actual_found_portrait_gfx = []
    actual_found_portrait_gfx_lower = []
    actual_amount = []
    for root, directories, filenames in walk(leaders_gfx_path):
        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:
                actual_found_portrait_gfx.append(temp_string)
                actual_found_portrait_gfx_lower.append((temp_string.lower()))
                actual_amount.append(1)
            else:
                index = actual_found_portrait_gfx.index(temp_string)
                amount = actual_amount[index] + 1
                actual_amount[index] = amount
                #print("Found Leader Portrait: " + temp_string + ", " + amount.__str__())

    #Scrub for leader gfx in vanilla
    for root, directories, filenames in walk(hoi4path + "\\gfx\\leaders"):
        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:
                #print("Found Leader Portrait: " + temp_string)
                actual_found_portrait_gfx.append(temp_string)
                actual_found_portrait_gfx_lower.append((temp_string.lower()))
                actual_amount.append(1)
            else:
                index = actual_found_portrait_gfx.index(temp_string)
                amount = actual_amount[index] + 1
                actual_amount[index] = amount
                #print("Found Leader Portrait: " + temp_string + ", " + amount.__str__())

    #Fill all the pictures (from events#)!
    amountarr = []
    event_picture = []
    leader_picture = []
    dirs = [country_history_path, event_path, tree_path, decisions_path]
    for dir in dirs:
        for file_name in listdir(dir):
            if 'categories' in file_name:
                continue
            line_number = 0
            file = open_file(path.join(dir, file_name))
            lines = file.readlines()
            for line in lines:
                line_number += 1
                if '#' in line:
                    line = line.split('#')[0].strip()
                if "picture" in line and line.strip().startswith('#') is False:
                    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:
                            temp_string = strip_and_clean(temp_string)
                            #print(temp_string)
                            leader_picture.append(temp_string)
                            amountarr.append(1)
                        else:
                            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:
                                #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:
                            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 = []
    file_names = listdir(interface_path)
    file_names.append("eventpictures.gfx")
    for file_name in file_names:
        if "event" in file_name and 'gfx' in file_name:
            line_number = 0
            if file_name != "eventpictures.gfx":
                file = open(path.join(interface_path, file_name), 'r', 'utf-8')
                vanilla = 0
            else:
                file = open_file(
                    path.join(path.join(hoi4path, 'interface'), file_name))
                vanilla = 1
            lines = file.readlines()
            for line in lines:
                line_number += 1
                if "name" in line and line.strip().startswith('#') is False:
                    if '#' in line:
                        line = line.split('#')[0].strip()
                    temp_string = line.split('"')[1].strip()
                    if finddup(event_gfx_key, temp_string) is True:
                        #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:
                        #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:
                    if '#' in line:
                        line = line.split('#')[0].strip()
                    temp_string = line.split('"')[1].strip()
                    event_gfx_file_names_in_gfx_file.append(temp_string)
                    #print(temp_string)

    #GFX keys in events that arent initialised
    for file_name in listdir(event_path):
        line_number = 0
        file = open_file(path.join(event_path, file_name))
        lines = file.readlines()
        for line in lines:
            line_number += 1
            temp_string = line.strip()
            if "picture" in line and temp_string.startswith('#') is False:
                if '"' not in temp_string:
                    if '#' in temp_string:
                        temp_string = temp_string.split('#')[0].strip()
                    temp_string.replace('	', ' ')
                    temp_string = temp_string.split(' ')[2]
                    #print(temp_string)
                    if finddup(event_gfx_key, temp_string) is False:
                        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)

    #Scrub actual pictures to see if theyre defined in .gfx files
    actual_found_event_gfx = []
    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:
                #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:
                output_file.write("GFX not used in any .gfx file: " +
                                  temp_string + "\n")
                #print("GFX not used in any .gfx file: " + temp_string)

    #Fill Decisions keys
    decisions_keys = []
    decisions_keys_full = []
    file = open(path.join(path.join(hoi4path, "interface"), "decisions.gfx"))
    lines = file.readlines()
    for line in lines:
        if '#' in line:
            line = line.split('#')[0].strip()
        if 'name' in line:
            if line.strip().startswith('#') is False:
                temp_string = line.split('\"')[1].strip()
                decisions_keys_full.append(temp_string)
                if 'category' in temp_string:
                    temp_string = temp_string[22:]
                else:
                    temp_string = temp_string[13:]
                decisions_keys.append(temp_string)
    for filenames in listdir(interface_path):
        if 'decisions' in filenames:
            file = open(path.join(interface_path, filenames))
            lines = file.readlines()
            for line in lines:
                if 'name' in line:
                    if '#' in line:
                        line = line.split('#')[0].strip()
                    if line.strip().startswith('#') is False:
                        temp_string = line.split('\"')[1].strip()
                        decisions_keys.append(temp_string[13:])
                        decisions_keys_full.append(temp_string)

    #Check Decision gfx in the txt files
    line_number = 0
    decisions_found = []
    pictures_found = []
    for filename in listdir(decisions_path):
        if 'categories' in filename:
            continue
        file = open(path.join(decisions_path, filename))
        lines = file.readlines()
        for line in lines:
            line_number += 1
            if 'icon' in line:
                if line.strip().startswith('#') is False:
                    if '#' in line:
                        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:
                            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 wrongly written (did you add or remove GFX_categories/GFX decisions)"
                                + temp_string + " in file " + filename +
                                " at " + line_number.__str__() + "\n")

    for filename in listdir(path.join(decisions_path, "categories")):
        file = open(
            path.join(path.join(decisions_path, "categories"), filename))
        lines = file.readlines()
        for line in lines:
            line_number += 1
            if 'icon' in line:
                if line.strip().startswith('#') is False:
                    if '#' in line:
                        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:
                            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:
                if line.strip().startswith('#') is False:
                    if '#' in line:
                        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:
                        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__())

    #Check if KReys are used
    for filenames in listdir(interface_path):
        if 'decisions' in filenames:
            file = open(path.join(interface_path, filenames))
            lines = file.readlines()
            for line in lines:
                if 'name' in line:
                    if '#' in line:
                        line = line.split('#')[0].strip()
                    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:
                                #print("Found Unused KR Decision GFX " + temp_string + " in " + filenames)
                                output_file.write(
                                    "Found Unused KR Decision GFX " +
                                    temp_string + " in " + filenames + "\n")
Esempio n. 21
0
def focus_tree_icons(tree_path, hoi4_path, output_file, mod_path, tree_gfx,
                     gfx_files):
    #First check if every file is defined

    #Fill all present goal icons
    tree_gfx_files = []
    for filename in listdir(tree_gfx):
        tree_gfx_files.append(filename)

    #Fill all defined keys from the .gfx file
    #KR specifically generates a shine file, so i will ignore that
    goals_files_needed = []
    gfx_names = []
    for filename in listdir(gfx_files):
        if 'goals' in filename and 'shine' not in filename:
            file = open(path.join(gfx_files, filename), 'r', 'utf-8')
            lines = file.readlines()
            for line in lines:
                if 'GFX_focus_jap_zero' in line:
                    print(line + ", " + filename)
                if 'name' in line:
                    temp_string = line.strip()
                    if temp_string.startswith('#'):
                        continue
                    if '#' in temp_string:
                        temp_string = temp_string.split('#')[0].strip()
                    temp_string = temp_string.split('"')[1]
                    gfx_names.append(temp_string)
                if 'texturefile' in line and 'shine_overlay' not in line:
                    temp_string = line.strip()
                    if temp_string.startswith('#'):
                        continue
                    if '#' in temp_string:
                        temp_string = temp_string.split('#')[0].strip()
                    temp_string = temp_string.split('"')[1]
                    if '/' in temp_string:
                        if 'goals' not in temp_string:
                            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 'tga' in temp_string:
                            if finddup(tree_gfx_files,
                                       temp_string.replace('tga',
                                                           'dds')) is False:
                                #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:
                                #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:
            #print("Found focus texture not used " + filename[:len(filename)-4])
            output_file.write("Found focus texture not used " +
                              filename[:len(filename) - 4] + "\n")

    kr_gfx_names = gfx_names.copy()
    #append vanilla stuff
    file.close()
    file = open(path.join(path.join(hoi4_path, "interface"), "goals.gfx"), 'r',
                'utf-8')
    lines = file.readlines()
    for line in lines:
        if 'name' in line:
            line = line.strip()
            if '#' in line:
                if line.startswith('#'):
                    continue
                else:
                    line = line.split('#')[0]
            line = line.split('"')[1]
            gfx_names.append(line)

    #start scrubbing
    found_gfx_in_tree = []
    for filename in listdir(tree_path):
        size = path.getsize(path.join(tree_path, filename))
        if size < 100:
            continue
        file = open_file(path.join(tree_path, filename))
        lines = file.readlines()
        line_number = 0
        for line in lines:
            line_number += 1
            if 'icon' in line:
                if '#' in line:
                    if line.startswith('#'):
                        continue
                    else:
                        line = line.split('#')[0]
                if line.strip() is not "" and '=' in line:
                    line = line.split('=')[1].strip()
                    found_gfx_in_tree.append(line)
                    if finddup(gfx_names, line) is False:
                        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:
            output_file.write(
                "Found focus icon never used in any focus tree: " + string +
                "\n")