-
Notifications
You must be signed in to change notification settings - Fork 101
Custom Documentation Ingame #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maxryan008
wants to merge
10
commits into
main
Choose a base branch
from
feature/ingame-documentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0b8ab29
Custom Documentation Ingame
maxryan008 e18eb9e
Ran spotless apply
maxryan008 8484b66
Added editor. hold inspect for 3 seconds while in a menu to start edi…
maxryan008 df75d1f
Small editor fixes
maxryan008 2e51cc9
Page renderer changes and editor changes:
maxryan008 79d9048
Improved home page text
maxryan008 fdad725
Another JSON file change
maxryan008 7a3ba86
Added subpages of home
maxryan008 01142b5
Resolved some issues and added all machine documentation pages. (mach…
maxryan008 e35b189
ran spotless
maxryan008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,46 @@ | ||
| { | ||
| "elements": [ | ||
| { | ||
| "type": "text", | ||
| "align": "left", | ||
| "nmaxX": 0.62, | ||
| "nmaxY": 0.42, | ||
| "nminX": 0.04, | ||
| "nminY": 0.18, | ||
| "order": 0, | ||
| "textKey": "doc.gc.home.intro" | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "align": "left", | ||
| "nmaxX": 0.76, | ||
| "nmaxY": 0.52, | ||
| "nminX": 0.04, | ||
| "nminY": 0.46, | ||
| "order": 1, | ||
| "textKey": "doc.gc.home.category_label" | ||
| }, | ||
| { | ||
| "type": "button", | ||
| "nh": 0.12, | ||
| "nw": 0.18, | ||
| "nx": 0.04, | ||
| "ny": 0.6, | ||
| "order": 2, | ||
| "target": "galacticraft:air_lock_controller", | ||
| "textKey": "doc.gc.home.btn.airlock" | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "align": "left", | ||
| "nmaxX": 0.38, | ||
| "nmaxY": 0.5, | ||
| "nminX": 0.06, | ||
| "nminY": 0.24, | ||
| "order": 3, | ||
| "textKey": "doc.gc.home.intro" | ||
| } | ||
| ], | ||
| "schema": 2, | ||
| "titleKey": "doc.gc.home.title" | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/generated/assets/galacticraft/docs/pages/air_lock_controller.json
This file contains hidden or 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,37 @@ | ||
| { | ||
| "bind": [ | ||
| "galacticraft:air_lock_controller" | ||
| ], | ||
| "elements": [ | ||
| { | ||
| "type": "text", | ||
| "align": "left", | ||
| "nmaxX": 0.54, | ||
| "nmaxY": 0.61, | ||
| "nminX": 0.04, | ||
| "nminY": 0.28, | ||
| "order": 0, | ||
| "textKey": "doc.gc.airlock.overview" | ||
| }, | ||
| { | ||
| "type": "button", | ||
| "nh": 0.1, | ||
| "nw": 0.24, | ||
| "nx": 0.04, | ||
| "ny": 0.7, | ||
| "order": 1, | ||
| "target": "galacticraft:home", | ||
| "textKey": "gc.docs.back" | ||
| } | ||
| ], | ||
| "id": "galacticraft:air_lock_controller", | ||
| "schema": 2, | ||
| "sections": [ | ||
| { | ||
| "type": "overview", | ||
| "bodyKey": "doc.gc.airlock.overview", | ||
| "headingKey": "doc.common.overview" | ||
| } | ||
| ], | ||
| "titleKey": "doc.gc.airlock.title" | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
src/main/java/dev/galacticraft/mod/api/documentation/DocsApi.java
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * Copyright (c) 2019-2025 Team Galacticraft | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package dev.galacticraft.mod.api.documentation; | ||
|
|
||
| import net.minecraft.resources.ResourceLocation; | ||
| import net.minecraft.world.item.Item; | ||
|
|
||
| public final class DocsApi { | ||
| private DocsApi() {} | ||
| public static ResourceLocation homeId() { return DocsManager.HOME_ID; } | ||
| public static void openHome() { DocsManager.openHome(); } | ||
| public static void open(ResourceLocation pageId) { DocsManager.open(pageId); } | ||
| public static ResourceLocation pageForItem(Item item) { return DocsManager.pageFor(item); } | ||
| } |
171 changes: 171 additions & 0 deletions
171
src/main/java/dev/galacticraft/mod/api/documentation/DocsManager.java
This file contains hidden or 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,171 @@ | ||
| /* | ||
| * Copyright (c) 2019-2025 Team Galacticraft | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package dev.galacticraft.mod.api.documentation; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonParseException; | ||
| import dev.galacticraft.mod.Constant; | ||
| import dev.galacticraft.mod.api.documentation.client.pages.BlankPageScreen; | ||
| import dev.galacticraft.mod.api.documentation.model.HomeDoc; | ||
| import dev.galacticraft.mod.api.documentation.model.SectionOverview; | ||
| import dev.galacticraft.mod.api.documentation.model.SubDoc; | ||
| import dev.galacticraft.mod.api.documentation.model.elements.ButtonElement; | ||
| import dev.galacticraft.mod.api.documentation.model.elements.Element; | ||
| import dev.galacticraft.mod.api.documentation.model.elements.ImageElement; | ||
| import dev.galacticraft.mod.api.documentation.model.elements.TextElement; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.resources.ResourceLocation; | ||
| import net.minecraft.world.item.Item; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| public final class DocsManager { | ||
| public static final ResourceLocation HOME_ID = Constant.id("home"); | ||
|
|
||
| public static final Gson GSON = new GsonBuilder() | ||
| .registerTypeAdapter(ResourceLocation.class, | ||
| (com.google.gson.JsonDeserializer<ResourceLocation>) (json, t, ctx) -> | ||
| ResourceLocation.parse(json.getAsString())) | ||
| .registerTypeAdapter(ResourceLocation.class, | ||
| (com.google.gson.JsonSerializer<ResourceLocation>) (src, t, ctx) -> | ||
| new com.google.gson.JsonPrimitive(src.toString())) | ||
| .registerTypeAdapter(dev.galacticraft.mod.api.documentation.model.Section.class, | ||
maxryan008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (com.google.gson.JsonDeserializer<dev.galacticraft.mod.api.documentation.model.Section>) (json, t, ctx) -> { | ||
| JsonObject obj = json.getAsJsonObject(); | ||
| String type = obj.get("type").getAsString(); | ||
| if ("overview".equals(type)) { | ||
| String headingKey = obj.has("headingKey") ? obj.get("headingKey").getAsString() : null; | ||
| String bodyKey = obj.has("bodyKey") ? obj.get("bodyKey").getAsString() : null; | ||
| return new SectionOverview(type, headingKey, bodyKey); | ||
| } | ||
| throw new JsonParseException("Unknown docs section type: " + type); | ||
| }) | ||
| .registerTypeAdapter(Element.class, | ||
| (com.google.gson.JsonDeserializer<Element>) (json, t, ctx) -> { | ||
| com.google.gson.JsonObject obj = json.getAsJsonObject(); | ||
maxryan008 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| String type = obj.get("type").getAsString(); | ||
|
|
||
| switch (type) { | ||
| case "button" -> { | ||
| float nx = obj.get("nx").getAsFloat(); | ||
| float ny = obj.get("ny").getAsFloat(); | ||
| float nw = obj.get("nw").getAsFloat(); | ||
| float nh = obj.get("nh").getAsFloat(); | ||
| String textKey = obj.get("textKey").getAsString(); | ||
| String target = obj.get("target").getAsString(); | ||
| int order = obj.get("order").getAsInt(); | ||
| return new ButtonElement(type, nx, ny, nw, nh, textKey, target, order); | ||
| } | ||
| case "text" -> { | ||
| float nminX = obj.get("nminX").getAsFloat(); | ||
| float nminY = obj.get("nminY").getAsFloat(); | ||
| float nmaxX = obj.get("nmaxX").getAsFloat(); | ||
| float nmaxY = obj.get("nmaxY").getAsFloat(); | ||
| String textKey = obj.get("textKey").getAsString(); | ||
| String align = obj.has("align") ? obj.get("align").getAsString() : null; | ||
| int order = obj.get("order").getAsInt(); | ||
| return new TextElement(type, nminX, nminY, nmaxX, nmaxY, textKey, align, order); | ||
| } | ||
| case "image" -> { | ||
| float nx = obj.get("nx").getAsFloat(); | ||
| float ny = obj.get("ny").getAsFloat(); | ||
| float nw = obj.get("nw").getAsFloat(); | ||
| float nh = obj.get("nh").getAsFloat(); | ||
| String texture = obj.get("texture").getAsString(); | ||
| int u = obj.get("u").getAsInt(); | ||
| int v = obj.get("v").getAsInt(); | ||
| int texW = obj.get("texW").getAsInt(); | ||
| int texH = obj.get("texH").getAsInt(); | ||
| int order = obj.get("order").getAsInt(); | ||
| return new ImageElement(type, nx, ny, nw, nh, texture, u, v, texW, texH, order); | ||
| } | ||
| default -> throw new com.google.gson.JsonParseException("Unknown docs element type: " + type); | ||
| } | ||
| }) | ||
| .setPrettyPrinting() | ||
| .create(); | ||
| private static final Map<ResourceLocation, SubDoc> DOCS = new LinkedHashMap<>(); | ||
| private static final Map<Item, ResourceLocation> ITEM_TO_PAGE = new HashMap<>(); | ||
| private static final Map<ResourceLocation, ResourceLocation> PARENTS = new HashMap<>(); | ||
| private static HomeDoc HOME; | ||
|
|
||
| private DocsManager() { | ||
| } | ||
|
|
||
| public static void clear() { | ||
| HOME = null; | ||
| DOCS.clear(); | ||
| ITEM_TO_PAGE.clear(); | ||
| PARENTS.clear(); | ||
| } | ||
|
|
||
| public static void setHome(HomeDoc home) { | ||
| HOME = home; | ||
| } | ||
|
|
||
| public static void addDoc(SubDoc doc, Collection<Item> boundItems) { | ||
| DOCS.put(doc.id(), doc); | ||
|
|
||
| ResourceLocation parent = doc.parent() != null ? doc.parent() : HOME_ID; | ||
| PARENTS.put(doc.id(), parent); | ||
|
|
||
| for (Item it : boundItems) { | ||
| ITEM_TO_PAGE.put(it, doc.id()); | ||
| } | ||
| } | ||
|
|
||
| public static ResourceLocation pageFor(Item item) { | ||
| return ITEM_TO_PAGE.get(item); | ||
| } | ||
|
|
||
| public static ResourceLocation parentOf(ResourceLocation id) { | ||
| return PARENTS.get(id); | ||
| } | ||
|
|
||
| public static HomeDoc getHomeDoc() { | ||
| return HOME; | ||
| } | ||
|
|
||
| public static SubDoc getDoc(ResourceLocation id) { | ||
| return DOCS.get(id); | ||
| } | ||
|
|
||
| public static void openHome() { | ||
| final String titleKey = (HOME != null) ? HOME.titleKey() : "doc.gc.home.title"; | ||
| Minecraft.getInstance().setScreen(new BlankPageScreen(HOME_ID, titleKey)); | ||
| } | ||
|
|
||
| public static void open(ResourceLocation id) { | ||
| SubDoc doc = DOCS.get(id); | ||
| if (doc != null) { | ||
| Minecraft.getInstance().setScreen(new BlankPageScreen(id, doc.titleKey())); | ||
| } else { | ||
| openHome(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.