Skip to content

Commit

Permalink
markdown generator to html generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk155 committed Mar 4, 2024
1 parent 39617fd commit f7b5157
Showing 1 changed file with 72 additions and 52 deletions.
124 changes: 72 additions & 52 deletions docs/entityguide/DocMaker.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,124 @@
import json

def ParseKeyValueData( f, key, atributes, data ):

if key in ["size","color","studio","iconsprite"]:
def ParseKeyValueData(f, key, atributes, data):
if key in ["size", "color", "studio", "iconsprite"]:
return

f.write(f'| {key} ')
f.write(f'<tr><td>{key}</td>')

default = ""
if "default" in atributes:
default = atributes.get( "default", "" )
f.write(f'| {default} ')
default = atributes.get("default", "")
f.write(f'<td>{default}</td>')

type = ""
if "type" in atributes:
type = atributes.get( "type", "" )
type = atributes.get("type", "")
if type == "cap":
type = "integer"
f.write(f'| {type} ')
f.write(f'<td>{type}</td>')

title = ""
if "title" in atributes:
title = atributes.get( "title", "" )
f.write(f'| {title} ')
title = atributes.get("title", "")
f.write(f'<td>{title}</td>')

description = ""
if "description" in atributes:
description = atributes.get( "description", "" )
f.write(f'| {description} |\n')
description = atributes.get("description", "")
f.write(f'<td>{description}</td></tr>\n')

if "base" in atributes:
GetBaseClass( f, atributes, data )
GetBaseClass(f, atributes, data)

if type == "choices":
if "choices" in atributes:
choices = atributes.get( "choices", {} )
choices = atributes.get("choices", {})
for choice, args in choices.items():
f.write(f'| {key} ')
f.write(f'| {choice} ')
f.write(f'| ')
f.write(f'| {args.get( "title", "" )} ')
f.write(f'| {args.get( "description", "" )} |\n')

def GetBaseClass( f, entity_data, data ):
f.write(f'<tr><td>{key}</td>')
f.write(f'<td>{choice}</td>')
f.write(f'<td></td>')
f.write(f'<td>{args.get("title", "")}</td>')
f.write(f'<td>{args.get("description", "")}</td></tr>\n')

def GetBaseClass(f, entity_data, data):
if "base" in entity_data:
base = entity_data.get( "base", "" )
bases = base.split( "," )
base = entity_data.get("base", "")
bases = base.split(",")

for dsplit in bases:
gbase = dsplit.replace( " ", "" )
gbase = dsplit.replace(" ", "")
if gbase in data:
baseclass = data.get( gbase, {} )
baseclass = data.get(gbase, {})
for key, args in baseclass.items():
ParseKeyValueData( f, key, args, data )

Choices = ""
ParseKeyValueData(f, key, args, data)

def GenerateWikiFile():
json_file = "ForgeGameData.json"
output_file = "limitlesspotential.fgd"

with open(json_file, 'r') as f:
data = json.load(f)

with open( f'README.md', 'w') as readme:
with open('entities.html', 'w') as readme:
readme.write('<!DOCTYPE html>\n')
readme.write('<html lang="en">\n')
readme.write('<head>\n')
readme.write('\t<meta charset="UTF-8">\n')
readme.write('\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n')
readme.write('\t<title>Wiki</title>\n')
readme.write('\t<link rel="stylesheet" href="styles.css">\n')
readme.write('</head>\n')

for entity_name, entity_data in data.items():

if not "Class" in entity_data:
if "Class" not in entity_data:
continue

readme.write(f'* [{entity_name}](entities/{entity_name}.md)\n')

with open( f'entities/{entity_name}.md', 'w') as f:

Choices = ""

f.write(f'# {entity_name}\n')
f.write(f'\n')
f.write(f'## {entity_data.get("name","")}\n')
f.write(f'{entity_data.get("description","")}\n')
f.write(f'\n')
f.write(f'## KeyValues\n')
f.write(f'| Key | Value | Type | FGD | Description |\n')
f.write(f'| --- | --- | --- | --- | --- |\n')
readme.write(f'<a href="entities/{entity_name}.html">{entity_name}</a><br>\n')

with open(f'entities/{entity_name}.html', 'w') as f:

f.write('<!DOCTYPE html>\n')
f.write('<html lang="en">\n')
f.write('<head>\n')
f.write('\t<meta charset="UTF-8">\n')
f.write('\t<meta name="viewport" content="width=device-width, initial-scale=1.0">\n')
f.write(f'\t<title>{entity_name}</title>\n')
f.write('\t<link rel="stylesheet" href="../styles.css">\n')
f.write('</head>\n')
f.write('</body>\n')

f.write(f'\t<h1>{entity_name}</h1>\n')
f.write(f'\t<h2>{entity_data.get("name", "")}</h2>\n')
f.write(f'\t<p>{entity_data.get("description", "")}</p>\n')
f.write('\t<p></p>\n')
f.write('\t<h2>KeyValues</h2>\n')
f.write(f'\t<table id="{entity_name}" border="1">\n')
f.write(f'\t<tr>\n')
f.write(f'\t\t<th class="centered">Key</th>\n')
f.write(f'\t\t<th class="centered">Value</th>\n')
f.write(f'\t\t<th class="centered">Type</th>\n')
f.write(f'\t\t<th class="centered">FGD</th>\n')
f.write(f'\t\t<th class="centered">Description</th>\n')
f.write(f'\t<tr>\n')

for key, args in entity_data.items():
if key in ["Class", "name", "description", "notes", "base"]:
continue

atributes = entity_data.get( key, {} )
atributes = entity_data.get(key, {})

ParseKeyValueData( f, key, atributes, data )
GetBaseClass( f, entity_data, data )
ParseKeyValueData(f, key, atributes, data)
GetBaseClass(f, entity_data, data)

f.write(f'\n')
f.write(f'</table>\n')

if "notes" in entity_data:
f.write(f'## Notes\n')
notes = entity_data.get( "notes", {} )
f.write(f'<h2>Notes</h2>\n')
notes = entity_data.get("notes", {})
for num, note in notes.items():
f.write(f'- {note}\n')
f.write(f'<p>{note}</p>\n')

f.write('</body></html>\n')

readme.write('</body></html>\n')

0 comments on commit f7b5157

Please sign in to comment.