Пример #1
0
def checkBankForUpdate(bankName, foundData, tileBased=True, printMe=False):
    '''checks the bank with the given bank name to see if anything from the given list, found data, has been added or removed'''
    #images = findAllFiles("art/"+fileName+"/");
    bankFile = open(bankName + ".txt", "r+")
    if tileBased:
        bankedData = getBankedData(bankFile)
        bankedNames = bankedData[0]
        bankedASCIIs = bankedData[1]
        addedNames = util.shallowCopy(foundData)
        #Figure out what has been added
        addedNames = util.deleteSimularItems(bankedNames, addedNames)
        removedNames = util.shallowCopy(bankedNames)
        #Figure out what has been removed
        removedNames = util.deleteSimularItems(foundData, removedNames)
        removedASCIIs = []
        for i in removedNames:
            if printMe:
                print(
                    i +
                    " has been removed, removing ascii representation from pool"
                )
            removedASCIIs.append(bankedASCIIs.pop(bankedNames.index(i)))
            #Removes it from the other an adds it to the removed list
            bankedNames.pop(bankedNames.index(i))
        if len(removedASCIIs) > 0:
            print("TILEBASED:" + str(removedASCIIs))
            changeMaps(bankName, removedASCIIs)
        asciiCatch = getNewASCIIs(addedNames, bankedASCIIs, printMe)
        for name in addedNames:
            bankedNames.append(name)
        writeOutBank(bankFile, bankedNames, bankedASCIIs, printMe)
        #bankedNames = util.deleteSimularItems(removedNames, bankedNames);
        #writeOutBank(foundData, bankFile, bankedNames, bankedASCIIs)
    else:
        bankedNames = getBankedData(bankFile, False)[0]
        print("\n")
        print(bankedNames)
        print("\n")
        addedNames = util.shallowCopy(foundData)
        addedNames = util.deleteSimularItems(bankedNames, addedNames)
        removedNames = util.shallowCopy(bankedNames)
        removedNames = util.deleteSimularItems(foundData, removedNames)
        bankedNames = util.deleteSimularItems(removedNames, bankedNames)
        for name in addedNames:
            bankedNames.append(name)
        if len(removedNames) > 0:
            print("NON TILEBASED: " + str(removedNames))
            changeMaps(bankName, removedNames, False)
        writeOutBank(bankFile, bankedNames, -1, printMe)
    bankFile.close()
Пример #2
0
 def saveMap(self):
     '''Basic map saving functionallity'''
     fileName = input("Save level as (Without .lvl extention)(enter 'x' to cancel): ")
     if fileName == 'x':
         print("Save cancelled");
         return 0;
     fileName += ".lvl"
     filePath = "levels/" + fileName
     try:
         file = open(filePath, 'r');
         found = True;
         file.close();
     except:
         found = False;
     if found:
         answer = util.ask("Level already created.  Overight?: (Yes/No) ");
         if answer == True:
             found = False;
         else:
             print("Save canceled!");
     if found == False:    
         file = open(filePath, 'w')
         mapOutPut = "mapWidth " + str(self.cols) + "\nmapHeight " + str(self.rows) + "\n" + self.getMapString()
         file.write(mapOutPut);
         file.close();
         for layer in self.layerList:
             layer.tileListCatch = util.shallowCopy(layer.tileList);
         print(fileName+" saved");
Пример #3
0
def checkBankForUpdate(bankName, foundData, tileBased=True, printMe=False):
    '''checks the bank with the given bank name to see if anything from the given list, found data, has been added or removed'''    
    #images = findAllFiles("art/"+fileName+"/");
    bankFile = open(bankName+".txt","r+");
    if tileBased:
        bankedData = getBankedData(bankFile);
        bankedNames = bankedData[0];bankedASCIIs = bankedData[1];
        addedNames = util.shallowCopy(foundData);#Figure out what has been added
        addedNames = util.deleteSimularItems(bankedNames, addedNames);
        removedNames = util.shallowCopy(bankedNames);#Figure out what has been removed
        removedNames = util.deleteSimularItems(foundData, removedNames);
        removedASCIIs = []
        for i in removedNames:
            if printMe:
                print(i + " has been removed, removing ascii representation from pool")
            removedASCIIs.append(bankedASCIIs.pop(bankedNames.index(i)));#Removes it from the other an adds it to the removed list
            bankedNames.pop(bankedNames.index(i));
        if len(removedASCIIs) > 0:
            print("TILEBASED:"+str(removedASCIIs));
            changeMaps(bankName,removedASCIIs);
        asciiCatch = getNewASCIIs(addedNames, bankedASCIIs, printMe);
        for name in addedNames:
            bankedNames.append(name);
        writeOutBank(bankFile, bankedNames, bankedASCIIs, printMe);
        #bankedNames = util.deleteSimularItems(removedNames, bankedNames);
        #writeOutBank(foundData, bankFile, bankedNames, bankedASCIIs)
    else:
        bankedNames = getBankedData(bankFile, False)[0];
        print("\n")
        print(bankedNames)
        print("\n")
        addedNames = util.shallowCopy(foundData);
        addedNames = util.deleteSimularItems(bankedNames, addedNames);
        removedNames = util.shallowCopy(bankedNames);
        removedNames = util.deleteSimularItems(foundData, removedNames);
        bankedNames = util.deleteSimularItems(removedNames, bankedNames);
        for name in addedNames:
            bankedNames.append(name);
        if len(removedNames) > 0:
            print("NON TILEBASED: "+str(removedNames));
            changeMaps(bankName, removedNames, False)
        writeOutBank(bankFile, bankedNames, -1, printMe);
    bankFile.close();