begin WIP modloader framework
This commit is contained in:
parent
d344841a1a
commit
67e7316a69
1 changed files with 53 additions and 0 deletions
|
@ -22,3 +22,56 @@ def fd_write(vault: str, path: str) -> object:
|
||||||
fp = os.path.join(program_path(), vault, path)
|
fp = os.path.join(program_path(), vault, path)
|
||||||
os.makedirs(os.path.join(program_path(), vault), exist_ok=True)
|
os.makedirs(os.path.join(program_path(), vault), exist_ok=True)
|
||||||
return open(fp, 'w')
|
return open(fp, 'w')
|
||||||
|
|
||||||
|
g_data = {}
|
||||||
|
|
||||||
|
class ModInfo(object):
|
||||||
|
def __init__(self: object, modname: str):
|
||||||
|
self.name = modname
|
||||||
|
self.modinfo = None
|
||||||
|
|
||||||
|
class ModInfoDir(ModInfo):
|
||||||
|
def __init__(self: object, modname: str):
|
||||||
|
super().__init__(modname)
|
||||||
|
|
||||||
|
def path(self: object, path: str) -> str:
|
||||||
|
return os.path.join(self.name, path)
|
||||||
|
|
||||||
|
def exists(self: object, path: str) -> object:
|
||||||
|
return exists('data', self.path(path))
|
||||||
|
|
||||||
|
def fd_open(self: object, path: str) -> object:
|
||||||
|
return fd_open('data', self.path(path))
|
||||||
|
|
||||||
|
def has_modinfo(self: object) -> bool:
|
||||||
|
return exists('data', self.path('modinfo.json'))
|
||||||
|
|
||||||
|
def read_modinfo(self: object) -> None:
|
||||||
|
inffile = self.fd_open('data', self.path('modinfo.json'))
|
||||||
|
self.modinfo = json.load(inffile)
|
||||||
|
|
||||||
|
|
||||||
|
def load_mods() -> None:
|
||||||
|
global g_data
|
||||||
|
g_data = {}
|
||||||
|
|
||||||
|
full_modlist = {}
|
||||||
|
for mod in os.listdir(os.path.join(program_path(), 'data')):
|
||||||
|
mn, me = os.path.splitext(mod)
|
||||||
|
if not mn in full_modlist:
|
||||||
|
full_modlist[mn] = {}
|
||||||
|
if me.lower() == 'zip':
|
||||||
|
# handle zip mods here somehow
|
||||||
|
# full_modlist[mn][me] = mod
|
||||||
|
pass
|
||||||
|
elif me == '' or os.path.isdir(os.path.join(program_path(), 'data', mn)):
|
||||||
|
moddata = ModInfoDir()
|
||||||
|
if moddata.has_modinfo():
|
||||||
|
full_modlist[mn][me] = moddata
|
||||||
|
|
||||||
|
modlist = {}
|
||||||
|
for mn in full_modlist.keys():
|
||||||
|
if '' in full_modlist[mn]:
|
||||||
|
modlist[mn] = full_modlist[mn]['']
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue