Skip to content

Commit

Permalink
Add Static Properties support (#63)
Browse files Browse the repository at this point in the history
* Add Static Properties support

* Update ClassBuilder.jsx

* Update ClassBuilder.jsx

* Update math.mdx
  • Loading branch information
NegativeNameNGT committed Apr 22, 2024
1 parent 06e2a5a commit 2fb5bbc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
6 changes: 1 addition & 5 deletions docs/scripting-reference/standard-libraries/math.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ TODO Examples

## 🗼 Static Properties

| **Value** | **Name** |
| :--- | :--- |
| `3.141592653589793` | **`math.pi`** |
| `2^1024` | **`math.huge`** |

<StaticPropertiesDeclaration type="StandardLibrary" name="math" />

## 🗿 Static Functions

Expand Down
19 changes: 1 addition & 18 deletions docs/scripting-reference/structs/color.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,7 @@ This structure supports `+`, `-`, `*`, `/`, `==`, and `tostring` operations.

## 🗼 Static Properties

| **Value** | **Name** |
| :--- | :--- |
| `Color(1, 1, 1)` | **`Color.WHITE`** |
| `Color(0, 0, 0)` | **`Color.BLACK`** |
| `Color(0, 0, 0, 0)` | **`Color.TRANSPARENT`** |
| `Color(1, 0, 0)` | **`Color.RED`** |
| `Color(0, 1, 0)` | **`Color.GREEN`** |
| `Color(0, 0, 1)` | **`Color.BLUE`** |
| `Color(1, 1, 0)` | **`Color.YELLOW`** |
| `Color(0, 1, 1)` | **`Color.CYAN`** |
| `Color(1, 0, 1)` | **`Color.MAGENTA`** |
| `Color(1, 0.5, 0)` | **`Color.ORANGE`** |
| `Color(0.5, 1, 1)` | **`Color.CHARTREUSE`** |
| `Color(0, 1, 0.5)` | **`Color.AQUAMARINE`** |
| `Color(0, 0.5, 1)` | **`Color.AZURE`** |
| `Color(0.5, 0, 1)` | **`Color.VIOLET`** |
| `Color(1, 0, 0.5)` | **`Color.ROSE`** |

<StaticPropertiesDeclaration type="Struct" name="Color" />

## 🗿 Static Functions

Expand Down
35 changes: 34 additions & 1 deletion src/components/ClassBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,37 @@ export const PropertiesDeclaration = ({ type, name }) => {
</div>
}
</>);
};
};

// Block of Static Properties
export const StaticPropertiesDeclaration = ({ type, name }) => {
const class_data = GetClassData(type, name);

return (<>
{
class_data.static_properties == null || class_data.static_properties.length === 0 ? <i>This class doesn't have static properties.</i> :
<div className="table-wrapper">
<table>
<thead>
<tr>
<th>Value</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{class_data.static_properties.map((property, index) => (
<tr key={`${property.name}-${index}`}>
<td><code>{property.value}</code></td>
<td>
<b>
<code>{name + "." + property.name}</code>
</b>
</td>
</tr>
))}
</tbody>
</table>
</div>
}
</>);
};
3 changes: 2 additions & 1 deletion src/theme/MDXComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import MDXComponents from '@theme-original/MDXComponents';

// Import custom elements
import { HeaderDeclaration, ConstructorDeclaration, FunctionsDeclaration, StaticFunctionsDeclaration, ExamplesDeclaration, EventsDeclaration, PropertiesDeclaration, APISourceURL } from '@site/src/components/ClassBuilder';
import { HeaderDeclaration, ConstructorDeclaration, FunctionsDeclaration, StaticFunctionsDeclaration, ExamplesDeclaration, EventsDeclaration, PropertiesDeclaration, StaticPropertiesDeclaration, APISourceURL } from '@site/src/components/ClassBuilder';
import { Classes, Structs, BasicType, AuthorityType, UtilityClasses, ReferenceLink, Enums, CardLink, AssetPath, VideoExternal } from '@site/src/components/_nanos';

export default {
Expand All @@ -15,6 +15,7 @@ export default {
FunctionsDeclaration,
StaticFunctionsDeclaration,
PropertiesDeclaration,
StaticPropertiesDeclaration,
EventsDeclaration,
ExamplesDeclaration,
APISourceURL,
Expand Down

0 comments on commit 2fb5bbc

Please sign in to comment.