Skip to content

Commit

Permalink
feat(ui): allow interface visibility to be set manually
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxuum committed Jul 31, 2024
1 parent 3df8be3 commit 47fa67f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
64 changes: 34 additions & 30 deletions packages/ui/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,20 @@ import { ContentProvider, Players } from "@rbxts/services";
import { mount } from "@rbxts/vide";
import { DEFAULT_INTERFACE_OPTIONS } from "../constants/options";
import { DefaultPalette } from "../palette";
import { interfaceOptions } from "../store";
import { interfaceOptions, interfaceVisible } from "../store";
import { InterfaceOptions } from "../types";
import { CenturionApp } from "./centurion-app";

export namespace CenturionUI {
const MAX_PRELOAD_ATTEMPTS = 3;
const PRELOAD_ATTEMPT_INTERVAL = 3;

export function updateOptions(options: Partial<InterfaceOptions>) {
interfaceOptions((prev) => ({ ...prev, ...options }));
export function setVisible(visible: boolean) {
interfaceVisible(visible);
}

function registerCommands(registry: ClientRegistry) {
registry.registerCommand(
{
name: "theme",
description: "Change the terminal's theme",
arguments: [
{
name: "name",
description: "The name of the theme",
type: CenturionType.String,
suggestions: ["mocha", "macchiato", "frappe", "latte"],
},
],
},
(ctx, theme: string) => {
if (!((theme as string) in DefaultPalette)) {
ctx.error("Invalid theme");
return;
}

updateOptions({
palette: DefaultPalette[theme as never],
});
ctx.reply(`Set theme to '${theme}'`);
},
["centurion"],
);
export function updateOptions(options: Partial<InterfaceOptions>) {
interfaceOptions((prev) => ({ ...prev, ...options }));
}

export function create(
Expand Down Expand Up @@ -76,4 +51,33 @@ export namespace CenturionUI {
mount(() => CenturionApp(api), target);
};
}

function registerCommands(registry: ClientRegistry) {
registry.registerCommand(
{
name: "theme",
description: "Change the terminal's theme",
arguments: [
{
name: "name",
description: "The name of the theme",
type: CenturionType.String,
suggestions: ["mocha", "macchiato", "frappe", "latte"],
},
],
},
(ctx, theme: string) => {
if (!((theme as string) in DefaultPalette)) {
ctx.error("Invalid theme");
return;
}

updateOptions({
palette: DefaultPalette[theme as never],
});
ctx.reply(`Set theme to '${theme}'`);
},
["centurion"],
);
}
}
6 changes: 2 additions & 4 deletions packages/ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { ImmutableRegistryPath } from "@rbxts/centurion";
import { splitString } from "@rbxts/centurion/out/shared/util/string";
import { atom, computed } from "@rbxts/charm";
import { DEFAULT_INTERFACE_OPTIONS } from "./constants/options";
import { InterfaceOptions, Suggestion } from "./types";
import { Suggestion } from "./types";

export const interfaceVisible = atom(false);
export const interfaceOptions = atom<InterfaceOptions>(
DEFAULT_INTERFACE_OPTIONS,
);
export const interfaceOptions = atom(DEFAULT_INTERFACE_OPTIONS);
export const mouseOverInterface = atom(false);

export const currentCommandPath = atom<ImmutableRegistryPath | undefined>(
Expand Down

0 comments on commit 47fa67f

Please sign in to comment.