83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
import os
|
|
import sys
|
|
from . import config
|
|
from .file import *
|
|
import pyglet.resource
|
|
|
|
g_data = {}
|
|
|
|
class ModDependency(object):
|
|
def __init__(self: object, modname: str):
|
|
self.name = modname
|
|
self.deps = []
|
|
|
|
def add(self: object, modname: str):
|
|
self.deps.append(modname)
|
|
|
|
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 == '' and os.path.isdir(os.path.join(program_path(), 'data', mn)):
|
|
# bare directory used for mod development/game development
|
|
moddata = ModInfoDir(mn)
|
|
if moddata.has_modinfo():
|
|
full_modlist[mn][me] = moddata
|
|
|
|
modlist = {}
|
|
for mn in full_modlist.keys():
|
|
print(f"Checking mod {full_modlist[mn]}")
|
|
if '' in full_modlist[mn]:
|
|
modlist[mn] = full_modlist[mn]['']
|
|
|
|
modgraph = {}
|
|
|
|
if not modlist:
|
|
""" we have no mods, which means we have no base game data """
|
|
""" assume development mode, and try git! """
|
|
import subprocess
|
|
projectname = project_name()
|
|
subprocess.check_output(["git", "clone", "ssh://git@git.eltanin.net/game_data/" + projectname, "maingame"], cwd=os.path.join(program_path(), "data"))
|
|
|
|
pyglet.resource.path = []
|
|
for mod in modlist:
|
|
pyglet.resource.path.append('data/' + mod)
|
|
|
|
pyglet.resource.reindex()
|
|
|
|
|