Files
pytomb/HilfeModul.py
2022-06-30 14:54:40 +02:00

77 lines
1.8 KiB
Python

import logging
import FileReader
from os.path import exists
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
self.check()
def readTxt(self, datei):
logging.debug(f'öffne Hilfedatei {datei}')
reader = FileReader.FileReader(datei)
lines = reader.lines()
reader = None
# reader.close()
return lines
def check(self):
for id in self.world.befehle:
befehl = self.world.befehle[id]
helptxt = self.baueHilfedatei(befehl.key)
logging.debug(f'suche Hilfedatei {helptxt}')
if not exists(helptxt):
logging.warn(f'Hilfedatei {helptxt} existiert nicht')
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 baueHilfedatei(self, key):
return f'ascii/hilfe/cmd-{key}.txt'
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 self.baueHilfedatei(befehl.key)
return None