Skip to content

Commit b2363a1

Browse files
authored
🤖 Merge PR DefinitelyTyped#74033 [Gimloader] Document settings api by @TheLazySquid
1 parent 57047b7 commit b2363a1

File tree

3 files changed

+248
-2
lines changed

3 files changed

+248
-2
lines changed

types/gimloader/gimloader-tests.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,124 @@ device.state; // $ExpectType Record<string, any>
7676
worldManager.physics.bodies.staticBodies; // $ExpectType Set<string>
7777
worldManager.devices.interactives.findClosestInteractiveDevice([], 0, 0); // $ExpectType Device | undefined
7878
worldManager.inGameTerrainBuilder.clearPreviewLayer();
79+
80+
api.settings.something;
81+
api.settings.somethingElse;
82+
api.settings.something = 123;
83+
api.settings.something = "abc";
84+
api.settings.something = {};
85+
api.settings.listen("someSetting", (val: any) => {});
86+
api.settings.create([
87+
{
88+
type: "group",
89+
title: "Group",
90+
settings: [
91+
{
92+
type: "toggle",
93+
id: "toggle1",
94+
title: "A Toggle",
95+
description: "Some Toggle",
96+
},
97+
],
98+
},
99+
{
100+
type: "color",
101+
id: "color1",
102+
title: "A Color",
103+
rgba: true,
104+
default: "rgba(255, 0, 0, 1)",
105+
onChange: (val: string) => {},
106+
},
107+
{
108+
type: "dropdown",
109+
id: "dropdown1",
110+
options: [
111+
{ label: "Option 1", value: "option1" },
112+
{ label: "Option 2", value: "option2" },
113+
],
114+
title: "A Dropdown",
115+
default: "option1",
116+
onChange: (value: string) => {},
117+
},
118+
{
119+
type: "multiselect",
120+
id: "multiselect1",
121+
options: [
122+
{ label: "Option A", value: "optionA" },
123+
{ label: "Option B", value: "optionB" },
124+
{ label: "Option C", value: "optionC" },
125+
],
126+
title: "A Multiselect",
127+
default: ["optionA", "optionC"],
128+
onChange: (value: string[]) => {},
129+
},
130+
{
131+
type: "number",
132+
id: "number1",
133+
title: "A Number",
134+
min: 5,
135+
max: 10,
136+
step: 2,
137+
onChange: (value: number) => {},
138+
},
139+
{
140+
type: "radio",
141+
id: "radio1",
142+
options: [
143+
{ label: "Option A", value: "optionA" },
144+
{ label: "Option B", value: "optionB" },
145+
{ label: "Option C", value: "optionC" },
146+
],
147+
title: "A Radio",
148+
default: "optionB",
149+
description: "Pick one",
150+
onChange: (value: string) => {},
151+
},
152+
{
153+
type: "slider",
154+
id: "slider1",
155+
title: "A Slider",
156+
min: 5,
157+
max: 500,
158+
step: 2,
159+
formatter: (v: number) => v + "s",
160+
ticks: [5, 100, 300, 400, 500],
161+
onChange: (value: number) => {},
162+
},
163+
{
164+
type: "text",
165+
id: "text1",
166+
title: "A Text",
167+
placeholder: "Type",
168+
maxLength: 50,
169+
onChange: (value: string) => {},
170+
},
171+
{
172+
type: "toggle",
173+
id: "toggle2",
174+
title: "Another Toggle",
175+
default: true,
176+
onChange: (value: boolean) => {},
177+
},
178+
{
179+
type: "custom",
180+
id: "custom1",
181+
title: "Custom Setting",
182+
default: 50,
183+
render: (container: HTMLElement, value: any, update: (value: any) => void) => {
184+
container.innerText = `Value is ${value}`;
185+
container.onclick = () => update(value + 1);
186+
},
187+
onChange: (value: any) => {},
188+
},
189+
{
190+
type: "customsection",
191+
id: "customsection1",
192+
default: 50,
193+
render: (container: HTMLElement, value: any, update: (value: any) => void) => {
194+
container.innerText = `Value is ${value}`;
195+
container.onclick = () => update(value + 1);
196+
},
197+
onChange: (value: any) => {},
198+
},
199+
]);

types/gimloader/index.d.ts

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ declare global {
452452
setCanInteractThroughColliders(canInteract: boolean): void;
453453
setForceDisabled(forceDisabled: boolean): void;
454454
setInfo(info: any): void;
455+
remove(zone: CircleShort | Rect): void;
456+
onInteraction?(): void;
455457
}
456458

