Skip to content

Instantly share code, notes, and snippets.

@Garciat
Created December 15, 2024 17:31
Show Gist options
  • Save Garciat/5437386ed5210ea448b0af68864057fe to your computer and use it in GitHub Desktop.
Save Garciat/5437386ed5210ea448b0af68864057fe to your computer and use it in GitHub Desktop.
type KeyEnumOf<T> = {[P in keyof T]: P}
class Enum {
static make<T>(source: T): Readonly<KeyEnumOf<T>> {
let result = {} as KeyEnumOf<T>;
for (const k in source) {
result[k] = k;
}
return Object.freeze(result);
}
static allCases<T>(source: T): (keyof T)[] {
var keys = [] as (keyof T)[];
for (const k in source) {
keys.push(k);
}
return keys;
}
}
const RendererType = Enum.make({
'rasterizer': '',
'raytracer': '',
});
const RendererTypeDefault = RendererType.rasterizer;
const RendererTypeAllCases = Enum.allCases(RendererType);
class GUI {
add<T, K extends keyof T>(target: T, key: K, value: T[K] | T[K][]): void {
}
}
type Params = {
renderer: keyof typeof RendererType,
rotateCamera: boolean
}
var params: Params = {renderer: RendererTypeDefault, rotateCamera: true};
var gui: GUI = new GUI();
gui.add(params, 'renderer', RendererTypeAllCases);
gui.add(params, 'rotateCamera', true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment