Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed weapon docs export as markdown string
And added a Python script to generate weapon docs markdown from JSON
- Loading branch information
Showing
3 changed files
with
73 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2007-2022 The OpenRA Developers (see AUTHORS) | ||
# This file is part of OpenRA, which is free software. It is made | ||
# available to you under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation, either version 3 of | ||
# the License, or (at your option) any later version. For more | ||
# information, see COPYING. | ||
|
||
import argparse | ||
import json | ||
from collections import OrderedDict | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('input', type=str) | ||
parser.add_argument('output', type=str) | ||
args = parser.parse_args() | ||
|
||
inputFile = open(args.input, "r") | ||
weaponInfo = json.loads(inputFile.read()) | ||
inputFile.close() | ||
|
||
weaponsByNamespace = OrderedDict() | ||
for currentWeapon in weaponInfo["WeaponTypes"]: | ||
if currentWeapon["Namespace"] in weaponsByNamespace: | ||
weaponsByNamespace[currentWeapon["Namespace"]].append(currentWeapon) | ||
else: | ||
weaponsByNamespace[currentWeapon["Namespace"]] = [currentWeapon] | ||
|
||
version = weaponInfo["Version"] | ||
|
||
outputFile = open(args.output, "w") | ||
outputFile.write("#### This documentation is aimed at modders. It displays a template for weapon definitions " + | ||
"as well as its contained types (warheads and projectiles) with default values and developer commentary. " + | ||
"Please do not edit it directly, but add new `[Desc(\"String\")]` tags to the source code.\n\n") | ||
|
||
outputFile.write(f"This file has been automatically generated for version **{version}** of OpenRA.") | ||
outputFile.write('\n\n#\n\n') | ||
|
||
for namespace in weaponsByNamespace: | ||
outputFile.write(f'## {namespace}\n') | ||
outputFile.write('\n') | ||
|
||
for weapon in weaponsByNamespace[namespace]: | ||
outputFile.write(f'### {weapon["Name"]}\n') | ||
outputFile.write(f'#### {weapon["Description"]}\n') | ||
|
||
if weapon["InheritedTypes"]: | ||
outputFile.write("Inherits from: " + ", ".join([f'`{x}`' for x in weapon["InheritedTypes"]]) + '\n') | ||
|
||
outputFile.write('\n') | ||
outputFile.write('| Property | Default Value | Type | Attributes | Description |\n') | ||
outputFile.write('| -------- | ------------- | ---- | ---------- | ----------- |\n') | ||
|
||
for prop in weapon["Properties"]: | ||
attributesList = [f'{x["Name"]}{"(" + str(x["Value"][0]) + ")" if x["Value"] else ""}' for x in prop["OtherAttributes"] if x["Name"]] | ||
if not attributesList: | ||
attributes = '' | ||
else: | ||
attributes = ", ".join(attributesList) | ||
|
||
outputFile.write(f'| {prop["Name"]} | {prop["DefaultValue"]} | {prop["Type"]} | {attributes} | {prop["Description"]} |\n') | ||
|
||
outputFile.write('\n\n') | ||
|
||
outputFile.close() |