Skip to content

Commit

Permalink
refactor: rename commander app
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxuum committed Feb 10, 2024
1 parent 7356cc6 commit 9a0ccd3
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/client/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export namespace CommanderClient {
await registryInstance.sync();
started = true;

if (options.app !== undefined) {
options.app({
if (options.interface !== undefined) {
options.interface({
options: optionsObject,
execute: (path, text) => dispatcherInstance.run(path, text),
addHistoryEntry: (entry) => dispatcherInstance.addHistoryEntry(entry),
Expand Down
19 changes: 9 additions & 10 deletions src/client/interface/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ import "./config";
import { createPortal, createRoot } from "@rbxts/react-roblox";
import Roact, { StrictMode, useMemo } from "@rbxts/roact";
import { Players } from "@rbxts/services";
import { AppContext } from "../../types";
import { InterfaceContext } from "../../types";
import { Layer } from "../components/interface/Layer";
import Terminal from "../components/terminal/Terminal";
import { DEFAULT_APP_OPTIONS } from "../constants/options";
import { DEFAULT_INTERFACE_OPTIONS } from "../constants/options";
import { RootProvider } from "../providers/rootProvider";
import { AppOptions } from "../types";
import { InterfaceOptions } from "../types";

interface TerminalAppProps {
context: AppContext;
options: Partial<AppOptions>;
context: InterfaceContext;
options: Partial<InterfaceOptions>;
}

function TerminalApp({ context, options = {} }: TerminalAppProps) {
const optionsValue = useMemo(
() => ({ ...DEFAULT_APP_OPTIONS, ...options }),
() => ({ ...DEFAULT_INTERFACE_OPTIONS, ...options }),
[options],
);

print(optionsValue);
return (
<RootProvider key="root-provider" context={context} options={optionsValue}>
<Layer key="terminal" displayOrder={optionsValue.displayOrder}>
Expand All @@ -31,9 +30,9 @@ function TerminalApp({ context, options = {} }: TerminalAppProps) {
);
}

export const CommanderApp =
(options: Partial<AppOptions> = {}) =>
(context: AppContext) => {
export const CommanderInterface =
(options: Partial<InterfaceOptions> = {}) =>
(context: InterfaceContext) => {
const root = createRoot(new Instance("Folder"));
const target = Players.LocalPlayer.WaitForChild("PlayerGui");

Expand Down
2 changes: 0 additions & 2 deletions src/client/interface/components/terminal/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export default function Terminal() {
store.setVisible(!visible);
});

print(options);

return (
<Group
key="terminal"
Expand Down
4 changes: 2 additions & 2 deletions src/client/interface/constants/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppOptions } from "../types";
import { InterfaceOptions } from "../types";

export const DEFAULT_APP_OPTIONS: AppOptions = {
export const DEFAULT_INTERFACE_OPTIONS: InterfaceOptions = {
displayOrder: 1000,
};
4 changes: 2 additions & 2 deletions src/client/interface/providers/commanderProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEventListener } from "@rbxts/pretty-react-hooks";
import Roact, { createContext, useState } from "@rbxts/roact";
import { CommandOptions, CommandPath, GroupOptions } from "../../../shared";
import { DEFAULT_CLIENT_OPTIONS } from "../../options";
import { AppContext, ClientOptions, HistoryEntry } from "../../types";
import { ClientOptions, HistoryEntry, InterfaceContext } from "../../types";

export interface CommanderContextData {
options: ClientOptions;
Expand All @@ -29,7 +29,7 @@ export const DEFAULT_COMMANDER_CONTEXT: CommanderContextData = {
};

export interface CommanderProviderProps extends Roact.PropsWithChildren {
value: AppContext;
value: InterfaceContext;
}

export const CommanderContext = createContext<CommanderContextData>(
Expand Down
10 changes: 6 additions & 4 deletions src/client/interface/providers/optionsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Roact, { createContext } from "@rbxts/roact";
import { DEFAULT_APP_OPTIONS } from "../constants/options";
import { AppOptions } from "../types";
import { DEFAULT_INTERFACE_OPTIONS } from "../constants/options";
import { InterfaceOptions } from "../types";

export const OptionsContext = createContext<AppOptions>(DEFAULT_APP_OPTIONS);
export const OptionsContext = createContext<InterfaceOptions>(
DEFAULT_INTERFACE_OPTIONS,
);

export interface OptionsProviderProps extends Roact.PropsWithChildren {
value: AppOptions;
value: InterfaceOptions;
}

export function OptionsProvider({ value, children }: OptionsProviderProps) {
Expand Down
8 changes: 4 additions & 4 deletions src/client/interface/providers/rootProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ReflexProvider } from "@rbxts/react-reflex";
import Roact from "@rbxts/roact";
import { AppContext } from "../../types";
import { InterfaceContext } from "../../types";
import { store } from "../store";
import { AppOptions } from "../types";
import { InterfaceOptions } from "../types";
import { CommanderProvider } from "./commanderProvider";
import { OptionsProvider } from "./optionsProvider";
import { RemProvider, RemProviderProps } from "./remProvider";

interface RootProviderProps extends RemProviderProps {
context: AppContext;
options: AppOptions;
context: InterfaceContext;
options: InterfaceOptions;
}

export function RootProvider({
Expand Down
2 changes: 1 addition & 1 deletion src/client/interface/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HistoryEntry } from "../types";

export interface AppOptions {
export interface InterfaceOptions {
anchorPoint?: Vector2;
size?: UDim2;
position?: UDim2;
Expand Down
20 changes: 10 additions & 10 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Options } from "../shared/options";
export interface ClientOptions extends Options {
historyLength: number;
activationKeys: Enum.KeyCode[];
app?: (data: AppContext) => void;
interface?: (data: InterfaceContext) => void;
}

export interface HistoryEntry {
text: string;
success: boolean;
sentAt: number;
}

export interface CommanderEvents {
Expand All @@ -21,20 +27,14 @@ export type CommanderEventCallbacks = {
: never;
};

export type AppContext = {
export type InterfaceContext = {
options: ClientOptions;
execute: (path: CommandPath, text: string) => Promise<HistoryEntry>;
addHistoryEntry: (entry: HistoryEntry) => void;
initialData: {
commands: Map<string, CommandOptions>;
groups: Map<string, GroupOptions>;
history: HistoryEntry[];
};
events: CommanderEventCallbacks;
execute: (path: CommandPath, text: string) => Promise<HistoryEntry>;
addHistoryEntry: (entry: HistoryEntry) => void;
};

export interface HistoryEntry {
text: string;
success: boolean;
sentAt: number;
}
4 changes: 2 additions & 2 deletions test/src/client/main.client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommanderApp, CommanderClient } from "@rbxts/commander";
import { CommanderClient, CommanderInterface } from "@rbxts/commander";

CommanderClient.start(
(registry) => {
Expand All @@ -7,7 +7,7 @@ CommanderClient.start(
registry.register(commandContainer);
},
{
app: CommanderApp(),
interface: CommanderInterface(),
},
).catch((err) => {
warn(`An error occurred and Commander could not be started: ${err}`);
Expand Down

0 comments on commit 9a0ccd3

Please sign in to comment.