Skip to content

Commit 954eef8

Browse files
Add see_also for related functions
1 parent b696fd0 commit 954eef8

12 files changed

+92
-6
lines changed

functions/Cursor/getCursorAlpha.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ client:
1717
description: |
1818
This example prints the cursor alpha to chatbox using */cursoralpha* command:
1919
see_also:
20-
- 'category:Client element functions'
20+
- 'functions:any:Cursor'

functions/Cursor/getCursorPosition.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ client:
3333
- path: 'examples/getCursorPosition-2.lua'
3434
description: |
3535
This (untested) example uses [processLineOfSight](/processLineOfSight) to calculate the exact world location: Warning, this script causes high CPU usage!
36+
see_also:
37+
- 'functions:any:Cursor'

functions/Cursor/isCursorShowing.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ shared: &shared
1313
values:
1414
- type: 'bool'
1515
name: 'result'
16+
see_also:
17+
- 'functions:any:Cursor'
1618

1719
server:
1820
<<: *shared

functions/Cursor/setCursorAlpha.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ client:
2121
description: |
2222
This example sets the cursor alpha to 100 using */cursoralpha* command:
2323
see_also:
24-
- 'category:Client GUI functions'
24+
- 'functions:any:Cursor'

functions/Cursor/setCursorPosition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ client:
1919
description: |
2020
This example sets your cursor position to the center of your screen after using the */cursorpos* command.
2121
see_also:
22-
- 'category:Client input functions'
22+
- 'functions:any:Cursor'

functions/Element/getElementHealth.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ shared: &shared
2424
description: 'setElementHealth in onClientPlayerDamage bug'
2525
- id: 1423
2626
description: 'When you setElementHealth under onClientPlayerDamage, the local (hit) player rotates automatically'
27+
see_also:
28+
- 'functions:any:Element'
2729

2830
server:
2931
<<: *shared

functions/Element/getElementPosition.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ shared: &shared
3333
issues:
3434
- id: 928
3535
description: 'Position desync with dead players'
36+
see_also:
37+
- 'functions:any:Element'
3638

3739
server:
3840
<<: *shared

functions/Element/setElementHealth.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ shared: &shared
4141
description: 'When you setElementHealth under onClientPlayerDamage, the local (hit) player rotates automatically'
4242
- id: 448
4343
description: 'Crash when plane explode'
44+
see_also:
45+
- 'functions:any:Element'
4446

4547
server:
4648
<<: *shared

functions/Element/setElementPosition.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ shared: &shared
4040
description: 'Changing player position when they have a jetpack will remove the jetpack and bug when skin is changed'
4141
- id: 529
4242
description: 'Player falls from bike when the bike is teleported using setElementPosition'
43+
see_also:
44+
- 'functions:any:Element'
4345

4446
server:
4547
<<: *shared

schemas/common-defs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ $defs:
111111
introduce this property, then you have to be explicit about it.
112112
items:
113113
type: string
114-
pattern: "^(category):"
114+
pattern: "^functions:(client|server|any):[A-Za-z0-9_]+$"
115115
uniqueItems: true

web/src/pages/[func].astro

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
33
import { getCollection } from 'astro:content';
4-
import { getFunctionInfo, parseFunctionSyntaxes } from '@src/utils/functions';
4+
import { getFunctionInfo, parseFunctionSyntaxes, getFunctionSeeAlsoLinks } from '@src/utils/functions';
55
import { renderInlineMarkdown } from '@src/utils/general';
66
import { marked } from 'marked';
77
import fs from "fs";
@@ -54,6 +54,8 @@ if (Array.isArray(funcInfo.notes) && funcInfo.notes.length > 0) {
5454
}
5555
5656
let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
57+
58+
const seeAlsoLinks = getFunctionSeeAlsoLinks(func);
5759
---
5860

5961
<div class={"show-type-badge-" + funcType}>
@@ -185,5 +187,25 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
185187
))}
186188
</div>
187189
)}
190+
191+
<!-- See Also links list -->
192+
{seeAlsoLinks.length > 0 && (
193+
<div class="see-also-section">
194+
<h4>See Also</h4>
195+
<ul>
196+
{seeAlsoLinks.map((link: any) => (
197+
(link.name === func.id) && (
198+
<li>
199+
<strong>{link.name}</strong>
200+
</li>
201+
) || (
202+
<li>
203+
<a href={link.link}>{link.name}</a>
204+
</li>
205+
)
206+
))}
207+
</ul>
208+
</div>
209+
)}
188210
</StarlightPage>
189211
</div>

web/src/utils/functions.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,56 @@ export function getFunctionsByCategory(): FunctionsByCategory {
236236

237237
export function getFunctionsByTypeByCategory(): FunctionsByTypeByCategory {
238238
return functionsByTypeByCategory;
239-
}
239+
}
240+
241+
// Gets related functions and other items (links) according to the see_also field
242+
export function getFunctionSeeAlsoLinks(
243+
func: FunctionItem
244+
): { name: string; link: string }[] {
245+
const seeAlso: string[] | undefined =
246+
func.data.shared?.see_also ??
247+
func.data.client?.see_also ??
248+
func.data.server?.see_also;
249+
250+
if (!seeAlso || seeAlso.length === 0) {
251+
return [];
252+
}
253+
254+
const links = seeAlso.map((item: string) => {
255+
const parts = item.split(':');
256+
if (parts.length !== 3) return null;
257+
258+
const [itemType, functionType, functionCategory] = parts;
259+
260+
if (itemType !== 'functions') return null;
261+
262+
let functionsInCategory: FunctionItem[] = [];
263+
264+
switch (functionType) {
265+
case 'client':
266+
functionsInCategory = functionsByTypeByCategory.client[functionCategory] || [];
267+
break;
268+
case 'server':
269+
functionsInCategory = functionsByTypeByCategory.server[functionCategory] || [];
270+
break;
271+
case 'any':
272+
functionsInCategory = [
273+
...(functionsByTypeByCategory.shared[functionCategory] || []),
274+
...(functionsByTypeByCategory.client[functionCategory] || []),
275+
...(functionsByTypeByCategory.server[functionCategory] || []),
276+
];
277+
break;
278+
default:
279+
return null;
280+
}
281+
282+
return functionsInCategory.map(f => ({
283+
name: f.id,
284+
link: `/${f.id}`,
285+
}));
286+
})
287+
.filter(linkGroup => linkGroup !== null)
288+
.flat();
289+
290+
return links.sort((a, b) => a.name.localeCompare(b.name));
291+
}

0 commit comments

Comments
 (0)