Skip to content

Commit efbc864

Browse files
committed
Multiple OOP syntaxes
1 parent 99b74ca commit efbc864

File tree

2 files changed

+159
-79
lines changed

2 files changed

+159
-79
lines changed

schemas/function.yaml

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ type: object
66
properties:
77
shared:
88
description: A shared specification of a function.
9-
$ref: '#/$defs/common_properties'
9+
$ref: "#/$defs/common_properties"
1010
server:
1111
description: A server-side specification of a function.
12-
$ref: '#/$defs/common_properties'
12+
$ref: "#/$defs/common_properties"
1313
client:
1414
description: A client-side specification of a function.
15-
$ref: '#/$defs/common_properties'
15+
$ref: "#/$defs/common_properties"
1616

1717
$defs:
1818
common_properties:
@@ -22,13 +22,13 @@ $defs:
2222
description: Additional syntaxes for function.
2323
items:
2424
allOf:
25-
- $ref: '#/$defs/common_properties'
25+
- $ref: "#/$defs/common_properties"
2626
- type: object
2727
properties:
2828
displayParams:
29-
type: boolean
30-
description: Specifies whether to display the parameters and returns sections.
31-
default: true
29+
type: boolean
30+
description: Specifies whether to display the parameters and returns sections.
31+
default: true
3232
required:
3333
- name
3434
properties:
@@ -45,69 +45,95 @@ $defs:
4545
type: string
4646
description: Associates this function with another getter or setter function.
4747
oop:
48-
$ref: '#/$defs/oop'
48+
$ref: "#/$defs/oop"
4949
disabled:
50-
description: |
51-
Describe why the function was disabled, and if there is an alternative approach;
52-
or just set the property to "true".
53-
anyOf:
54-
- type: string
55-
- const: true
50+
description: |
51+
Describe why the function was disabled, and if there is an alternative approach;
52+
or just set the property to "true".
53+
anyOf:
54+
- type: string
55+
- const: true
5656
parameters:
57-
$ref: '#/$defs/parameters'
57+
$ref: "#/$defs/parameters"
5858
ignore_parameters:
59-
$ref: '#/$defs/ignore_parameters'
59+
$ref: "#/$defs/ignore_parameters"
6060
returns:
61-
$ref: '#/$defs/returns'
61+
$ref: "#/$defs/returns"
6262
meta:
63-
$ref: 'common-defs.yaml#/$defs/meta'
63+
$ref: "common-defs.yaml#/$defs/meta"
6464
notes:
65-
$ref: 'common-defs.yaml#/$defs/notes'
65+
$ref: "common-defs.yaml#/$defs/notes"
6666
preview_images:
67-
$ref: 'common-defs.yaml#/$defs/preview_images'
67+
$ref: "common-defs.yaml#/$defs/preview_images"
6868
version:
69-
$ref: 'common-defs.yaml#/$defs/version'
69+
$ref: "common-defs.yaml#/$defs/version"
7070
issues:
71-
$ref: 'common-defs.yaml#/$defs/issues'
71+
$ref: "common-defs.yaml#/$defs/issues"
7272
examples:
73-
$ref: 'common-defs.yaml#/$defs/examples'
73+
$ref: "common-defs.yaml#/$defs/examples"
7474
see_also:
75-
$ref: 'common-defs.yaml#/$defs/see_also'
75+
$ref: "common-defs.yaml#/$defs/see_also"
7676
requires_review:
77-
$ref: 'common-defs.yaml#/$defs/requires_review'
78-
77+
$ref: "common-defs.yaml#/$defs/requires_review"
78+
7979
oop:
80-
type: object
8180
description: Object-Oriented Programming (OOP) information block for the function.
82-
required:
83-
- element
84-
properties:
85-
note:
86-
type: string
87-
description: A piece of information to show alongside OOP syntax.
88-
element:
89-
type: string
90-
description: Name of the element or userdata.
9181
oneOf:
92-
- required:
93-
- method
82+
- type: object
83+
required:
84+
- element
9485
properties:
95-
method:
86+
note:
9687
type: string
97-
description: Name of the method.
98-
static:
99-
type: boolean
100-
default: false
101-
description: If set to true, this method will be marked as static.
102-
variable:
88+
element:
10389
type: string
104-
description: Name of the variable without a leading dot.
105-
- required:
106-
- constructorclass
107-
properties:
108-
constructorclass:
90+
side:
10991
type: string
110-
description: Name of the constructor class.
92+
enum: [client, server]
93+
94+
oneOf:
95+
- required: [method]
96+
properties:
97+
method:
98+
type: string
99+
static:
100+
type: boolean
101+
default: false
102+
variable:
103+
type: string
104+
- required: [constructorclass]
105+
properties:
106+
constructorclass:
107+
type: string
108+
109+
- type: array
110+
items:
111+
type: object
112+
required:
113+
- element
114+
properties:
115+
note:
116+
type: string
117+
element:
118+
type: string
119+
side:
120+
type: string
121+
enum: [client, server]
122+
123+
oneOf:
124+
- required: [method]
125+
properties:
126+
method:
127+
type: string
128+
static:
129+
type: boolean
130+
variable:
131+
type: string
132+
133+
- required: [constructorclass]
134+
properties:
135+
constructorclass:
136+
type: string
111137

