From f7b51576be13efd979b614402ea8ee69ec323c2f Mon Sep 17 00:00:00 2001 From: Mikk Date: Mon, 4 Mar 2024 07:43:51 -0300 Subject: [PATCH] markdown generator to html generator --- docs/entityguide/DocMaker.py | 124 ++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 52 deletions(-) diff --git a/docs/entityguide/DocMaker.py b/docs/entityguide/DocMaker.py index 4e423a3be..a8fb73770 100644 --- a/docs/entityguide/DocMaker.py +++ b/docs/entityguide/DocMaker.py @@ -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'{key}') default = "" if "default" in atributes: - default = atributes.get( "default", "" ) - f.write(f'| {default} ') + default = atributes.get("default", "") + f.write(f'{default}') 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'{type}') title = "" if "title" in atributes: - title = atributes.get( "title", "" ) - f.write(f'| {title} ') + title = atributes.get("title", "") + f.write(f'{title}') description = "" if "description" in atributes: - description = atributes.get( "description", "" ) - f.write(f'| {description} |\n') + description = atributes.get("description", "") + f.write(f'{description}\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'{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): 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('\n') + readme.write('\n') + readme.write('\n') + readme.write('\t\n') + readme.write('\t\n') + readme.write('\tWiki\n') + readme.write('\t\n') + readme.write('\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'{entity_name}
\n') + + with open(f'entities/{entity_name}.html', 'w') as f: + + f.write('\n') + f.write('\n') + f.write('\n') + f.write('\t\n') + f.write('\t\n') + f.write(f'\t{entity_name}\n') + f.write('\t\n') + f.write('\n') + f.write('\n') + + f.write(f'\t

{entity_name}

\n') + f.write(f'\t

{entity_data.get("name", "")}

\n') + f.write(f'\t

{entity_data.get("description", "")}

\n') + f.write('\t

\n') + f.write('\t

KeyValues

\n') + f.write(f'\t\n') + f.write(f'\t\n') + f.write(f'\t\t\n') + f.write(f'\t\t\n') + f.write(f'\t\t\n') + f.write(f'\t\t\n') + f.write(f'\t\t\n') + f.write(f'\t\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'
KeyValueTypeFGDDescription
\n') if "notes" in entity_data: - f.write(f'## Notes\n') - notes = entity_data.get( "notes", {} ) + f.write(f'

Notes

\n') + notes = entity_data.get("notes", {}) for num, note in notes.items(): - f.write(f'- {note}\n') + f.write(f'

{note}

\n') + + f.write('\n') + + readme.write('\n') \ No newline at end of file