Autogenerate document files

This commit is contained in:
xtaodada
2022-05-19 11:44:36 +08:00
committed by Melledy
parent e3ed396889
commit 7fb26c3843
7 changed files with 6 additions and 11 deletions

View File

@@ -26,6 +26,7 @@ public final class Configuration extends ConfigContainer {
public static final Locale LANGUAGE = config.language.language;
public static final Locale FALLBACK_LANGUAGE = config.language.fallback;
public static final String DOCUMENT_LANGUAGE = config.language.document;
private static final String DATA_FOLDER = config.folderStructure.data;
private static final String RESOURCES_FOLDER = config.folderStructure.resources;
private static final String PLUGINS_FOLDER = config.folderStructure.plugins;

View File

@@ -5,11 +5,10 @@ import static emu.grasscutter.Configuration.RESOURCE;
import com.google.gson.reflect.TypeToken;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.Utils;
import static emu.grasscutter.Configuration.DOCUMENT_LANGUAGE;
import express.http.Request;
import express.http.Response;
import java.io.FileInputStream;
@@ -27,8 +26,7 @@ final class GachaMappingRequestHandler implements DocumentationHandler {
private Map<Long, String> map;
GachaMappingRequestHandler() {
ResourceLoader.loadResources();
final String textMapFile = "TextMap/TextMap" + Tools.getLanguageOption() + ".json";
final String textMapFile = "TextMap/TextMap" + DOCUMENT_LANGUAGE + ".json";
try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(
Utils.toFilePath(RESOURCE(textMapFile))), StandardCharsets.UTF_8)) {
map = Grasscutter.getGsonFactory().fromJson(fileReader,

View File

@@ -1,19 +1,16 @@
package emu.grasscutter.server.http.documentation;
import static emu.grasscutter.Configuration.DATA;
import static emu.grasscutter.Configuration.RESOURCE;
import static emu.grasscutter.Configuration.*;
import static emu.grasscutter.utils.Language.translate;
import com.google.gson.reflect.TypeToken;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.CommandMap;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.data.def.SceneData;
import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.Utils;
import express.http.Request;
@@ -35,7 +32,6 @@ final class HandbookRequestHandler implements DocumentationHandler {
public HandbookRequestHandler() {
ResourceLoader.loadResources();
final File templateFile = new File(Utils.toFilePath(DATA("documentation/handbook.html")));
if (templateFile.exists()) {
template = new String(FileUtils.read(templateFile), StandardCharsets.UTF_8);
@@ -44,7 +40,7 @@ final class HandbookRequestHandler implements DocumentationHandler {
template = null;
}
final String textMapFile = "TextMap/TextMap" + Tools.getLanguageOption() + ".json";
final String textMapFile = "TextMap/TextMap" + DOCUMENT_LANGUAGE + ".json";
try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(
Utils.toFilePath(RESOURCE(textMapFile))), StandardCharsets.UTF_8)) {
map = Grasscutter.getGsonFactory()

View File

@@ -17,7 +17,6 @@ final class RootRequestHandler implements DocumentationHandler {
private final String template;
public RootRequestHandler() {
ResourceLoader.loadResources();
final File templateFile = new File(Utils.toFilePath(DATA("documentation/index.html")));
if (templateFile.exists()) {
template = new String(FileUtils.read(templateFile), StandardCharsets.UTF_8);

View File

@@ -104,6 +104,7 @@ public class ConfigContainer {
public static class Language {
public Locale language = Locale.getDefault();
public Locale fallback = Locale.US;
public String document = "EN";
}
public static class Account {

View File

@@ -0,0 +1,162 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400&display=swap">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
<style>
body {
background-color: #f0f0f0;
}
p {
font-weight: 300;
}
a, a:hover {
text-decoration: none !important;
color: #626976;
}
.content {
padding: 3rem 0;
}
.container {
color: #626976;
position: relative;
}
h2 {
font-size: 20px;
}
h3 {
font-size: 16px;
}
table {
border-collapse: collapse;
width: 70%;
margin: 0 auto;
}
table thead tr {
height: 60px;
background: #626976;
}
table thead tr th {
font-size: 18px;
color: white;
}
table tbody tr {
height: 50px;
background-color: #f5f5f5;
}
tbody tr:nth-child(even) {
background-color: #fdfdfd;
}
table th, table td {
text-align: left;
padding: 0 8px;
}
</style>
<title>GM Handbook</title>
</head>
<body>
<div class="content">
<div class="container">
<h2 class="mb-5">{{TITLE}}</h2>
<h3>{{TITLE_COMMANDS}}</h3>
<hr/>
<table>
<thead>
<tr>
<th>{{HEADER_COMMAND}}</th>
<th>{{HEADER_DESCRIPTION}}</th>
</tr>
</thead>
{{COMMANDS_TABLE}}
</table>
<h3>{{TITLE_AVATARS}}</h3>
<hr/>
<table>
<thead>
<tr>
<th>{{HEADER_ID}}</th>
<th>{{HEADER_AVATAR}}</th>
</tr>
</thead>
{{AVATARS_TABLE}}
</table>
<h3>{{TITLE_ITEMS}}</h3>
<hr/>
<table>
<thead>
<tr>
<th>{{HEADER_ID}}</th>
<th>{{HEADER_ITEM}}</th>
</tr>
</thead>
{{ITEMS_TABLE}}
</table>
<h3>{{TITLE_SCENES}}</h3>
<hr/>
<table>
<thead>
<tr>
<th>{{HEADER_ID}}</th>
<th>{{HEADER_SCENE}}</th>
</tr>
</thead>
{{SCENES_TABLE}}
</table>
<h3>{{TITLE_MONSTERS}}</h3>
<hr/>
<table>
<thead>
<tr>
<th>{{HEADER_ID}}</th>
<th>{{HEADER_MONSTER}}</th>
</tr>
</thead>
{{MONSTERS_TABLE}}
</table>
</div>
</div>
<footer>
<div class="copyright">
<div class="container">
<div class="row">
<div class="col-md-6">
<span>Template by BecodReyes. All rights reserved.</span>
</div>
<div class="col-md-6">
<ul style="float:right">
<li class="list-inline-item">
<a href="https://github.com/Grasscutters/Grasscutter">Github</a>
</li>
<li class="list-inline-item">·</li>
<li class="list-inline-item">
<a href="https://github.com/Grasscutters/Grasscutter/blob/stable/LICENSE">License</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</footer>
</body>
</html>

View File

@@ -0,0 +1,106 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400&display=swap">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
<style>
body {
background-color: #f0f0f0;
}
p {
font-weight: 300;
}
a, a:hover {
text-decoration: none !important;
color: #626976;
}
.content {
padding: 3rem 0;
}
.container {
color: #626976;
position: relative;
}
h2 {
font-size: 20px;
}
h3 {
font-size: 16px;
}
table {
border-collapse: collapse;
width: 70%;
margin: 0 auto;
}
table thead tr {
height: 60px;
background: #626976;
}
table thead tr th {
font-size: 18px;
color: white;
}
table tbody tr {
height: 50px;
background-color: #f5f5f5;
}
tbody tr:nth-child(even) {
background-color: #fdfdfd;
}
table th, table td {
text-align: left;
padding: 0 8px;
}
</style>
<title>Documentation</title>
</head>
<body>
<div class="content">
<div class="container">
<h2 class="mb-5">{{TITLE}}</h2>
<ul>
<li><a href="/documentation/handbook">{{ITEM_HANDBOOK}}</a></li>
<li><a href="/documentation/gachamapping">{{ITEM_GACHA_MAPPING}}</a></li>
</ul>
</div>
</div>
<footer>
<div class="copyright">
<div class="container">
<div class="row">
<div class="col-md-6">
<span>Template by BecodReyes. All rights reserved.</span>
</div>
<div class="col-md-6">
<ul style="float:right">
<li class="list-inline-item">
<a href="https://github.com/Grasscutters/Grasscutter">Github</a>
</li>
<li class="list-inline-item">·</li>
<li class="list-inline-item">
<a href="https://github.com/Grasscutters/Grasscutter/blob/stable/LICENSE">License</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</footer>
</body>
</html>