def editor_click(self, pos, typ, button=None): if typ == 'up': # only detect mouse down return x, y = self.calc_cursor_coord(pos, typ, button=button) # don't check outside of level area if not (0 <= x < LEVEL_WIDTH and 0 <= y < LEVEL_HEIGHT): return # if cursor exists, and is an object prototype, create new object if self.game.editor.object_prototype and self.game.cursor == self.game.editor.object_prototype: # obj_type = type(self.game.cursor) name = self.game.cursor.__class__.__name__ while True: if name in self.game.map.objects.keys(): name += '0' else: break dic = self.game.editor.object_prototype.create_save_dict() ch = character.Character(self.game, 0, 0, 32, 32) ch.load_from_dict(dic) self.game.map.objects[name] = ch self.game.gather_objects() self.interaction_this_click = True self.game.editor.create_undo_state()
def load_object(game, d): name = d[u'object_type'] if '_prop' in name: new_obj = prop_objects.possible_props[name[:-5]](game) else: new_obj = character.Character(game, 0, 0, 32, 32) new_obj.load_from_dict(d) return new_obj
def copy_as_template(self): # copy current char_to_edit as new template if self.char_to_edit: dic = self.char_to_edit.create_save_dict() self.char_to_edit = character.Character(self.game, 0, 0, 32, 32) self.char_to_edit.load_from_dict(dic) self.sub_editors = [] self.create_character_elements() self.char_template_name += ' - Copy' self.buttons[ 'rename_character'].text = 'Rename: ' + self.char_template_name
def load_character_template(self): fil_name = self.drop_lists['load_template'].selected if fil_name: with io.open(os.path.join(CHARACTERS_DIR, fil_name + '.char'), 'r', encoding='utf-8') as f: dic = json.load(f) self.char_to_edit = character.Character( self.game, 0, 0, 32, 32) self.char_to_edit.load_from_dict(dic) self.sub_editors = [] self.create_character_elements() self.char_template_name = fil_name # strip .char self.buttons[ 'rename_character'].text = 'Rename: ' + self.char_template_name
def func(game): ch = character.Character(game, 0, 0, 32, 32) ch.load_from_dict(dictionary) return ch
def new_character_template(self): # new default template to edit self.char_to_edit = character.Character(self.game, 0, 0, 32, 32) self.sub_editors = [] self.create_character_elements()