457459
interface DeviceInput {
@@ -515,6 +517,11 @@ declare global {
515517
update(): void;
516518
}
517519

520+
interface SkinSetupOptions extends SkinOptions {
521+
x?: number;
522+
y?: number;
523+
}
524+
518525
interface SkinOptions {
519526
id: string;
520527
editStyles?: Record<string, string>;
@@ -527,7 +534,7 @@ declare global {
527534
scene: Scene;
528535
skinId: string;
529536
applyEditStyles(options: SkinOptions): void;
530-
setupSkin(position: Vector): void;
537+
setupSkin(position: SkinSetupOptions): void;
531538
updateSkin(options: SkinOptions): void;
532539
}
533540

@@ -1077,6 +1084,8 @@ declare global {
10771084
device: Device;
10781085
scene: Scene;
10791086
angle: number;
1087+
x: number;
1088+
y: number;
10801089
} & Partial<RectShort & CircleShort & Ellipse>;
10811090

10821091
interface ColliderEntry {
@@ -2110,6 +2119,118 @@ declare global {
21102119
}
21112120
}
21122121

2122+
type SettingsChangeCallback = (value: any, remote: boolean) => void;
2123+
2124+
interface CustomSection {
2125+
type: "customsection";
2126+
id: string;
2127+
default?: any;
2128+
onChange?: (value: any, remote: boolean) => void;
2129+
render: (
2130+
container: HTMLElement,
2131+
currentValue: any,
2132+
onChange: (newValue: any) => void,
2133+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
2134+
) => (() => void) | void;
2135+
}
2136+
2137+
interface CustomSetting extends BaseSetting<any> {
2138+
type: "custom";
2139+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
2140+
render: (container: HTMLElement, currentValue: any, update: (newValue: any) => void) => (() => void) | void;
2141+
}
2142+
2143+
interface ColorSetting extends BaseSetting<string> {
2144+
type: "color";
2145+
rgba?: boolean;
2146+
}
2147+
2148+
interface RadioSetting extends BaseSetting<string> {
2149+
type: "radio";
2150+
options: {
2151+
label: string;
2152+
value: string;
2153+
}[];
2154+
}
2155+
2156+
interface SliderSetting extends BaseSetting<number> {
2157+
type: "slider";
2158+
min: number;
2159+
max: number;
2160+
step?: number;
2161+
ticks?: number[];
2162+
formatter?: (value: number) => string;
2163+
}
2164+
2165+
interface TextSetting extends BaseSetting<string> {
2166+
type: "text";
2167+
placeholder?: string;
2168+
maxLength?: number;
2169+
}
2170+
2171+
interface ToggleSetting extends BaseSetting<boolean> {
2172+
type: "toggle";
2173+
}
2174+
2175+
interface NumberSetting extends BaseSetting<number> {
2176+
type: "number";
2177+
min?: number;
2178+
max?: number;
2179+
step?: number;
2180+
}
2181+
2182+
interface MultiselectSetting extends BaseSetting<string[]> {
2183+
type: "multiselect";
2184+
options: {
2185+
label: string;
2186+
value: string;
2187+
}[];
2188+
}
2189+
2190+
interface BaseSetting<T> {
2191+
id: string;
2192+
default?: T;
2193+
title: string;
2194+
description?: string;
2195+
onChange?: (value: T, remote: boolean) => void;
2196+
}
2197+
2198+
interface DropdownSetting extends BaseSetting<string> {
2199+
type: "dropdown";
2200+
options: {
2201+
label: string;
2202+
value: string;
2203+
}[];
2204+
allowNone?: boolean;
2205+
}
2206+
2207+
type PluginSetting =
2208+
| DropdownSetting
2209+
| MultiselectSetting
2210+
| NumberSetting
2211+
| ToggleSetting
2212+
| TextSetting
2213+
| SliderSetting
2214+
| RadioSetting
2215+
| ColorSetting
2216+
| CustomSetting
2217+
| CustomSection;
2218+
2219+
interface SettingGroup {
2220+
type: "group";
2221+
title: string;
2222+
settings: PluginSetting[];
2223+
}
2224+
2225+
type PluginSettingsDescription = (PluginSetting | SettingGroup)[];
2226+
2227+
interface SettingsMethods {
2228+
create: (description: PluginSettingsDescription) => void;
2229+
listen: (key: string, callback: SettingsChangeCallback) => () => void;
2230+
}
2231+
2232+
type PluginSettings = SettingsMethods & Record<string, any>;
2233+
21132234
class PluginsApi {
21142235
/** A list of all the plugins installed */
21152236
get list(): string[];
@@ -2128,6 +2249,7 @@ declare global {
21282249
needsLib: string[];
21292250
optionalLib: string[];
21302251
syncEval: string;
2252+
deprecated: string | null;
21312253
gamemode: string[];
21322254
hasSettings: string;
21332255
};
@@ -2160,6 +2282,7 @@ declare global {
21602282
needsLib: string[];
21612283
optionalLib: string[];
21622284
syncEval: string;
2285+
deprecated: string | null;
21632286
gamemode: string[];
21642287
hasSettings: string;
21652288
};
@@ -2653,6 +2776,8 @@ declare global {
26532776
storage: Readonly<ScopedStorageApi>;
26542777
/** Functions for intercepting the arguments and return values of functions */
26552778
patcher: Readonly<ScopedPatcherApi>;
2779+
/** A utility for creating persistent settings menus, only available to plugins */
2780+
settings: PluginSettings;
26562781
/** Methods for getting info on libraries */
26572782
libs: Readonly<LibsApi>;
26582783
/** Gets the exported values of a library */

types/gimloader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/gimloader",
4-
"version": "1.8.9999",
4+
"version": "1.9.9999",
55
"nonNpm": "conflict",
66
"nonNpmDescription": "Types for the Gimloader global variables",
77
"projects": [

0 commit comments

Comments
 (0)