112138
parameters:
113139
type: array
@@ -173,4 +199,4 @@ $defs:
173199
description: Name of the return value.
174200
templateList:
175201
type: string
176-
description: It allows to display a list of possible values (radio station IDs, bone IDs, onPlayerChat message types, etc.).
202+
description: It allows to display a list of possible values (radio station IDs, bone IDs, onPlayerChat message types, etc.).

web/src/pages/reference/[func].astro

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const changelogEntries = metaArray.find((m: MetaItem) => m.changelog)?.changelog
8383
const needsChecking = metaArray.find((m: MetaItem) => m.needs_checking)?.needs_checking;
8484
8585
let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
86+
87+
const oopList = Array.isArray(funcInfo.oop) ? funcInfo.oop : funcInfo.oop ? [funcInfo.oop]: [];
8688
---
8789

8890
<div class={`show-type-badge-${funcType}`}>
@@ -170,35 +172,87 @@ let funcSyntaxes = parseFunctionSyntaxes(func.id, func.data);
170172
)}
171173

172174
<!-- OOP Syntax -->
173-
{funcInfo.oop && (
175+
{oopList.length > 0 && (
174176
<div class="function-oop">
175-
<h4>OOP Syntax <a class="small-text" href="/reference/OOP">Help! I don't understand this!</a></h4>
176-
<ul>
177-
{funcInfo.oop.note && (
178-
<li><i><Fragment set:html={marked("<b>Note:</b> " + funcInfo.oop.note)} /></i></li>
179-
)}
180-
181-
{funcInfo.oop.constructorclass ? (
182-
<li>
183-
<strong>Constructor</strong>:
184-
<a href={`/reference/${funcInfo.oop.element}`}>{funcInfo.oop.constructorclass}</a>(...)
185-
</li>
186-
) : (
187-
<>
188-
{funcInfo.oop.method && (
189-
<li>
190-
<strong>Method</strong>:
191-
<a href={`/reference/${funcInfo.oop.element}`}>{funcInfo.oop.static ? getFixedStaticOOPClass(funcInfo.oop.element) : funcInfo.oop.element}</a>{funcInfo.oop.static ? '.' : ':'}{funcInfo.oop.method}(...)
192-
</li>
193-
)}
194-
{funcInfo.oop.variable && (
195-
<li>
196-
<strong>Variable</strong>: .{funcInfo.oop.variable}
197-
</li>
177+
<h4>
178+
OOP Syntax
179+
<a class="small-text" href="/reference/OOP">Help! I don't understand this!</a>
180+
</h4>
181+
182+
{oopList.length > 1 && (
183+
oopList.map((oopItem) => (
184+
<div class="oop-block">
185+
{oopItem.side && (
186+
<h5>{oopItem.side.charAt(0).toUpperCase() + oopItem.side.slice(1)} OOP syntax</h5>
198187
)}
199-
</>
200-
)}
201-
</ul>
188+
<ul>
189+
{oopItem.note && (
190+
<li>
191+
<i>
192+
<Fragment set:html={marked("<b>Note:</b> " + oopItem.note)} />
193+
</i>
194+
</li>
195+
)}
196+
197+
{oopItem.constructorclass ? (
198+
<li>
199+
<strong>Constructor</strong>:
200+
<a href={`/reference/${oopItem.element}`}>{oopItem.constructorclass}</a>(...)
201+
</li>
202+
) : (
203+
<>
204+
{oopItem.method && (
205+
<li>
206+
<strong>Method</strong>:<a href={`/reference/${oopItem.element}`}>{oopItem.static ? getFixedStaticOOPClass(oopItem.element) : oopItem.element}</a>{oopItem.static ? "." : ":"}{oopItem.method}(...)
207+
</li>
208+
)}
209+
{oopItem.variable && (
210+
<li>
211+
<strong>Variable</strong>: .{oopItem.variable}
212+
</li>
213+
)}
214+
</>
215+
)}
216+
</ul>
217+
</div>
218+
))
219+
)}
220+
221+
{oopList.length === 1 && (
222+
// We already have several dozen functions documented, so we need to maintain backward compatibility - that’s why it’s here
223+
<ul>
224+
{oopList[0].note && (
225+
<li>
226+
<i>
227+
<Fragment set:html={marked("<b>Note:</b> " + oopList[0].note)} />
228+
</i>
229+
</li>
230+
)}
231+
232+
{oopList[0].constructorclass ? (
233+
<li>
234+
<strong>Constructor</strong>:
235+
<a href={`/reference/${oopList[0].element}`}>
236+
{oopList[0].constructorclass}
237+
</a>(...)
238+
</li>
239+
) : (
240+
<>
241+
{oopList[0].method && (
242+
<li>
243+
<strong>Method</strong>:<a href={`/reference/${oopList[0].element}`}>{oopList[0].static ? getFixedStaticOOPClass(oopList[0].element) : oopList[0].element}</a>{oopList[0].static ? "." : ":"}{oopList[0].method}(...)
244+
</li>
245+
)}
246+
247+
{oopList[0].variable && (
248+
<li>
249+
<strong>Variable</strong>: .{oopList[0].variable}
250+
</li>
251+
)}
252+
</>
253+
)}
254+
</ul>
255+
)}
202256
</div>
203257
)}
204258

0 commit comments

Comments
 (0)