-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- made generation much faster - added ability in code to designate file to write to (currently just in the "save_data" folder - fixed var names to make them easier to understand - fixed issue where types and region lists were stored as strings
- Loading branch information
1 parent
0238916
commit 456c696
Showing
11 changed files
with
189 additions
and
3,680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,120 @@ | ||
from Objects.Item import * | ||
from Objects.Shop import ShopManager | ||
from Objects.Item import ItemManager | ||
|
||
|
||
class TypeManager: | ||
|
||
def __init__(self, shop, item): | ||
def __init__(self, shop: ShopManager, item: ItemManager, filename="types.txt"): | ||
|
||
self.itemTypes = item.getItemTypes() # gets all the item Types | ||
self.shopTypes = shop.getShopTypes() # gets all the shop Types | ||
self.typeManager = {} # this is to manage the save file for the supported item Types for each shop | ||
self.item_types = item.getItemTypes() # gets all the item Types | ||
self.shop_types = shop.getShopTypes() # gets all the shop Types | ||
self.filename = filename | ||
self.type_list = {} | ||
try: | ||
with open("../Resources/save_data/types.txt", "x") as file: | ||
with open("../Resources/save_data/"+self.filename, "x") as file: | ||
file.write("") | ||
file.close() | ||
self.typeList = {} | ||
except FileExistsError: | ||
try: | ||
with open("../Resources/save_data/types.txt") as file: | ||
self.typeList = json.load(file) | ||
except json.decoder.JSONDecodeError: | ||
self.typeList = {} | ||
for key in self.typeList: | ||
self.typeManager.update({key: self.typeList[key]}) # updates all the keys with the types in the save file | ||
with open("../Resources/save_data/"+self.filename) as file: | ||
self.type_list = json.load(file) | ||
except json.decoder.JSONDecodeError as e: | ||
self.type_list = {} | ||
|
||
for key in self.type_list: | ||
self.type_list.update({key: self.type_list[key]}) | ||
# updates all the keys with the types in the save file | ||
for key in self.shop_types: | ||
if key not in self.type_list: | ||
self.type_list.update({key: []}) # updates all the keys with the types in the save file | ||
|
||
def addItemType(self, key, value): # adds an item shop_type to a given shop shop_type | ||
temp = [] | ||
if self.typeManager[key] != '': | ||
temp += self.typeManager[key] | ||
if self.type_list[key]: | ||
temp += self.type_list[key] | ||
if temp.count(value) == 0: | ||
temp += [value] | ||
if len(temp) != 0: | ||
self.typeManager.update({key: temp}) | ||
self.type_list.update({key: temp}) | ||
|
||
def addNewShopType(self, key): | ||
if key not in self.typeManager: | ||
self.typeManager.update({key: ""}) | ||
if key not in self.type_list: | ||
self.type_list.update({key: []}) | ||
|
||
def removeItemType(self, key, value): # removes an item shop_type from a given shop shop_type | ||
temp = [] | ||
if self.typeManager[key] != '': | ||
temp += self.typeManager[key] | ||
if self.type_list[key]: | ||
temp += self.type_list[key] | ||
if temp.count(value) != 0: | ||
temp.pop(value) | ||
if len(temp) != 0: | ||
self.typeManager.update({key: temp}) | ||
self.type_list.update({key: temp}) | ||
|
||
def addNewShopItemType(self, key, value): # adds a new shop shop_type and a new item shop_type to the shop shop_type | ||
if key not in self.typeManager: | ||
if key not in self.type_list: | ||
print(key) | ||
self.typeManager.update({key: ""}) | ||
self.type_list.update({key: []}) | ||
self.addItemType(key, value) | ||
|
||
def saveTypes(self): # saves the types for each shop to the save text file | ||
file = open("../Resources/save_data/types.txt", "r+") | ||
json.dump(self.typeManager, file, indent=4) | ||
file = open("../Resources/save_data/"+self.filename, "r+") | ||
json.dump(self.type_list, file, indent=2) | ||
file.close() | ||
|
||
|
||
class RegionManager: | ||
def __init__(self, shop, item): | ||
self.itemRegions = item.getItemRegions() # gets all the item regions | ||
self.shopRegions = shop.getShopRegions() # gets all the shop regions | ||
self.regionManager = {} # this is to manage the save file for the supported item regions for each shop | ||
def __init__(self, shop: ShopManager, item: ItemManager,filename: str = "regions.txt"): | ||
self.item_regions = item.getItemRegions() # gets all the item regions | ||
self.shop_regions = shop.getShopRegions() # gets all the shop regions | ||
self.filename = filename | ||
self.region_list = {} | ||
try: | ||
with open("../Resources/save_data/regions.txt", "x") as file: | ||
with open("../Resources/save_data/" + self.filename, "x") as file: | ||
file.write("") | ||
file.close() | ||
self.regionList = {} | ||
except FileExistsError: | ||
try: | ||
with open("../Resources/save_data/regions.txt") as file: | ||
self.regionList = json.load(file) | ||
except json.decoder.JSONDecodeError: | ||
self.regionList = {} | ||
for key in self.regionList: | ||
self.regionManager.update({key: self.regionList[key]}) | ||
with open("../Resources/save_data/" + self.filename) as file: | ||
self.region_list = json.load(file) | ||
except json.decoder.JSONDecodeError as e: | ||
self.region_list = {} | ||
|
||
for key in self.region_list: | ||
self.region_list.update({key: self.region_list[key]}) | ||
# updates all the keys with the regions in the save file | ||
count = 0 | ||
for key in self.shopRegions: | ||
if key not in self.regionManager: | ||
self.regionManager.update({key: '[]'}) # updates all the keys with the regions in the save file | ||
count += 1 | ||
for key in self.shop_regions: | ||
if key not in self.region_list: | ||
self.region_list.update({key: []}) # updates all the keys with the regions in the save file | ||
|
||
def addItemRegion(self, key, value): # adds an item region to a given shop region | ||
temp = [] | ||
if self.regionManager[key] != '': | ||
temp += self.regionManager[key] | ||
if self.region_list[key]: | ||
temp += self.region_list[key] | ||
if temp.count(value) == 0: | ||
temp += [value] | ||
if len(temp) != 0: | ||
self.regionManager.update({key: temp}) | ||
self.region_list.update({key: temp}) | ||
|
||
def addNewShopRegion(self, key): | ||
if key not in self.regionManager: | ||
self.regionManager.update({key: "[]"}) | ||
if key not in self.region_list: | ||
self.region_list.update({key: []}) | ||
|
||
def removeItemRegion(self, key, value): # removes an item region from a given shop region | ||
temp = [] | ||
if self.regionManager[key] != '': | ||
temp += self.regionManager[key] | ||
if self.region_list[key]: | ||
temp += self.region_list[key] | ||
if temp.count(value) != 0: | ||
temp.pop(value) | ||
if len(temp) != 0: | ||
self.regionManager.update({key: temp}) | ||
self.region_list.update({key: temp}) | ||
|
||
def addNewShopItemRegion(self, key, value): # adds a new shop region and a new item region to the shop region | ||
if key not in self.regionManager: | ||
self.regionManager.update({key: ""}) | ||
if key not in self.region_list: | ||
self.region_list.update({key: []}) | ||
self.addItemRegion(key, value) | ||
|
||
def saveRegions(self): # saves the regions for each shop to the save text file | ||
file = open("../Resources/save_data/regions.txt", "r+") | ||
json.dump(self.regionManager, file, indent=4) | ||
file = open("../Resources/save_data/" + self.filename, "r+") | ||
json.dump(self.region_list, file, indent=2) | ||
file.close() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
{ | ||
"East Ozoa": "['Mountains','Forest','Developed Area']", | ||
"Unknown Lands": "[]", | ||
"Magius": "['Magic Lands']", | ||
"South East Ozoa": "['Plains','Mines]", | ||
"West Ozoa": "['Plains']", | ||
"Fechura": "['Jungle','Plains']", | ||
"Polar": "[]", | ||
"Oksandarr": "['Mines','Magic Lands']", | ||
"Crestus": "['Mines','Plains']", | ||
"Pitt": "[]" | ||
"East Ozoa": [ | ||
"Mountains", | ||
"Forest", | ||
"Developed Area" | ||
], | ||
"Unknown Lands": [], | ||
"Magius": [ | ||
"Magic Lands" | ||
], | ||
"South East Ozoa": [ | ||
"Plains", | ||
"Mines" | ||
], | ||
"West Ozoa": [ | ||
"Plains" | ||
], | ||
"Fechura": [ | ||
"Jungle", | ||
"Plains" | ||
], | ||
"Polar": [], | ||
"Oksandarr": [ | ||
"Mines", | ||
"Magic Lands" | ||
], | ||
"Crestus": [ | ||
"Mines", | ||
"Plains" | ||
], | ||
"Pitt": [] | ||
} |
Oops, something went wrong.