Open source Star Ruler 2 source code!

This commit is contained in:
Lucas de Vries
2018-07-17 14:15:37 +02:00
commit cc307720ff
4342 changed files with 2365070 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/python
import os
import sys
import json
from mako.template import Template
from mako.lookup import TemplateLookup
import pprint
def main(infile, outdir):
# Load JSON
data = json.load(open(infile))
tmpl = TemplateLookup(directories=["source/doc/"])
tmpl_engine = ""
tmpl_edata = None
def render(template, filename, data):
result = tmpl.get_template(template).render(
engine = tmpl_engine,
data = tmpl_edata,
**data)
with open(os.path.join(outdir, filename), "w") as fl:
fl.write(result)
# Render CSS
render("template.styles.css", "styles.css", data)
render("template.top.html", "index.html", data)
# Output data files
for engine, edata in data.items():
tmpl_engine = engine
tmpl_edata = edata
edata["classmap"] = {c["name"] for c in edata["classes"]}
edata["enummap"] = {e["name"] for e in edata["enums"]}
render("template.index.html", "%s.index.html" % engine, edata)
render("template.globals.html", "%s.globals.html" % engine, edata)
render("template.functions.html", "%s.functions.html" % engine, edata)
for cls in edata["classes"]:
render("template.class.html", "%s.class.%s.html" % (engine, cls["name"]), cls)
for en in edata["enums"]:
render("template.enum.html", "%s.enum.%s.html" % (engine, en["name"]), en)
if __name__ == '__main__':
infile = sys.argv[1] if len(sys.argv) >= 2 else "api_documentation.json"
outdir = sys.argv[2] if len(sys.argv) >= 3 else "api_documentation/"
try:
os.makedirs(outdir)
except:
pass
main(infile, outdir)
# vim: ff=unix :
+152
View File
@@ -0,0 +1,152 @@
import resources;
import orbitals;
import buildings;
void dumpImages() {
//Dump materials
uint cnt = getMaterialCount();
for(uint i = 0; i < cnt; ++i) {
auto@ mat = getMaterial(i);
if(mat.texture0 is null || mat.texture1 !is null)
continue;
string fname = "images/"+getMaterialName(i)+".png";
print("dumping "+fname);
Image img(Sprite(mat));
img.save(fname);
}
//Dump sprites
cnt = getSpriteSheetCount();
for(uint i = 0; i < cnt; ++i) {
const SpriteSheet@ sheet = getSpriteSheet(i);
if(sheet.material.texture0 is null || sheet.material.texture1 !is null)
continue;
Image img(Sprite(sheet.material));
uint spriteCount = sheet.count;
string name = getSpriteSheetName(i);
for(uint j = 0; j < spriteCount; ++j) {
recti source = sheet.getSource(j);
string fname = "images/"+name+"::"+j+".png";
print("dumping "+fname);
Image sprite(img, source);
sprite.save(fname);
}
}
}
string makeReference(const Sprite& image, const string& name, const string& tooltip, int width = -1) {
string res;
res += "<span onmouseover=\"children[0].style.display = 'block'; children[0].style.top = offsetTop; children[0].style.left = offsetLeft; return true;\" onmouseout=\"children[0].style.display = 'none';\" style=\"display: inline-block; background: #eeeeee;\">\n";
res += "<span style=\"display: none; position: absolute; margin-top: 25px; width: 250px; background: #343434; color: white; border: 1px solid #666666; padding: 4px; font-style: normal;\">\n";
res += tooltip.replaced("\n", "[br/]");
res += "</span>\n";
if(!image.valid)
res += format("$1</span>", name);
else if(width > 0)
res += format("<img src=\"images/$1.png\" width=\"$3\"/> $2</span>",
getSpriteDesc(image), name, toString(width));
else
res += format("<img src=\"images/$1.png\"/> $2</span>",
getSpriteDesc(image), name);
return res;
}
string makeListing(const Sprite& image, const string& name, const string& desc, int width = -1) {
string res;
if(image.valid) {
if(width > 0)
res += format("[img=$1;$2]",
getSpriteDesc(image), toString(width));
else
res += format("[img=$1]",
getSpriteDesc(image));
}
if(name.length > 0)
res += format("[font=Subtitle][b]$1[/b][/font][br/]", name);
if(desc.length > 0)
res += desc.replaced("\n", "[br/]");
if(image.valid)
res += "[/img]";
return res;
}
void dumpTemplates() {
//Resource templates
uint cnt = getResourceCount();
for(uint i = 0; i < cnt; ++i) {
const ResourceType@ type = getResource(i);
{
string fname = format("templates/resource_ref;$1", type.ident);
print("dumping "+fname);
WriteFile file(fname);
file.writeLine(makeReference(type.smallIcon, type.name, getResourceTooltip(type)));
}
{
string fname = format("templates/resource;$1", type.ident);
print("dumping "+fname);
WriteFile file(fname);
string name = type.name;
if(type.rarity > RR_Common)
name = format("[color=$1]$2[/color]", toString(getResourceRarityColor(type.rarity)), name);
name += format(" [img=$1;20/]", getSpriteDesc(type.smallIcon));
file.writeLine(makeListing(type.icon, name, getResourceTooltip(type, null, null, false)));
}
}
//Orbital templates
cnt = getOrbitalModuleCount();
for(uint i = 0; i < cnt; ++i) {
const OrbitalModule@ type = getOrbitalModule(i);
{
string fname = format("templates/orbital_ref;$1", type.ident);
print("dumping "+fname);
WriteFile file(fname);
file.writeLine(makeReference(Sprite(), type.name, type.getTooltip()));
}
{
string fname = format("templates/orbital;$1", type.ident);
print("dumping "+fname);
WriteFile file(fname);
string name = type.name;
file.writeLine(makeListing(Sprite(), name, type.getTooltip()));
}
}
//Building templates
cnt = getBuildingTypeCount();
for(uint i = 0; i < cnt; ++i) {
const BuildingType@ type = getBuildingType(i);
{
string fname = format("templates/building_ref;$1", type.ident);
print("dumping "+fname);
WriteFile file(fname);
file.writeLine(makeReference(type.sprite, type.name, type.getTooltip(), 22));
}
{
string fname = format("templates/building;$1", type.ident);
print("dumping "+fname);
WriteFile file(fname);
string name = type.name;
file.writeLine(makeListing(type.sprite, name, type.getTooltip(false)));
}
}
}
+63
View File
@@ -0,0 +1,63 @@
<%namespace file="template.util.html" name="util" />
<!DOCTYPE html>
<title>${name}</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<section class="classdoc">
<h1>${name}</h1>
% if doc:
<span>${doc}</span>
% endif
</section>
% if len(members):
<section class="classmembers">
<h2>Members</h2>
<ul>
% for m in members:
<li>
<b>${util.type(m["type"])} ${m["name"]}</b>
% if "doc" in m:
&mdash; ${m["doc"]}
% endif
</li>
% endfor
</ul>
</section>
% endif
% if len(methods):
<section class="classmethods">
<h2>Methods</h2>
<ul>
% for i, m in enumerate(methods):
<li>${util.func(m, "#"+str(i) if "doc" in m else None)}</li>
% endfor
</ul>
</section>
% endif
% for i, m in enumerate(methods):
% if "doc" in m:
<section class="method">
<h3><a name="${i}" class="anchor">${util.func(m)}</a></h2>
<span>${m["doc"]}</span>
% if len(m["arguments"]):
<ul>
% for a in m["arguments"]:
% if "doc" in a and a["doc"]:
<li>
<b>${util.type(a["type"])} ${a["name"]}</b> &mdash; ${a["doc"]}
</li>
% endif
% endfor
</ul>
% endif
% if "doc" in m["return"]:
<span><b>Returns ${util.type(m["return"]["type"])}:</b> ${m["return"]["doc"]}</span>
% endif
</section>
% endif
% endfor
+19
View File
@@ -0,0 +1,19 @@
<%namespace file="template.util.html" name="util" />
<!DOCTYPE html>
<title>${name}</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<section class="enumdoc">
<h1>${name}</h1>
% if doc:
<span>${doc}</span>
% endif
</section>
<section class="enumvalues">
<ul>
% for v in values:
<li>${v}</li>
% endfor
</ul>
</section>
+38
View File
@@ -0,0 +1,38 @@
<%namespace file="template.util.html" name="util" />
<!DOCTYPE html>
<title>${engine} - Functions</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<section class="functions">
<h2>Functions</h2>
<ul>
% for i, m in enumerate(functions):
<li>${util.func(m, "#"+str(i) if "doc" in m else None)}</li>
% endfor
</ul>
</section>
% for i, m in enumerate(functions):
% if "doc" in m:
<section class="method">
<h3><a name="${i}" class="anchor">${util.func(m)}</a></h2>
<span>${m["doc"]}</span>
% if len(m["arguments"]):
<ul>
% for a in m["arguments"]:
% if "doc" in a and a["doc"]:
<li>
<b>${util.type(a["type"])} ${a["name"]}</b> &mdash; ${a["doc"]}
</li>
% endif
% endfor
</ul>
% endif
% if "doc" in m["return"]:
<span><b>Returns ${util.type(m["return"]["type"])}:</b> ${m["return"]["doc"]}</span>
% endif
</section>
% endif
% endfor
+27
View File
@@ -0,0 +1,27 @@
<%namespace file="template.util.html" name="util" />
<!DOCTYPE html>
<title>${engine} - Globals</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<%
ns = {}
for g in globals:
if g["ns"] not in ns:
ns[g["ns"]] = []
ns[g["ns"]].append(g)
%>
% for name, n in ns.items():
<section class="globals">
<h2>${name if name else "Globals"}</h2>
<ul>
% for g in n:
<li>
<b>${util.type(g["type"])} ${g["ns"]+"::" if g["ns"] else ""}${g["name"]}</b>
% if "doc" in g:
&mdash; ${g["doc"]}
% endif
</li>
% endfor
</ul>
</section>
% endfor
+44
View File
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<title>${engine} - Star Ruler 2 API Documentation</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css">
<nav>
<section>
<h2>Engines</h2>
<ul>
<li><a href="client.index.html">client</a></li>
<li><a href="server.index.html">server</a></li>
</ul>
</section>
<section>
<h2>Links</h2>
<ul>
<li><a href="${engine}.globals.html" target="contentframe">Globals</a></li>
<li><a href="${engine}.functions.html" target="contentframe">Functions</a></li>
</ul>
</section>
<section>
<h2>Classes</h2>
<ul>
% for cls in sorted(data["classmap"], key=str.lower):
<li><a href="${engine}.class.${cls}.html" class="classdef" target="contentframe">${cls}</a></li>
% endfor
</ul>
</section>
<section>
<h2>Enums</h2>
<ul>
% for en in data["enums"]:
<li><a href="${engine}.enum.${en["name"]}.html" class="enumdef" target="contentframe">${en["name"]}</a></li>
% endfor
</ul>
</section>
</nav>
<section id="content">
<iframe name="contentframe" id="contentframe" src="server.globals.html" />
</section>
+82
View File
@@ -0,0 +1,82 @@
body, nav, section, h1, h2, h3 {
margin: 0;
padding: 0;
}
body {
font-size: 0.9em;
font-family: verdana;
}
nav {
width: 312px;
background: #eee;
margin-right: 10px;
position: fixed;
height: 100%;
overflow: auto;
}
nav > section {
padding: 4px;
}
section {
padding: 8px;
}
#content {
position: absolute;
bottom: 0px;
left: 310px;
right: 0px;
top: 0px;
padding: 0;
}
#content > iframe {
width: 100%;
height: 100%;
display: block;
border: none;
}
.method, .classdoc, .classmembers, .classmethods,
.enumdoc, .enumvalues, .globals, .functions {
margin: 10px;
}
.classdoc span {
display: block;
margin-top: 10px;
}
.classmethods, .classmembers {
background: #eee;
}
.method:nth-child(odd) {
background: #fee;
}
.method:nth-child(even) {
background: #eef;
}
a {
text-decoration: none;
color: #2222ff;
}
a:hover {
color: red;
}
a.anchor {
color: black;
}
span {
display: block;
}
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<title>Star Ruler 2 API Documentation</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<section>
<h1>Client Engine</h1>
<span>The client script engine handles the game user interface.</span>
<a href="client.index.html">View Client API</a>
</section>
<section>
<h1>Server Engine</h1>
<span>The server script engine handles the game logic backend and manages the game state.</span>
<a href="server.index.html">View Server API</a>
</section>
+36
View File
@@ -0,0 +1,36 @@
<%def name="type(name)">
<%
cname = name
if cname.startswith("const "):
cname = cname[6:]
if cname.endswith("@"):
cname = cname[:-1]
if cname.endswith("&"):
cname = cname[:-1]
cname = cname.strip()
%>
% if cname in data["classmap"]:
<a href="${engine}.class.${cname}.html">${name}</a>
% elif cname in data["enummap"]:
<a href="${engine}.enum.${cname}.html">${name}</a>
% else:
${name}
% endif
</%def>
<%def name="func(f, link=None)">
${type(f["return"]["type"])}
% if link is not None:
<a href="${link}">${f["name"]}</a>(
% else:
${f["name"]}(
% endif
% for i, arg in enumerate(f["arguments"]):
${type(arg["type"])} ${arg["name"]}<%
d = ""
if "default" in arg:
d = " = "+arg["default"]
%>${d}${"," if i != len(f["arguments"]) - 1 else ""}
% endfor
) ${"const" if f["const"] else ""}
</%def>