Dateien von pykerker übernommen.
This commit is contained in:
120
WorldParser.py
Normal file
120
WorldParser.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
from data.Raum import Raum, Befehl, Gegenstand,Person,TextNode
|
||||
import io
|
||||
import logging
|
||||
|
||||
class WorldParser():
|
||||
|
||||
def __init__(self,world):
|
||||
self.neuerRaum = None
|
||||
self.world = world
|
||||
self.textCount = 0
|
||||
|
||||
def parseWorld(self,filename):
|
||||
tree = ET.parse(filename)
|
||||
root = tree.getroot()
|
||||
|
||||
for item in root.findall('ebene/raum'):
|
||||
id = item.attrib['id']
|
||||
name = item.attrib['name']
|
||||
beschreibung = ''
|
||||
# Beschreibung
|
||||
for text in item.iter():
|
||||
if text != None and text.text != None:
|
||||
beschreibung = beschreibung + text.text.strip()
|
||||
# Ausgaenge
|
||||
raum = Raum(name,id, beschreibung)
|
||||
ausgaenge = item.findall('ausgang')
|
||||
|
||||
for ausgang in ausgaenge:
|
||||
dir = ausgang.attrib['dir']
|
||||
nachRaum = ausgang.attrib['nachRaum']
|
||||
|
||||
print('Raum: ' + raum.name + '- dir=' + dir + ',nachRaum=' + nachRaum)
|
||||
if dir == 'Nord':
|
||||
raum.ausgaenge[self.world.NORD] = nachRaum
|
||||
elif dir == 'Sued':
|
||||
raum.ausgaenge[self.world.SUED] = nachRaum
|
||||
elif dir == 'West':
|
||||
raum.ausgaenge[self.world.WEST] = nachRaum
|
||||
elif dir == 'Ost':
|
||||
raum.ausgaenge[self.world.OST] = nachRaum
|
||||
elif dir == 'Rauf':
|
||||
raum.ausgaenge[self.world.RAUF] = nachRaum
|
||||
elif dir == 'Runter':
|
||||
raum.ausgaenge[self.world.RUNTER] = nachRaum
|
||||
|
||||
|
||||
self.world.raumliste[id] = raum
|
||||
startr = root.find('startraum')
|
||||
print(startr)
|
||||
print(startr.attrib['id'])
|
||||
startraum = self.world.sucheRaum(startr.attrib['id'])
|
||||
self.world.aktuellerRaum = startraum
|
||||
print('Startraum gefunden.')
|
||||
print(startraum)
|
||||
|
||||
#Befehle
|
||||
for befehl in root.findall('commandset/command'):
|
||||
name = befehl.attrib['name']
|
||||
id = befehl.attrib['id']
|
||||
key = befehl.attrib['key']
|
||||
command = Befehl(name,id,key)
|
||||
|
||||
self.world.befehle[id] = command
|
||||
|
||||
# Sortouts
|
||||
for sortout in root.findall('sortouts/sortout'):
|
||||
name = sortout.attrib['name']
|
||||
self.world.sortouts.append(name)
|
||||
# Messages
|
||||
for msg in root.findall('messages/pickup'):
|
||||
id = msg.attrib['id']
|
||||
text = msg.attrib['text']
|
||||
self.world.msg[id] = text
|
||||
|
||||
# Gegenstände
|
||||
for item in root.findall('items/item'):
|
||||
name = item.attrib['name']
|
||||
id = item.attrib['id']
|
||||
msgid = item.attrib['msgid']
|
||||
raumid = item.attrib['raum']
|
||||
gegenstand = Gegenstand(name,id,raumid)
|
||||
imobil = item.attrib['imobil']
|
||||
visible = item.attrib['visible']
|
||||
raum = self.world.sucheRaum(raumid)
|
||||
gegenstand.raum = raum.id
|
||||
gegenstand.imobil = imobil.lower() in ['true','True','1']
|
||||
logging.debug('itemid= ' + id + ',visible= ' + visible)
|
||||
gegenstand.sichtbar = visible.lower() not in ['false','False','0']
|
||||
logging.debug('Gegenstand ' + gegenstand.name + ' ist sichtbar: ' + str(gegenstand.sichtbar))
|
||||
gegenstand.pickupmsg = msgid
|
||||
print('Item ' + gegenstand.name + ' - Pickup: ' + gegenstand.pickupmsg)
|
||||
|
||||
raum.items[id] = gegenstand
|
||||
self.world.gegenstaende[id] = gegenstand
|
||||
|
||||
# Personen
|
||||
for item in root.findall('personen/person'):
|
||||
name = item.attrib['name']
|
||||
id = item.attrib['id']
|
||||
move = item.attrib['bewegung']
|
||||
|
||||
raumid = item.attrib['raum']
|
||||
person = Person(name,id,raum)
|
||||
self.world.personen[id] = person
|
||||
raum = self.world.sucheRaum(raumid)
|
||||
raum.personen[raumid] = person
|
||||
|
||||
# Texte
|
||||
for item in root.findall('texte/text'):
|
||||
id = item.attrib['id']
|
||||
print('Id: ' + id+ ' Text ' + item.text)
|
||||
textnode = TextNode(id,item.text)
|
||||
self.world.texte[id] = textnode
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user