浏览代码

Created a DataContainer class to house array and dictionary data elements, allowing them to be weakref'ed by ResourceManager.

master
Bryan Miller 6 年前
父节点
当前提交
694047c7d4
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. +1
    -1
      game/gbe/resource.py
  2. +9
    -1
      game/gbe/resourceLoaders.py

+ 1
- 1
game/gbe/resource.py 查看文件



import os, sys import os, sys
import logging import logging
import json
import weakref import weakref
import pygame import pygame
from .resourceLoaders import * from .resourceLoaders import *
try: try:
d["instance"] = loader(filename, params) d["instance"] = loader(filename, params)
except Exception as e: except Exception as e:
raise e
_l.error("{}".format(e)) _l.error("{}".format(e))
return None return None
return weakref.ref(d["instance"]) return weakref.ref(d["instance"])

+ 9
- 1
game/gbe/resourceLoaders.py 查看文件

import os import os
import json
import pygame import pygame




raise LoadError("Font subsystem not initialized before attempting to obtain resource.") raise LoadError("Font subsystem not initialized before attempting to obtain resource.")




class DataContainer:
def __init__(self, data):
self._data = data
@property
def data(self):
return self._data

def load_JSON(filename, params={}): def load_JSON(filename, params={}):
if not os.path.isfile(filename): if not os.path.isfile(filename):
raise LoaderError("File '{}' is missing or not a file.".format(filename)) raise LoaderError("File '{}' is missing or not a file.".format(filename))
try: try:
with open(filename) as f: with open(filename) as f:
data = json.load(f) data = json.load(f)
return data
return DataContainer(data)
except Exception as e: except Exception as e:
raise e raise e



正在加载...
取消
保存