Give EntityClassDict mapping access functions.

They just redirect to the actual entity class dictionary, but it saves a
lot of unnecessary code elsewhere.
This commit is contained in:
Bill Currie 2012-09-16 10:55:06 +09:00
parent 8416276cee
commit 6b8df7f42a
4 changed files with 23 additions and 7 deletions

View file

@ -60,7 +60,7 @@ def ecm_draw(self, context):
layout = self.layout
for item in self.menu_items:
if type(item[1]) is str:
ec = context.scene.qfmap.entity_classes.entity_classes[item[1]]
ec = context.scene.qfmap.entity_classes[item[1]]
if ec.size:
icon = 'OBJECT_DATA'
else:
@ -205,7 +205,7 @@ class QFEntityClasses(bpy.types.PropertyGroup):
script = bpy.data.texts[self.script].as_string()
self.entity_classes.from_plist(script)
menudict = {}
entclasses = self.entity_classes.entity_classes.keys()
entclasses = self.entity_classes.keys()
for ec in entclasses:
ecsub = ec.split("_")
d = menudict

View file

@ -39,7 +39,7 @@ def draw_callback(self, context):
loc += Vector(obj.bound_box[i])
return obj.location + loc/8.0
qfmap = context.scene.qfmap
entity_classes = qfmap.entity_classes.entity_classes
entity_classes = qfmap.entity_classes
entity_targets = qfmap.entity_targets
target_entities = qfmap.target_entities
bgl.glLineWidth(3)
@ -103,7 +103,7 @@ class QFEntityRelations(bpy.types.Panel):
def qfentity_items(self, context):
qfmap = context.scene.qfmap
entclasses = qfmap.entity_classes.entity_classes
entclasses = qfmap.entity_classes
eclist = list(entclasses.keys())
eclist.sort()
enum = (('', "--", ""),)
@ -156,7 +156,7 @@ class EntityPanel(bpy.types.Panel):
qfentity = context.active_object.qfentity
qfmap = context.scene.qfmap
if qfentity.classname:
ec = qfmap.entity_classes.entity_classes[qfentity.classname]
ec = qfmap.entity_classes[qfentity.classname]
else:
ec = EntityClass.null()
flags = ec.flagnames + ("",) * (8 - len(ec.flagnames))
@ -266,7 +266,7 @@ def set_entity_props(obj, ent):
item.value = ent.d[key]
def add_entity(self, context, entclass):
entity_class = context.scene.qfmap.entity_classes.entity_classes[entclass]
entity_class = context.scene.qfmap.entity_classes[entclass]
context.user_preferences.edit.use_global_undo = False
for obj in bpy.data.objects:
obj.select = False

View file

@ -137,6 +137,22 @@ class EntityClassDict:
def __init__(self):
self.path = ""
self.entity_classes = {}
def __len__(self):
return self.entity_classes.__len__()
def __getitem__(self, key):
return self.entity_classes.__getitem__(key)
def __iter__(self):
return self.entity_classes.__iter__()
def __contains__(self, item):
return self.entity_classes.__contains__(item)
def keys(self):
return self.entity_classes.keys()
def values(self):
return self.entity_classes.values()
def items(self):
return self.entity_classes.items()
def get(self, key, default=None):
return self.entity_classes.get(key, default)
def scan_source(self, fname):
text = open(fname, "rt", encoding="idquake").read()
line = 1

View file

@ -164,7 +164,7 @@ def process_entity(ent, wads):
obj = bpy.data.objects.new(name, mesh)
else:
try:
entityclass = qfmap.entity_classes.entity_classes[classname]
entityclass = qfmap.entity_classes[classname]
except KeyError:
entityclass = None
if entityclass and entityclass.size: