Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.etree.ElementTree as ET
- import urllib2, re
- levels = 'http://mspaintadventures.com/storyfiles/hs2/05305/levels/openbound_p2/'
- resources = 'http://mspaintadventures.com/storyfiles/hs2/05305/resources/openbound_p2/'
- dialogue_files = ['cronusDialog.xml','expoDialog.xml','karkatDialog.xml','kurlozDialog.xml','meenahDialog.xml','meulinDialog.xml','mitunaDialog.xml','tereziDialog.xml']
- asset_files = ['etc/ui.xml','rooms/fourthRoom.xml','chars/andrew.xml','chars/aranea.xml','chars/bicyclops.xml','chars/cronus.xml','chars/kankri.xml','chars/karkat.xml','chars/kurloz.xml','chars/meenah.xml','chars/meulin.xml','chars/mituna.xml','chars/seahorsedad.xml','chars/terezi.xml']
- assets = {}
- for f in asset_files:
- data = urllib2.urlopen(levels + f).read()
- tree = ET.fromstring(data)
- for asset in tree.iter('asset'):
- if asset.get('type') != 'graphic':
- continue
- assets[asset.get('name')] = resources + asset.text
- conversations = []
- styles = {"dialogBox":True}
- for f in dialogue_files:
- data = urllib2.urlopen(levels + 'dialogs/' + f).read()
- tree = ET.fromstring(data)
- for talk in tree.iter('action'):
- if talk.get('command') != 'talk':
- continue
- args = talk.find('args')
- if args is None:
- print "Failure :(",f,repr(list(talk))
- continue
- convo = []
- for match in re.finditer('@([^:\s~]*)(?:(?:~([^\s]*))|(?::([^\s]*))? (?:([^@:]*):)?([^@]*))', args.text):
- sprite, image, hashtags, actor, dialogue = match.groups()
- sprite, chaff, background = sprite.partition("%")
- if image:
- image, chaff, override = image.partition(":")
- if override and not hashtags:
- hashtags = override
- image = "%sinterface/backgrounds/%s.png" % (resources, image) if image else ''
- hashtags = hashtags.replace('-',' ').replace('#',' #').strip() if hashtags else ''
- actor = actor.lower() if actor else ''
- dialogue = dialogue.strip() if dialogue else ''
- # Check for andrew
- if sprite == "!":
- sprite = ""
- elif sprite:
- styles[sprite] = True
- if not sprite and not actor:
- actor = "andrew"
- if background:
- styles[background] = True
- convo.append({'sprite': sprite, 'image': image, 'hashtags': hashtags, 'actor': actor, 'dialogue': "%s: %s" % (actor.upper(), dialogue), 'background': background if background else "dialogBox"})
- conversations.append(convo)
- css = []
- template = "\t\t.%s { background-image: url('%s'); }"
- for key in styles.iterkeys():
- if key in assets:
- css.append(template % (key, assets[key]))
- css = "\n".join(css)
- text = ""
- html = """<!doctype html>
- <html><head>
- <meta charset="UTF-8">
- <title>Openbound Dialogue</title>
- <style>
- @font-face { font-family: Sburb; src: url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/fonts/cour.ttf'), url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/fonts/cour.woff'); }
- body { font-size: 14px; font-weight: bold; font-family: Courier New, Courier, Sburb; }
- .conversation { clear: both; border-bottom: 3px solid black; }
- .dialogue { float: left; margin: 10px; }
- .sprite { height: 325px; width: 230px; float: left; background-size: 100%% auto; background-repeat: no-repeat; }
- .words { float: left; height: 325px; width: 537px; }
- .text { height: 230px; width: 497px; padding: 20px; }
- .text span { overflow: auto; }
- .text img { margin: -25px; }
- .hashtags { position: relative; color: black; height: 29px; width: 497px; padding: 13px 20px; background: url('http://mspaintadventures.com/storyfiles/hs2/05260/resources/openbound/interface/hashtagbar.png'); }
- .permalink { position: absolute; bottom: 10px; right: 10px; font-size: 10px; font-weight: normal; }
- .meenah { color: #77003c; } .aranea { color: #005682; } .porrim { color: #008141; } .kankri { color: #ff0000; font-size: 12px; }
- .latula { color: #008282; } .aradia { color: #a10000; } .nepeta { color: #416600; } .vriska { color: #005682; }
- .tavros { color: #a15000; } .eridan { color: #6a006a; } .feferi { color: #77003c; } .karkat { color: #626262; }
- .equius { color: #000056; } .kanaya { color: #008141; } .terezi { color: #008282; } .sollux { color: #a1a100; }
- .gamzee { color: #2b0057; } .dave { color: #e00707; } .rose { color: #b536da; }
- .cronus { color: #6a006a; } .mituna { color: #a1a100; } .kurloz { color: #6c00da; } .meulin { color: #416600; }
- %s
- </style>
- </head><body>
- """ % css
- id = 1
- for convo in conversations:
- html += '\t<div class="conversation">\n'
- for c in convo:
- template = '\t\t<div id="dialogue-%d" class="dialogue %s"><div class="sprite %s"></div><div class="words"><div class="text %s">%s</div><div class="hashtags">%s<a class="permalink" href="#dialogue-%d">Permalink</a></div></div></div>\n'
- args = (id, c['actor'], c['sprite'], c["background"], '<img src="%s" />' % c['image'] if c['image'] else '<span>%s</span>' % c['dialogue'], c['hashtags'], id)
- html += template % args
- text += "%s %s\n" % (c['image'], c['hashtags']) if c['image'] else "%s %s\n" % (c['dialogue'], c['hashtags'])
- id += 1
- html += '\t</div>\n'
- text += "\n"
- html += '</body></html>'
- with open("openbound2_dialogue.html","w") as f:
- f.write(html.encode("utf-8"))
- with open("openbound2_dialogue.txt","w") as f:
- f.write(text.encode("utf-8"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement