コード例 #1
0
 def test_02_check_mappings(self):
     fle = os.path.join(pth, 'samples', 'tiny_world.yaml')
     y = sample._read_yaml(fle)
     
     print('mappings[0] = ', y['mappings'][0])
     print('mappings[1] = ', y['mappings'][1])
     
     self.assertEqual(y['mappings'][1], {'people <<': [{'name': 'cat'}]})
コード例 #2
0
 def test_01_read_yaml_tiny(self):
     fle = os.path.join(pth, 'samples', 'tiny_world.yaml')
     
     # _print_yaml(fle)  # works
     y = sample._read_yaml(fle)
     pprint.pprint(y) 
     self.assertEqual(y['rooms'][0]['name'], 'kitchen')
     self.assertEqual(y['rooms'][1]['name'], 'lounge')
     
     self.assertEqual(y['objects'][0]['name'], 'chair')
     self.assertEqual(y['objects'][1]['name'], 'ball')
     
     self.assertEqual(y['characters'][0]['name'], 'cat')
コード例 #3
0
ファイル: wiki.py プロジェクト: acutesoftware/worldbuild
def create_wiki_from_yaml(src_fldr, fname, op_fldr):
    dat = sample._read_yaml(fname)
    if 'wiki' not in dat:
        print('missing wiki: Yes tag, so cant generate wiki for ' + fname)
        return
    if 'contents' not in dat:
        print('missing content tag, so cant generate wiki for ' + fname)
        return

    # first create the folder where the wiki files will live
    if not os.path.exists(op_fldr):
        print('Creating output folder ', op_fldr)
        os.makedirs(op_fldr)
    shutil.copyfile(os.path.join(src_fldr, dat['maps'][0]), os.path.join(op_fldr, 'map_full.jpg'))    
    shutil.copyfile(os.path.join(src_fldr, 'worldbuild.css'), os.path.join(op_fldr, 'worldbuild.css'))    
    shutil.copyfile(os.path.join(src_fldr, 'paper-texture.jpg'), os.path.join(op_fldr, 'paper-texture.jpg'))    
 
    # TODO - copy ALL jpgs to wiki_op shutil.copy(os.path.join(src_fldr, '*.jpg'), op_fldr)    
    
    # make a medium size image of the full map for main page
    image_utils.make_map_medium(os.path.join(src_fldr, dat['maps'][0]),  os.path.join(op_fldr, 'map_med.jpg'))
    
    
    # make the main page
    ndx_page = os.path.join(op_fldr, dat['world_name'] + '.html')
    with open(ndx_page, 'w') as f:
        f.write(html_utils.get_header(dat['world_name']))
        f.write(get_world_build_menu(dat, 'Welcome to ' + dat['world_name']))
        
        f.write('<div id = content><div id = "map">\n')
        f.write('<center><a href="map_full.jpg"><img src="map_med.jpg"></a></center><BR>') #YUCK - hard coded CSS - TODO
        f.write('<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR></div>\n')

        
        f.write(html_utils.get_footer(''))
            
    # make the individual pages
    for chap in dat['contents']:
        op_file = os.path.join(op_fldr, chap + '.html')
        with open(op_file, 'w') as f2:
            f2.write(html_utils.get_header(dat['world_name']))
            f2.write(get_world_build_menu(dat, dat['world_name'] + ': ' + chap))
            f2.write(format_yaml_section(dat[chap], chap, dat, src_fldr, op_fldr))
            f2.write(html_utils.get_footer(''))
コード例 #4
0
    def test_01_read_yaml_game(self):
        fle = os.path.join(pth, 'samples', 'game.yaml')
        
        # _print_yaml(fle)  # works
        y = sample._read_yaml(fle)
        #pprint.pprint(y)
        # {'Monsters': [{'ac': 16,
                       # 'attacks': ['BITE', 'HURT'],
                       # 'hp': [2, 6],
                       # 'name': 'Cave spider'},
                      # {'ac': 26,
                       # 'attacks': ['CRUSH', 'HIT'],
                       # 'hp': [5, 7],
                       # 'name': 'Troll'}]}    
        
        self.assertTrue(len(str(y)) > 600)
        
        #for m in y['Monsters']:
        #    print(m['name'], m['attacks'])
            # > Cave spider ['BITE', 'HURT']
            # > Troll ['CRUSH', 'HIT']
            
        self.assertEqual(y['Monsters'][0]['ac'], 16)
        self.assertEqual(y['Monsters'][1]['ac'], 26)
       
        self.assertEqual( y['Objects'][3], 'Cheese')
        
        #pprint.pprint(sample.convert_yaml_to_json(fle))
        #pprint.pprint(sample.convert_json_to_yaml(''))
        
        
        self.assertEqual(y['actions'][0]['name'], 'Smite')
        self.assertEqual(y['actions'][1]['name'], 'Fireball')
        self.assertEqual(y['actions'][2]['name'], 'Magic Missile')
        
     


        self.assertTrue(os.path.exists(fle))