61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
import logging
|
|
import FileReader
|
|
|
|
class HilfeModul():
|
|
|
|
def isBlank(self,str):
|
|
if str != None and len(str.strip()) == 0:
|
|
return True
|
|
return False
|
|
|
|
def __init__(self, world):
|
|
|
|
self.world = world
|
|
|
|
def readTxt(self, datei):
|
|
|
|
logging.debug(f'öffne Hilfedatei {datei}')
|
|
reader = FileReader.FileReader(datei)
|
|
|
|
lines = reader.lines()
|
|
reader = None
|
|
# reader.close()
|
|
|
|
return lines
|
|
|
|
def hilfe(self, command):
|
|
generalHelp = True
|
|
if not self.isBlank(command):
|
|
helptxt = self.findHilfetext(command)
|
|
|
|
logging.debug(f'Hilfetext: {helptxt}')
|
|
|
|
if helptxt != None:
|
|
lines = self.readTxt(helptxt)
|
|
logging.debug(f'lines: {lines}')
|
|
self.world.printHilfe(lines)
|
|
generalHelp = False
|
|
|
|
if generalHelp:
|
|
if command == 'befehle':
|
|
self.world.printBefehle()
|
|
else:
|
|
self.world.printText('hilfe')
|
|
|
|
def findHilfetext(self, command):
|
|
|
|
logging.debug(f'suche Hilfetext zu {command}')
|
|
|
|
for cmdid in range(0,len(self.world.befehle)):
|
|
if str(cmdid) in self.world.befehle:
|
|
befehl = self.world.befehle[str(cmdid)]
|
|
|
|
logging.debug(f'cmdid= {cmdid}')
|
|
|
|
# logging.debug(f'vergleiche {befehl.name.lower()} mit {command.lower()}')
|
|
|
|
if befehl.name.lower() == command.lower():
|
|
logging.debug(f'gefundener Befehl: {befehl.name}')
|
|
return f'ascii/hilfe/cmd-{befehl.key}.txt'
|
|
|
|
return None |