def selectSentences(): global picks, SECTIONS, pickedDict, dataDict # iterate how many picks to do in each section for howmany, section in zip(picks, SECTIONS): pickedList = [] howmany = int(howmany) while howmany > 0: pick = randint(0, len(dataDict[section]) - 1) if pick in pickedList: continue else: if not section in pickedDict: pickedDict[section] = [] pickedDict[section].append(dataDict[section][pick]) pickedList.append(pick) howmany -= 1 del dataDict[section][pick] # check if we have snetences left if len(dataDict[section]) == 0: reskinPrint( 'Picked all sentences from section ' + section + '...', 'w') break
def replaceWords(): global picks, description # prepare a bucket dict to count how many times we used each keyword totalReplacementsLeft = len( keywords ) * MAX_REPITATIONS_PER_KEYWORD # count how many replacements were done since we don't care which word to choose if all words replaced max times bucketDict = OrderedDict() for word in keywords: bucketDict[word] = 0 while PLACEHOLDER in description: # draw a word random.seed(time.time()) word = keywords[randint(0, len(keywords) - 1)] while (totalReplacementsLeft > 0) and (bucketDict[word] == MAX_REPITATIONS_PER_KEYWORD): word = keywords[randint(0, len(keywords) - 1)] description = description.replace(PLACEHOLDER, word, 1) bucketDict[word] += 1 totalReplacementsLeft -= 1 if totalReplacementsLeft == 0: reskinPrint("All keywords were placed " + str(MAX_REPITATIONS_PER_KEYWORD) + " times... randomly placing.")
def selectSentences(): global picks, SECTIONS, pickedDict, dataDict # iterate how many picks to do in each section for howmany, section in zip(picks, SECTIONS): pickedList = [] howmany = int(howmany) while howmany > 0: pick = randint(0, len(dataDict[section])-1) if pick in pickedList: continue else: if not section in pickedDict: pickedDict[section] = [] pickedDict[section].append(dataDict[section][pick]) pickedList.append(pick) howmany-=1 del dataDict[section][pick] # check if we have snetences left if len(dataDict[section]) == 0: reskinPrint('Picked all sentences from section ' + section + '...', 'w') break
def outputDescription(): global output, description reskinPrint("Printing description...") if output == "": print(description) else: outputFile = open(output, "w") outputFile.write(description) outputFile.close()
def replaceWords(): global picks, description # prepare a bucket dict to count how many times we used each keyword totalReplacementsLeft = len(keywords) * MAX_REPITATIONS_PER_KEYWORD # count how many replacements were done since we don't care which word to choose if all words replaced max times bucketDict = OrderedDict(); for word in keywords: bucketDict[word] = 0 while PLACEHOLDER in description: # draw a word random.seed(time.time()) word = keywords[randint(0, len(keywords) - 1)] while (totalReplacementsLeft > 0) and (bucketDict[word] == MAX_REPITATIONS_PER_KEYWORD): word = keywords[randint(0, len(keywords) - 1)] description = description.replace(PLACEHOLDER, word, 1) bucketDict[word] += 1 totalReplacementsLeft -= 1 if totalReplacementsLeft == 0: reskinPrint("All keywords were placed " + str(MAX_REPITATIONS_PER_KEYWORD) + " times... randomly placing.")
def readDict(lang=""): global SECTIONS, dataDict dictFile = "aldg." + lang + ".dict" # dictFile = "tmp.py" if not os.path.isfile(dictFile): reskinPrint("Cannot load dictionary, file not exists: " + dictFile, "e") return False else: reskinPrint("Found dictionary file " + dictFile) with open(dictFile) as inFile: sectionName = "" sentences = [] for line in inFile: if line == "\n": continue # Check for section begin if line.startswith('['): # If we started a new section (or come up with "end"), store the previous one if not (sectionName == ''): dataDict[sectionName] = sentences sectionName = line.replace('[', '').replace(']', '').replace('\n', '') sentences = [] # Verify section name is valid if not sectionName in SECTIONS: reskinPrint( "Invalid section " + sectionName + ", skipping...", "w") sectionName = '' continue # If not a new section, store sentence sentences.append(line.replace('\n', '')) return True
def readDict(lang=""): global SECTIONS, dataDict dictFile = "aldg." + lang + ".dict" # dictFile = "tmp.py" if not os.path.isfile(dictFile): reskinPrint("Cannot load dictionary, file not exists: " + dictFile , "e") return False else: reskinPrint("Found dictionary file " + dictFile) with open(dictFile) as inFile: sectionName = "" sentences = [] for line in inFile: if line=="\n": continue # Check for section begin if line.startswith('['): # If we started a new section (or come up with "end"), store the previous one if not (sectionName == ''): dataDict[sectionName] = sentences; sectionName = line.replace('[','').replace(']','').replace('\n','') sentences = [] # Verify section name is valid if not sectionName in SECTIONS: reskinPrint("Invalid section " + sectionName + ", skipping..." , "w") sectionName = '' continue # If not a new section, store sentence sentences.append(line.replace('\n','')) return True
4 * 20 + 2 * 2 * 4 + 2, 103, 104 ]) print("Done.") # replace simpleslots/artwork/feature_overlay* print("Replacing feature overlay in artwork...") dirToCopy = "/SimpleSlots/artwork" if len( glob.glob(trgDir + dirToCopy + "reskin/LevelSelect/feature_overlay*.png")) > 0: reskinutils.copyFilesByGlob( trgDir + dirToCopy + "reskin/LevelSelect/feature_overlay*.png", trgDir + dirToCopy) reskinutils.checkCopy(2) else: reskinPrint("Couldn't find feature_overlay files...", "w") print("Done.") # replace simpleslots/artwork/icon* print("Replacing icons on assets dir...") srcIconFiles = [ "/AppIcon57x57.png", "/[email protected]", "/AppIcon72x72.png", "/[email protected]" ] trgIconFiles = [ "/SimpleSlots/artwork/icon.png", "/SimpleSlots/artwork/[email protected]", "/SimpleSlots/artwork/icon-ipad.png", "/SimpleSlots/artwork/[email protected]" ]
dirToCopy = "/SimpleSlots/artwork/reskin" subdirs = ["/LevelSelect", "/lvl1", "/lvl2", "/lvl3", "/lvl4"] for i in range(0, len(subdirs)): reskinutils.copyFilesByGlob(assets + subdirs[i] + "/*.png", trgDir + dirToCopy + subdirs[i]) reskinutils.checkCopy([4 * 20 + 2 * 2 * 4 + 4, 4 * 20 + 2 * 2 * 4 + 3, 4 * 20 + 2 * 2 * 4, 4 * 20 + 2 * 2 * 4 + 2, 103, 104]) print("Done.") # replace simpleslots/artwork/feature_overlay* print("Replacing feature overlay in artwork...") dirToCopy = "/SimpleSlots/artwork" if len(glob.glob(trgDir + dirToCopy + "reskin/LevelSelect/feature_overlay*.png"))>0: reskinutils.copyFilesByGlob(trgDir + dirToCopy + "reskin/LevelSelect/feature_overlay*.png", trgDir + dirToCopy) reskinutils.checkCopy(2) else: reskinPrint("Couldn't find feature_overlay files...", "w") print("Done.") # replace simpleslots/artwork/icon* print("Replacing icons on assets dir...") srcIconFiles = ["/AppIcon57x57.png", "/[email protected]", "/AppIcon72x72.png", "/[email protected]"] trgIconFiles = ["/SimpleSlots/artwork/icon.png", "/SimpleSlots/artwork/[email protected]", "/SimpleSlots/artwork/icon-ipad.png", "/SimpleSlots/artwork/[email protected]"] for i in range(0, len(srcIconFiles)): reskinutils.copyFilesByName(icons + srcIconFiles[i], trgDir + trgIconFiles[i]) reskinutils.checkCopy(4) print("Done.") # END OF FILES REPLACEMENT