diff --git a/functions/Element/setElementHealth.yaml b/functions/Element/setElementHealth.yaml index 61fda85..b4da136 100644 --- a/functions/Element/setElementHealth.yaml +++ b/functions/Element/setElementHealth.yaml @@ -8,14 +8,15 @@ shared: &shared description: | This function sets the health of a [player](/player), [ped](/ped), [vehicle](/vehicle), or [object](/object) element. notes: - - | - In the case of the [vehicle](/vehicle) element, the health ranges from 0 to 1000. - - - *1000:* no damage at all - - *650:* white steam 0%, black smoke 0% - - *450:* white steam 100%, black smoke 50% - - *250:* white steam 0%, black smoke 100% - - *249:* fire with big black smoke (blowing up) + - type: 'standard' + content: | + In the case of the [vehicle](/vehicle) element, the health ranges from 0 to 1000. + + - *1000:* no damage at all + - *650:* white steam 0%, black smoke 0% + - *450:* white steam 100%, black smoke 50% + - *250:* white steam 0%, black smoke 100% + - *249:* fire with big black smoke (blowing up) parameters: - name: 'theElement' type: 'element' diff --git a/schemas/common-defs.yaml b/schemas/common-defs.yaml index 5e820e4..b2c4d1f 100644 --- a/schemas/common-defs.yaml +++ b/schemas/common-defs.yaml @@ -5,9 +5,25 @@ type: object $defs: notes: type: array - description: List of noteworthy pieces of information for the item. + description: | + List of noteworthy pieces of information for the item. + Each note can be of a specific type, e.g., 'standard' or 'important'. items: - type: string + type: object + description: An individual note item. + required: + - content + properties: + type: + type: string + description: The type of the note, influencing its presentation. + enum: + - standard + - important + default: standard + content: + type: string + description: The textual content of the note. Can use markdown and YAML multi-line strings. meta: type: array diff --git a/schemas/function.yaml b/schemas/function.yaml index e29880a..755045b 100644 --- a/schemas/function.yaml +++ b/schemas/function.yaml @@ -150,4 +150,4 @@ $defs: description: Type of the return value. name: type: string - description: Name of the return value. + description: Name of the return value. \ No newline at end of file diff --git a/web/src/components/NoteBox.astro b/web/src/components/NoteBox.astro new file mode 100644 index 0000000..0d0f210 --- /dev/null +++ b/web/src/components/NoteBox.astro @@ -0,0 +1,63 @@ +--- +import type { HTMLAttributes } from 'astro/types'; + +interface Props extends HTMLAttributes<'div'> { + type?: 'standard' | 'important'; +} + +const { type = 'standard', class: className, ...rest } = Astro.props; +--- +
+ {type === 'important' && ( + + + + )} + +
+ + \ No newline at end of file diff --git a/web/src/pages/[func].astro b/web/src/pages/[func].astro index 6f3348a..d391b31 100644 --- a/web/src/pages/[func].astro +++ b/web/src/pages/[func].astro @@ -7,6 +7,10 @@ import fs from "fs"; import path from "path"; import { Code } from '@astrojs/starlight/components'; +import NoteBox from '@src/components/NoteBox.astro'; +import '@src/styles/function-page.css'; +import type { NotesType } from '@src/utils/types'; + export async function getStaticPaths() { const functions = await getCollection('functions'); return functions.map(func => ({ @@ -19,24 +23,30 @@ const { func } = Astro.props; const funcInfo = getFunctionInfo(func.data); const funcType = funcInfo.type; -const funcTypePretty = funcInfo.typePretty; - const funcPair = funcInfo.pair; -const funcPath = path.dirname(func.filePath ?? "") -let funcExamples = funcInfo.examples +const funcPath = path.dirname(func.filePath ?? ""); -if ( funcExamples.length > 0 ){ - funcExamples = funcInfo.examples.map((example: any) => { +const { description, notes: funcNotes, examples: rawExamples } = funcInfo; + +let processedExamples: any[] = []; +if (Array.isArray(rawExamples) && rawExamples.length > 0) { + processedExamples = rawExamples.map((example: any) => { try { - const luaCode = fs.readFileSync(path.resolve(`${funcPath}`, example.path), "utf8"); + const exampleFilePath = path.resolve(funcPath, example.path); + const luaCode = fs.readFileSync(exampleFilePath, "utf8"); return { ...example, luaCode }; } catch (error) { - console.error(`Error reading ${example.path}:`, error); - return { ...example, luaCode: "Loading example error." }; + console.error(`Error reading example file ${example.path} at ${path.resolve(funcPath, example.path)}:`, error); + return { ...example, luaCode: `Error loading example: ${example.path}` }; } }); } +let notesContent: NotesType = []; +if (Array.isArray(funcNotes) && funcNotes.length > 0) { + notesContent = funcNotes; +} + ---
@@ -45,18 +55,34 @@ if ( funcExamples.length > 0 ){ title: func.id, tableOfContents: false, }}> + {funcPair && ( -

Pair: { funcPair }

+

Pair: { funcPair }

)} - + {description && } + + +
+ {notesContent.map((note) => ( + + + + ))} +
- {funcExamples.length > 0 && funcExamples.map((example: any) => ( -
-

- + + {processedExamples.length > 0 && ( +
+

Exemplos

+ {processedExamples.map((example: any) => ( +
+ + +
+ ))}
- ))} + )}
\ No newline at end of file diff --git a/web/src/styles/function-page.css b/web/src/styles/function-page.css new file mode 100644 index 0000000..1c3e79b --- /dev/null +++ b/web/src/styles/function-page.css @@ -0,0 +1,26 @@ +.function-syntax, +.function-oop, +.notes-section, +.examples-section { + margin-top: 1.5rem; + margin-bottom: 1.5rem; +} + +.function-syntax h3, +.function-oop h3, +.examples-section h3 { + margin-bottom: 0.75rem; + font-size: 1.25em; + border-bottom: 1px solid var(--sl-color-gray-5); + padding-bottom: 0.25rem; +} + +.function-example { + margin-bottom: 1.5rem; +} +.function-example > :first-child { + margin-bottom: 0.5rem; +} +.examples-section .function-example:last-child { + margin-bottom: 0; +} \ No newline at end of file diff --git a/web/src/utils/functions.ts b/web/src/utils/functions.ts index b75c715..f8d8618 100644 --- a/web/src/utils/functions.ts +++ b/web/src/utils/functions.ts @@ -1,30 +1,49 @@ import { getCollection } from 'astro:content'; import path from 'path'; -import type { FunctionType } from './types'; +import type { FunctionType, NotesType } from './types'; type FunctionItem = Awaited>[number]; +type FunctionParameter = { + name: string; + type: string; + description?: string; +}; + +type FunctionDetails = { + description?: string; + pair?: boolean; + examples?: { code: string; description?: string }[]; + notes?: NotesType; + parameters?: FunctionParameter[]; +}; + type FunctionsByCategory = { [folder: string]: FunctionItem[]; }; type FunctionsByTypeByCategory = { - shared: FunctionsByCategory; - client: FunctionsByCategory; - server: FunctionsByCategory; + [key in FunctionType]: FunctionsByCategory; }; + export type FunctionData = { shared?: any; client?: any; server?: any; }; +export type TypedFunctionData = { + shared?: FunctionDetails; + client?: FunctionDetails; + server?: FunctionDetails; +}; + export const functionTypePrettyName = { 'client': 'Client-side', 'server': 'Server-side', 'shared': 'Shared', -}; +} as const; function getFunctionType(data: FunctionData): FunctionType { if (data.shared) return 'shared'; @@ -33,16 +52,31 @@ function getFunctionType(data: FunctionData): FunctionType { } function getFunctionTypePretty(data: FunctionData): string { const funcType = getFunctionType(data); - return functionTypePrettyName[funcType] ?? 'Server-side'; + return functionTypePrettyName[funcType]; } -export function getFunctionInfo(data: FunctionData): any { +export type FunctionInfo = { + description: string; + type: FunctionType; + typePretty: string; + pair: boolean; + examples: { code: string; description?: string }[]; + notes?: NotesType; + parameters?: FunctionParameter[]; +}; + +export function getFunctionInfo(data: TypedFunctionData): FunctionInfo { + const type = getFunctionType(data); + const details = data[type] ?? {}; + return { - description: data.shared?.description || data.client?.description || data.server?.description || '', - type: getFunctionType(data), + description: details.description || '', + type: type, typePretty: getFunctionTypePretty(data), - pair: data.shared?.pair || data.client?.pair || data.server?.pair || false, - examples: data.shared?.examples || data.client?.examples || data.server?.examples || [ ], + pair: details.pair || false, + examples: details.examples || [], + notes: details.notes || [], + parameters: details.parameters || [], }; } @@ -55,7 +89,7 @@ let functionsByTypeByCategory: FunctionsByTypeByCategory = { }; for (let func of functionsCollection) { - const normalizedPath = path.normalize(func.filePath || ''); + const normalizedPath = path.normalize(func.id); const folder = path.basename(path.dirname(normalizedPath)); if (!functionsByCategory[folder]) { functionsByCategory[folder] = []; @@ -63,7 +97,7 @@ for (let func of functionsCollection) { functionsByCategory[folder].push(func); const funcType = getFunctionType(func.data); - if (!functionsByTypeByCategory[funcType][folder]) { + if (!functionsByTypeByCategory[funcType]?.[folder]) { functionsByTypeByCategory[funcType][folder] = []; } functionsByTypeByCategory[funcType][folder].push(func); diff --git a/web/src/utils/types.ts b/web/src/utils/types.ts index 0fc7920..6894708 100644 --- a/web/src/utils/types.ts +++ b/web/src/utils/types.ts @@ -1 +1,5 @@ -export type FunctionType = 'shared' | 'client' | 'server'; \ No newline at end of file +export type FunctionType = 'shared' | 'client' | 'server'; +export type NotesType = { + type: 'standard' | 'important'; + content: string; +}[]; \ No newline at end of file