Skip to content

Commit 76b71d3

Browse files
Start drafting API docs
1 parent 77519b3 commit 76b71d3

29 files changed

Lines changed: 901 additions & 28 deletions

astro.config.mjs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import starlight from '@astrojs/starlight';
44

55
// https://astro.build/config
66
export default defineConfig({
7-
integrations: [
8-
starlight({
9-
title: 'Skript',
7+
integrations: [
8+
starlight({
9+
title: 'Skript',
1010
favicon: '/favicon.svg',
1111
/*logo: {
1212
src: './src/assets/banner.webp',
@@ -29,9 +29,55 @@ export default defineConfig({
2929
editLink: {
3030
baseUrl: 'https://github.com/SkriptLang/docs/edit/master/',
3131
},
32-
pagination: false,
33-
}),
34-
],
32+
sidebar: [
33+
{
34+
label: 'Scripting',
35+
collapsed: true,
36+
autogenerate: {
37+
directory: 'scripting',
38+
},
39+
},
40+
{
41+
label: 'API',
42+
collapsed: true,
43+
items: [
44+
'api',
45+
{
46+
label: 'Skript',
47+
collapsed: true,
48+
autogenerate: {
49+
directory: 'api/skript',
50+
},
51+
},
52+
{
53+
label: 'Localization',
54+
collapsed: true,
55+
autogenerate: {
56+
directory: 'api/localization',
57+
},
58+
},
59+
{
60+
label: 'Syntax',
61+
collapsed: true,
62+
autogenerate: {
63+
directory: 'api/syntax',
64+
},
65+
},
66+
{
67+
label: 'Registries',
68+
collapsed: true,
69+
autogenerate: {
70+
directory: 'api/registries',
71+
},
72+
},
73+
],
74+
},
75+
],
76+
expressiveCode: {
77+
tabWidth: 4,
78+
},
79+
}),
80+
],
3581
redirects: {
3682
"tutorials": "/scripting",
3783
"events": "/syntaxes",

src/content/docs/api/index.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
11
---
22
title: Getting Started
33
tableOfContents: false
4+
sidebar:
5+
order: 0
6+
prev: false
7+
next: false
48
---
59

10+
Welcome to the official documentation for Skript's API!
11+
12+
Skript comprises dozens of interworking systems, each contributing to the process that makes it tick.
13+
It is important to understand that many parts of this API have been around since the beginning (more than 14 years ago), undergoing little to no change since then.
14+
While these systems continue to work, their age shows.
15+
They are intricately interwoven, and rewriting them to modern standards is no simple task, though we are making progress.
16+
As a result, some of these systems will seem relatively modern while others are in desperate need of attention.
17+
Regardless of status, the purpose of these pages is to provide a deeper explanation of how to best use these systems.
18+
19+
## Expectations
20+
When working with Skript's API, it is strongly recommended that:
21+
- You have a strong understanding of Java
22+
- You have a strong understanding of using Skript
23+
- That is, you can comfortably write scripts
24+
- You are not scared by old, cobweb-ridden code :)
25+
26+
## Organization
27+
This documentation is organized by breaking up Skript into its major components (systems), and by breaking up each of these components into their subcomponents.
28+
For example, *syntax* is a major component of Skript, and there are many different kinds of syntax (expressions, statements, etc.).
29+
30+
The cards below cover the major components covered by this documentation.
31+
632
import { CardGrid, LinkCard } from "@astrojs/starlight/components";
733

8-
We're happy to see you're interested in learning about the Skript API.
34+
<CardGrid>
35+
<LinkCard
36+
title="Skript"
37+
description="The heart of Skript, where your journey begins."
38+
href="skript"
39+
/>
40+
<LinkCard
41+
title="Localization"
42+
description="Localization powers dynamic messages based on a user's preferences."
43+
href="localization"
44+
/>
45+
<LinkCard
46+
title="Syntax"
47+
description="Syntax is Skript's most core component, powering the scripts you write."
48+
href="syntax"
49+
/>
50+
<LinkCard
51+
title="Registries"
52+
description="Registries provide dynamic ways to interact with and expand Skript's functionality."
53+
href="registries"
54+
/>
55+
</CardGrid>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Getting Started
3+
tableOfContents: false
4+
sidebar:
5+
order: 0
6+
prev: false
7+
---
8+
9+
Skript includes localization capabilities for changing its messages or translating them into other languages.
10+
First, this guide walks through the format of language files.
11+
Then, it describes the process for loading the translations defined by language files.
12+
Finally, it highlights what methods and utilities are available for working with these translations.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Language Files
3+
sidebar:
4+
order: 10
5+
---
6+
7+
By default, Skript has two core language files, `default.lang` and `english.lang`.
8+
The former is used for language entries that are *not* intended to be edited by the user,
9+
while the latter is for entries, such as error messages, that are safe to be translated into other languages.
10+
11+
For addons, these language files are typically stored in a `lang` directory in your project's resources folder.
12+
Addons are not required to provide language files by default.
13+
Note that some features may require language entries, and if that is the case, the addon only has to provide a `default.lang` file.
14+
15+
Within a language file, it is only required that you include a version entry:
16+
```
17+
// default.lang
18+
version: 1.0.0
19+
```
20+
21+
Language entries are defined in a tree-like structure:
22+
```
23+
// default.lang
24+
error messages:
25+
unknown error: An unknown error has occurred.
26+
```
27+
This entry would then be available under the key `error messages.unknown error`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Language
3+
sidebar:
4+
order: 30
5+
---
6+
7+
:::danger[Under Construction]
8+
This page is still under construction!
9+
Check back for updates.
10+
:::
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Localizer
3+
sidebar:
4+
order: 20
5+
badge:
6+
text: Experimental
7+
variant: caution
8+
---
9+
10+
:::caution[Experimental]
11+
The API described in this page is still experimental and subject to change.
12+
However, there will be no breaking changes to methods detailed below.
13+
If necessary, they would only be deprecated for future removal.
14+
:::
15+
16+
The Localizer is an **experimental** interface defining the methods available for localization.
17+
Currently, it is only used by addons to load their language files, which is described below.
18+
19+
## Obtaining a Localizer
20+
A Localizer instance is available through your [registered addon](../../skript/addons) by calling the `localizer()` method:
21+
```java
22+
SkriptAddon addon = ...;
23+
Localizer addonLocalizer = addon.localizer();
24+
```
25+
26+
## Loading language files
27+
The localizer currently provides a single method, `setSourceDirectories(String, String)` for loading an addon's language files.
28+
It takes two parameters:
29+
- A string representing the path to the directory (on the jar) containing language files
30+
- A string representing the path to the directory (on the disk) containing language files
31+
32+
The second parameter may be null. That is, there is no requirement that you store language files outside your application's jar.
33+
However, you may wish to do so if you have language files that are intended to be customizable by the user.
34+
35+
### Example usage
36+
Let's say my addon's language files are stored in a directory `lang` on the jar (as is typical).
37+
I can simply call the `setSourceDirectories` method with this path:
38+
```java
39+
Localizer localizer = ...;
40+
localizer.setSourceDirectories("lang", null);
41+
```
42+
After calling this method, Skript will immediately load the `default.lang` and `english.lang` (if present) files from that directory in your jar.
43+
44+
## Evaluating entries
45+
The `translate(String)` method can be used for obtaining the translation of a language key (the parameter).
46+
This method will return `null` if there is no translation for the provided key.
47+
48+
Let's say my addon's default language file has the following entry:
49+
```
50+
// default.lang
51+
error messages:
52+
unknown error: An unknown error has occurred.
53+
```
54+
I can obtain its value by simply calling:
55+
```java
56+
Localizer localizer = ...;
57+
String message = localizer.translate("error messages.unknown error");
58+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Arithmetic
3+
---
4+
5+
:::danger[Under Construction]
6+
This page is still under construction!
7+
Check back for updates.
8+
:::
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Comparators
3+
---
4+
5+
:::danger[Under Construction]
6+
This page is still under construction!
7+
Check back for updates.
8+
:::
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Converters
3+
---
4+
5+
:::danger[Under Construction]
6+
This page is still under construction!
7+
Check back for updates.
8+
:::
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Experiments
3+
---
4+
5+
:::danger[Under Construction]
6+
This page is still under construction!
7+
Check back for updates.
8+
:::

0 commit comments

Comments
 (0)