Skip to content

Commit

Permalink
Fix showing guide on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jan 21, 2025
1 parent 68ea0c1 commit 38bd8df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 7 additions & 6 deletions docs/docs/authoring/live-preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This mode can be enabled by passing system properties (`-D<prop>=<value>` if you
| System Property | Description |
|-----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `guideme.<guide_id_namespace>.<guide_id_path>.sources` | Path to the directory on disk containing the pages. If you are developing a mod, i.e. `file("guidebook").absolutePath` to refer to pages in a root guidebook directory. |
| `guideme.<guide_id_namespace>.<guide_id_path>.sourcesNamespace` | Specifies the resourcepack namespace for pages found in the directory specified as `.sources`. |
| `guideme.<guide_id_namespace>.<guide_id_path>.sourcesNamespace` | Specifies the resourcepack namespace for pages found in the directory specified as `.sources`. Defaults to `<guide_id_namespace>`. |

## Gradle Example

Expand All @@ -23,8 +23,8 @@ folder.
It will also automatically reload any pages that are changed in this folder, while the game is running.

To automatically show the guidebook directly after launching the game, you can also set the
`guideme.<guide_id_namespace>.<guide_id_path>.startupPage`
system property to the page that should be shown on startup.
`guideme.showOnStartup` system property to the id of the guide that should be shown on startup. You can also jump
to a specific page using `mod:guide!page.md#anchor`.

You can combine these properties for a separate `runGuide` run configuration, that will directly launch into your guide
live preview.
Expand All @@ -36,9 +36,10 @@ neoForge {
runs {
guide {
client()
property "guideme.ae2.guide.sources", file("guidebook").absolutePath
property "guideme.ae2.guide.sourcesNamespace", "ae2"
property "guideme.ae2.guide.startupPage", "ae2:index.md" // Start at index.md
property 'guideme.ae2.guide.sources', file('guidebook').absolutePath
// This is only needed if you are developing an addon and it should be your mod id
// property "guideme.ae2.guide.sourcesNamespace", "ae2addon"
systemProperty('guideme.showOnStartup', 'ae2:index.md') // Start at index.md
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/guideme/internal/GuideOnStartup.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.resource.ResourcePackLoader;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -67,16 +68,25 @@ public static void init(IEventBus modBus) {
if (guide == null) {
LOG.error("Cannot show guide '{}' since it does not exist.", showOnStartup.guideId);
} else {
e.setNewScreen(GuideScreen.openNew(guide, showOnStartup.anchor,
GlobalInMemoryHistory.INSTANCE));
try {
var anchor = showOnStartup.anchor;
if (anchor == null) {
anchor = PageAnchor.page(guide.getStartPage());
}
e.setNewScreen(GuideScreen.openNew(guide, anchor,
GlobalInMemoryHistory.INSTANCE));
} catch (Exception ex) {
LOG.error("Failed to open {}", showOnStartup, ex);
System.exit(1);
}
}
}
}
});
}
}

private record ShowOnStartup(ResourceLocation guideId, PageAnchor anchor) {
private record ShowOnStartup(ResourceLocation guideId, @Nullable PageAnchor anchor) {
}

private static ShowOnStartup getShowOnStartup() {
Expand Down

0 comments on commit 38bd8df

Please sign in to comment.