def loadObjectData(): '''LOAD OBJECT DATA reads the CFG files in the data folder to build dictionaries of monsters, items, and name generation data.''' parser = libtcod.parser_new() #Use the parser to read data for monsters. monsterStruct = libtcod.parser_new_struct(parser, "monster") libtcod.struct_add_property(monsterStruct, "name", libtcod.TYPE_STRING, True) libtcod.struct_add_property(monsterStruct, "glyph", libtcod.TYPE_CHAR, True) libtcod.struct_add_property(monsterStruct, "col", libtcod.TYPE_COLOR, True) libtcod.struct_add_property(monsterStruct, "dsc", libtcod.TYPE_STRING, True) libtcod.struct_add_property(monsterStruct, "tier", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "hp", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "atk", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "dfn", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "min", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "max", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "xp", libtcod.TYPE_INT, True) libtcod.struct_add_property(monsterStruct, "deathEffect", libtcod.TYPE_STRING, False) libtcod.parser_run(parser, os.path.join('data', 'monster.cfg'), MonsterReader()) if option_debug: print "The current contents of rawMonsterData, outside of the parsing operation, are..." print rawMonsterData.items() #Use the parser to read data for items. itemStruct = libtcod.parser_new_struct(parser, "item") libtcod.struct_add_property(itemStruct, "name", libtcod.TYPE_STRING, True) libtcod.struct_add_property(itemStruct, "kind", libtcod.TYPE_STRING, True) libtcod.struct_add_property(itemStruct, "col", libtcod.TYPE_COLOR, True) libtcod.struct_add_property(itemStruct, "dsc", libtcod.TYPE_STRING, True) libtcod.struct_add_property(itemStruct, "bloat", libtcod.TYPE_INT, False) libtcod.struct_add_property(itemStruct, "rarity", libtcod.TYPE_INT, True) libtcod.struct_add_property(itemStruct, "useEffect", libtcod.TYPE_STRING, False) #libtcod.struct_add_property(itemStruct, "slot", libtcod.TYPE_STRING, False) libtcod.parser_run(parser, os.path.join('data', 'item.cfg'), ItemReader()) if option_debug: print "The current contents of rawItemData, outside of the parsing operation, are..." print rawItemData.items() #Load the name generation data. for file in os.listdir('data/name'): if file.find('.cfg') > 0: libtcod.namegen_parse(os.path.join('data', 'name', file)) rawNameSets = libtcod.namegen_get_sets()
def place_ants(number): global farm, entities spots = farm.standable_locations() if len(spots) > 0: for i in range(number): (x, y) = choice(spots) entities.append(Ant(x, y, '@', libtcod.black, farm, libtcod.namegen_generate(choice(libtcod.namegen_get_sets()))))
def test_namegen_parse(): libtcodpy.namegen_parse('../data/namegen/jice_celtic.cfg') assert libtcodpy.namegen_generate('Celtic female') assert libtcodpy.namegen_get_sets() libtcodpy.namegen_destroy()