Просмотр исходного кода

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

master
Bryan Miller 7 лет назад
Родитель
Сommit
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



Загрузка…
Отмена
Сохранить