Skip to content

Commit d72fbe2

Browse files
scrlysAWSWCommunity
authored andcommitted
Added a better mod importation system. Doesn't actually import any mods yet
1 parent f8557f6 commit d72fbe2

File tree

12 files changed

+116
-526
lines changed

12 files changed

+116
-526
lines changed
File renamed without changes.

clean.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
DIR=$(dirname $0)
3+
for f in ${DIR}/*; do rm -rf "$DIR/../game/$f"; done

modloader/__init__.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,4 @@
1-
import renpy
2-
import os
3-
import sys
4-
import imp
51
import modinfo
6-
import importlib
7-
# So technically anything up here's going to be imported into mods since we're making a copy of our globals. It's safe to import them anyway.
82

9-
modinfo.init()
10-
11-
def getdir():
12-
return renpy.config.gamedir
13-
14-
print("AWSW Mod Loader Init")
15-
16-
search_dir = getdir() + "/mods/"
17-
if not os.path.exists(search_dir):
18-
os.makedirs(search_dir)
19-
20-
sys.path.append(getdir() + "/modloader/")
21-
sys.path.append(getdir() + "/mods/")
22-
23-
loaded_mods = []
24-
25-
for object in os.listdir(search_dir):
26-
fullpath = search_dir + object
27-
if os.path.isdir(fullpath):
28-
for object2 in os.listdir(fullpath):
29-
modobj = fullpath + '/' + object2
30-
if object2 == 'mod.py':
31-
print(('Loaded mod ' + object).encode('utf-8'))
32-
name = os.path.splitext(os.path.split(modobj)[-1])
33-
modinfo.modlist.append(object)
34-
loc = dict()
35-
glo = dict(globals())
36-
execfile(modobj, glo, loc) # We want to isolate mods from each other, but give them a copy of our globals so modinfo is not reloaded.
37-
loaded_mods.append((glo, loc)) # Grab locals so we can initialize the mods later.
38-
elif object2 == 'resource' and os.path.isdir(modobj):
39-
renpy.config.searchpath.append(modobj)
40-
41-
for (glo, loc) in loaded_mods:
42-
if 'mod_init' in loc:
43-
comb = glo.copy()
44-
comb.update(loc)
45-
func = loc['mod_init']
46-
exec(func.__code__, comb) # This is nasty!
47-
48-
# force renpy to reindex all game files
49-
renpy.loader.old_config_archives = None
3+
import test
4+
print(modinfo.modlist)

modloader/modclass.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import modinfo
2+
3+
class Mod():
4+
"""The Mod class
5+
6+
This is supposed to act like a superclass for mods.
7+
"""
8+
def mod_info(self):
9+
"""Get the mod info
10+
11+
Returns:
12+
A tuple with the name, version, and author
13+
"""
14+
raise Exception("Mod info isn't overriden")
15+
16+
def loadable_mod(clazz):
17+
"""Annotation to add a Mod subclass to the mod list
18+
19+
Args:
20+
clazz (Mod): The Mod class
21+
"""
22+
mod = clazz() # Create a new instance of the class
23+
modinfo.add_mod(mod.mod_info()[0], mod)

modloader/modinfo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
modlist = {}
12

2-
def init():
3-
global modlist
4-
modlist = []
5-
6-
print('init modinfo')
3+
def add_mod(mod_name, mod):
4+
print("Adding mod {}".format(mod_name))
5+
modlist[mod_name] = mod

0 commit comments

Comments
 (0)