Преглед на файлове

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

master
Bryan Miller преди 7 години
родител
ревизия
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



Loading…
Отказ
Запис