Browse Source

Add HTML formatting

master
Noëlle 3 years ago
parent
commit
5235fbb981
1 changed files with 56 additions and 20 deletions
  1. 56
    20
      koboldgen.py

+ 56
- 20
koboldgen.py View File

@@ -35,7 +35,7 @@ class Plot:
{
"id": 1,
"name": "a rival band of kobolds",
"shortname": "kobolds",
"shortname": "kobold rivals",
"stats": [3,3,4,4],
},
{
@@ -178,15 +178,23 @@ class Character:
def gen_career(self):
self.career = r.choice(["Soldier/Guard","Pilot","Medic","Mechanic","Politician","Spellcaster","Performer","Historian","Spy","Cook","Cartographer","Inventor","Merchant"])

def print_name(self):
print(f"Name: {self.name} (Kobold {self.career})")
def print_name(self, html=False):
if html:
charText = f"<br>\n<h4>Name: {self.name} (Kobold {self.career})</h4>"
else:
charText = f"\nName: {self.name} (Kobold {self.career})"
print(charText)

def print(self, html=False):
self.print_name()
print(f"Order: {self.stats[0]}")
print(f"Chaos: {self.stats[1]}")
print(f"Brain: {self.stats[2]}")
print(f"Body: {self.stats[3]}")
self.print_name(html)
if html:
endc = "<br>\n"
else:
endc = "\n"
print(f"Order: {self.stats[0]}", end=endc)
print(f"Chaos: {self.stats[1]}", end=endc)
print(f"Brain: {self.stats[2]}", end=endc)
print(f"Body: {self.stats[3]}", end=endc)

class Ship:
def __init__(self):
@@ -197,8 +205,11 @@ class Ship:
self.fullname = f"{self.name1} {self.name2}"

def print(self, html=False):
print(f"The {self.fullname} {self.gqual}, but {self.bqual}.")
print()
if (html):
shipText = f"<p>The <strong>{self.fullname}</strong> <span style='color: blue;'>{self.gqual}</span>, but <span style='color: red;'>{self.bqual}</span>.</p>\n"
else:
shipText = f"The {self.fullname} {self.gqual}, but {self.bqual}.\n"
print(shipText)

class Campaign:
def __init__(self, n=None, makeChars=True):
@@ -214,25 +225,50 @@ class Campaign:
self.art = "an" if self.params.loc_desc[0] in ["a","e","i","o","u"] else "a"


def print_params(self, endc="", html=False):
def print_params(self, endc=" ", html=False):
st = ["Order:", "Chaos:", "Brains:", "Body:"]
print(f"The Kobolds of the {self.ship.fullname} ", end=endc)
print(f"have been sent out to {self.art} {self.params.loc_desc} {self.params.location} ", end=endc)
print(f"in order {self.params.mission} ", end=endc)
print(f"-- but they're challenged by {self.params.fullProblem}!")
cst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.problem["stats"]]))])
print(f"The stats of the {self.params.problem['shortname']}: {cst}")
lines = [
f"The Kobolds of the {self.ship.fullname}",
f"have been sent out to {self.art} {self.params.loc_desc} {self.params.location}",
f"in order {self.params.mission}",
f"but they're challenged by {self.params.fullProblem}!",
f"The stats of the {self.params.problem['shortname']}",
f"{cst}"
]
if self.params.secProblem:
mst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.secProblem["stats"]]))])
print(f"- The stats of the {self.params.secProblem['shortname']}: {mst}")
lines.append(f"The stats of the {self.params.secProblem['shortname']}")
lines.append(f"{mst}")
if self.params.thirdProblem:
pst = ", ".join([" ".join(y) for y in list(zip(st, [str(x) for x in self.params.thirdProblem["stats"]]))])
print(f"- - The stats of the {self.params.thirdProblem['shortname']}: {pst}")
print()
lines.append(f"The stats of the {self.params.thirdProblem['shortname']}")
lines.append("{pst}")
if html:
print(f"<h2>{lines[0]}</h2>")
print(f"<p>{lines[1]} <strong>{lines[2]}</strong> --</p>")
print(f"<p><em>{lines[3]}</em></p>")
print(f"<p>{lines[4]}: {lines[5]}")
if self.params.secProblem:
print(f"<p style='padding-left: 10px;'>{lines[6]}: {lines[7]}</p>")
if self.params.thirdProblem:
print(f"<p style='padding-left: 20px;'>{lines[8]}: {lines[9]}</p>")
print("</p>\n<br>")
else:
print(f"{lines[0]} {lines[1]} {lines[2]} -- {lines[3]}")
print(f"{lines[4]}: {lines[5]}")
if self.params.secProblem:
print(f"- {lines[6]}: {lines[7]}")
if self.params.thirdProblem:
print(f"- - {lines[8]}: {lines[9]}")
print()
self.ship.print(html=html)

def print_chars(self, html=False):
print("The kobolds:")
if html:
print("<h3>The kobolds:</h3>")
else:
print("The kobolds:")
for k in self.characters:
k.print(html=html)


Loading…
Cancel
Save