2022-03-04 03:39:48 +00:00
|
|
|
import Modal from "components/Modal.vue";
|
2022-06-27 00:17:22 +00:00
|
|
|
import type {
|
2022-02-27 23:06:38 +00:00
|
|
|
CoercableComponent,
|
|
|
|
JSXFunction,
|
2022-06-26 03:34:18 +00:00
|
|
|
OptionsFunc,
|
2022-02-27 23:06:38 +00:00
|
|
|
Replace,
|
|
|
|
StyleValue
|
2022-03-04 03:39:48 +00:00
|
|
|
} from "features/feature";
|
2022-06-27 00:17:22 +00:00
|
|
|
import { jsx, setDefault } from "features/feature";
|
|
|
|
import { globalBus } from "game/events";
|
|
|
|
import type { Persistent } from "game/persistence";
|
|
|
|
import { persistent } from "game/persistence";
|
|
|
|
import player from "game/player";
|
|
|
|
import type { Emitter } from "nanoevents";
|
|
|
|
import { createNanoEvents } from "nanoevents";
|
|
|
|
import type {
|
2022-01-14 04:25:47 +00:00
|
|
|
Computable,
|
|
|
|
GetComputableType,
|
|
|
|
GetComputableTypeWithDefault,
|
|
|
|
ProcessedComputable
|
2022-03-04 03:39:48 +00:00
|
|
|
} from "util/computed";
|
2022-06-27 00:17:22 +00:00
|
|
|
import { processComputable } from "util/computed";
|
2022-03-04 03:39:48 +00:00
|
|
|
import { createLazyProxy } from "util/proxies";
|
2022-06-27 00:17:22 +00:00
|
|
|
import type { InjectionKey, Ref } from "vue";
|
|
|
|
import { ref, shallowReactive, unref } from "vue";
|
2022-01-14 04:25:47 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/** A feature's node in the DOM that has its size tracked. */
|
2022-03-20 18:57:45 +00:00
|
|
|
export interface FeatureNode {
|
2022-03-28 00:06:58 +00:00
|
|
|
rect: DOMRect;
|
|
|
|
observer: MutationObserver;
|
2022-03-20 18:57:45 +00:00
|
|
|
element: HTMLElement;
|
|
|
|
}
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
2022-07-10 08:00:08 +00:00
|
|
|
* An injection key that a {@link ContextComponent} will use to provide a function that registers a {@link FeatureNode} with the given id and HTML element.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-03-20 18:57:45 +00:00
|
|
|
export const RegisterNodeInjectionKey: InjectionKey<(id: string, element: HTMLElement) => void> =
|
2022-07-10 07:20:51 +00:00
|
|
|
Symbol("RegisterNode");
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
2022-07-10 08:00:08 +00:00
|
|
|
* An injection key that a {@link ContextComponent} will use to provide a function that unregisters a {@link FeatureNode} with the given id.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-03-20 18:57:45 +00:00
|
|
|
export const UnregisterNodeInjectionKey: InjectionKey<(id: string) => void> =
|
|
|
|
Symbol("UnregisterNode");
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
2022-07-10 08:00:08 +00:00
|
|
|
* An injection key that a {@link ContextComponent} will use to provide a ref to a map of all currently registered {@link FeatureNode}s.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-03-20 18:57:45 +00:00
|
|
|
export const NodesInjectionKey: InjectionKey<Ref<Record<string, FeatureNode | undefined>>> =
|
|
|
|
Symbol("Nodes");
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
2022-07-10 08:00:08 +00:00
|
|
|
* An injection key that a {@link ContextComponent} will use to provide a ref to a bounding rect of the Context.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-05-22 23:09:34 +00:00
|
|
|
export const BoundsInjectionKey: InjectionKey<Ref<DOMRect | undefined>> = Symbol("Bounds");
|
2022-03-20 18:57:45 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/** All types of events able to be sent or emitted from a layer's emitter. */
|
2022-01-25 04:23:30 +00:00
|
|
|
export interface LayerEvents {
|
2022-07-15 05:55:36 +00:00
|
|
|
/**
|
|
|
|
* Sent every game tick, before the update event. Intended for "generation" type actions.
|
|
|
|
* @param diff The delta time since last tick, in ms.
|
|
|
|
*/
|
2022-03-11 20:02:41 +00:00
|
|
|
preUpdate: (diff: number) => void;
|
2022-07-15 05:55:36 +00:00
|
|
|
/**
|
|
|
|
* Sent every game tick. Intended for "automation" type actions.
|
|
|
|
* @param diff The delta time since last tick, in ms.
|
|
|
|
*/
|
2022-03-11 20:02:41 +00:00
|
|
|
update: (diff: number) => void;
|
2022-07-15 05:55:36 +00:00
|
|
|
/**
|
|
|
|
* Sent every game tick, after the update event. Intended for checking state.
|
|
|
|
* @param diff The delta time since last tick, in ms.
|
|
|
|
*/
|
2022-03-11 20:02:41 +00:00
|
|
|
postUpdate: (diff: number) => void;
|
2022-01-25 04:23:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* A reference to all the current layers.
|
|
|
|
* It is shallow reactive so it will update when layers are added or removed, but not interfere with the existing refs within each layer.
|
|
|
|
*/
|
2022-05-01 20:00:00 +00:00
|
|
|
export const layers: Record<string, Readonly<GenericLayer> | undefined> = shallowReactive({});
|
2022-07-10 03:09:25 +00:00
|
|
|
|
|
|
|
declare global {
|
2022-07-10 05:43:34 +00:00
|
|
|
/** Augment the window object so the layers can be accessed from the console. */
|
2022-07-10 03:09:25 +00:00
|
|
|
interface Window {
|
|
|
|
layers: Record<string, Readonly<GenericLayer> | undefined>;
|
|
|
|
}
|
|
|
|
}
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
window.layers = layers;
|
|
|
|
|
2022-02-27 19:49:34 +00:00
|
|
|
declare module "@vue/runtime-dom" {
|
2022-07-10 05:43:34 +00:00
|
|
|
/** Augment CSS Properties to allow for setting the layer color CSS variable. */
|
2022-02-27 19:49:34 +00:00
|
|
|
interface CSSProperties {
|
|
|
|
"--layer-color"?: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/** An object representing the position of some entity. */
|
2022-01-14 04:25:47 +00:00
|
|
|
export interface Position {
|
2022-07-10 05:43:34 +00:00
|
|
|
/** The X component of the entity's position. */
|
2022-01-14 04:25:47 +00:00
|
|
|
x: number;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** The Y component of the entity's position. */
|
2022-01-14 04:25:47 +00:00
|
|
|
y: number;
|
|
|
|
}
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* An object that configures a {@link Layer}.
|
|
|
|
* Even moreso than features, the developer is expected to include extra properties in this object.
|
2022-07-10 08:00:08 +00:00
|
|
|
* All {@link game/persistence.Persistent} refs must be included somewhere within the layer object.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
export interface LayerOptions {
|
2022-07-10 05:43:34 +00:00
|
|
|
/** The color of the layer, used to theme the entire layer's display. */
|
2022-01-14 04:25:47 +00:00
|
|
|
color?: Computable<string>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* The layout of this layer's features.
|
2022-07-10 08:00:08 +00:00
|
|
|
* When the layer is open in {@link game/player.PlayerData.tabs}, this is the content that is display.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
display: Computable<CoercableComponent>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** An object of classes that should be applied to the display. */
|
2022-01-14 04:25:47 +00:00
|
|
|
classes?: Computable<Record<string, boolean>>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** Styles that should be applied to the display. */
|
2022-01-14 04:25:47 +00:00
|
|
|
style?: Computable<StyleValue>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* The name of the layer, used on minimized tabs.
|
2022-07-10 08:00:08 +00:00
|
|
|
* Defaults to {@link BaseLayer.id}.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
name?: Computable<string>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the layer can be minimized.
|
|
|
|
* Defaults to true.
|
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
minimizable?: Computable<boolean>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Whether or not to force the go back button to be hidden.
|
2022-07-10 08:00:08 +00:00
|
|
|
* If true, go back will be hidden regardless of {@link data/projInfo.allowGoBack}.
|
2022-07-10 05:43:34 +00:00
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
forceHideGoBack?: Computable<boolean>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* A CSS min-width value that is applied to the layer.
|
|
|
|
* Can be a number, in which case the unit is assumed to be px.
|
|
|
|
* Defaults to 600px.
|
|
|
|
*/
|
2022-04-17 19:01:03 +00:00
|
|
|
minWidth?: Computable<number | string>;
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/** The properties that are added onto a processed {@link LayerOptions} to create a {@link Layer} */
|
2022-01-14 04:25:47 +00:00
|
|
|
export interface BaseLayer {
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* The ID of the layer.
|
|
|
|
* Populated from the {@link createLayer} parameters.
|
|
|
|
* Used for saving and tracking open tabs.
|
|
|
|
*/
|
2022-04-06 03:16:40 +00:00
|
|
|
id: string;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** A persistent ref tracking if the tab is minimized or not. */
|
2022-04-06 03:16:40 +00:00
|
|
|
minimized: Persistent<boolean>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** An emitter for sending {@link LayerEvents} events for this layer. */
|
2022-01-14 04:25:47 +00:00
|
|
|
emitter: Emitter<LayerEvents>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** A function to register an event listener on {@link emitter}. */
|
2022-01-14 04:25:47 +00:00
|
|
|
on: OmitThisParameter<Emitter<LayerEvents>["on"]>;
|
2022-07-10 05:43:34 +00:00
|
|
|
/** A function to emit a {@link LayerEvents} event to this layer. */
|
|
|
|
emit: <K extends keyof LayerEvents>(...args: [K, ...Parameters<LayerEvents[K]>]) => void;
|
2022-07-10 08:00:08 +00:00
|
|
|
/** A map of {@link FeatureNode}s present in this layer's {@link ContextComponent} component. */
|
2022-03-20 18:57:45 +00:00
|
|
|
nodes: Ref<Record<string, FeatureNode | undefined>>;
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/** An unit of game content. Displayed to the user as a tab or modal. */
|
2022-01-14 04:25:47 +00:00
|
|
|
export type Layer<T extends LayerOptions> = Replace<
|
|
|
|
T & BaseLayer,
|
|
|
|
{
|
|
|
|
color: GetComputableType<T["color"]>;
|
|
|
|
display: GetComputableType<T["display"]>;
|
|
|
|
classes: GetComputableType<T["classes"]>;
|
|
|
|
style: GetComputableType<T["style"]>;
|
2022-04-06 03:16:40 +00:00
|
|
|
name: GetComputableTypeWithDefault<T["name"], string>;
|
2022-01-14 04:25:47 +00:00
|
|
|
minWidth: GetComputableTypeWithDefault<T["minWidth"], 600>;
|
|
|
|
minimizable: GetComputableTypeWithDefault<T["minimizable"], true>;
|
|
|
|
forceHideGoBack: GetComputableType<T["forceHideGoBack"]>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/** A type that matches any valid {@link Layer} object. */
|
2022-01-14 04:25:47 +00:00
|
|
|
export type GenericLayer = Replace<
|
|
|
|
Layer<LayerOptions>,
|
|
|
|
{
|
|
|
|
name: ProcessedComputable<string>;
|
|
|
|
minWidth: ProcessedComputable<number>;
|
|
|
|
minimizable: ProcessedComputable<boolean>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* When creating layers, this object a map of layer ID to a set of any created persistent refs in order to check they're all included in the final layer object.
|
|
|
|
*/
|
2022-04-06 03:16:40 +00:00
|
|
|
export const persistentRefs: Record<string, Set<Persistent>> = {};
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* When creating layers, this array stores the layers currently being created, as a stack.
|
|
|
|
*/
|
2022-04-06 03:16:40 +00:00
|
|
|
export const addingLayers: string[] = [];
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Lazily creates a layer with the given options.
|
|
|
|
* @param id The ID this layer will have. See {@link BaseLayer.id}.
|
|
|
|
* @param optionsFunc Layer options.
|
|
|
|
*/
|
2022-03-13 23:55:47 +00:00
|
|
|
export function createLayer<T extends LayerOptions>(
|
2022-04-06 03:16:40 +00:00
|
|
|
id: string,
|
2022-06-26 03:34:18 +00:00
|
|
|
optionsFunc: OptionsFunc<T, BaseLayer>
|
2022-03-13 23:55:47 +00:00
|
|
|
): Layer<T> {
|
2022-02-27 19:49:34 +00:00
|
|
|
return createLazyProxy(() => {
|
2022-03-13 23:55:47 +00:00
|
|
|
const layer = {} as T & Partial<BaseLayer>;
|
2022-02-27 19:49:34 +00:00
|
|
|
const emitter = (layer.emitter = createNanoEvents<LayerEvents>());
|
|
|
|
layer.on = emitter.on.bind(emitter);
|
2022-07-10 07:20:51 +00:00
|
|
|
layer.emit = emitter.emit.bind(emitter) as <K extends keyof LayerEvents>(
|
|
|
|
...args: [K, ...Parameters<LayerEvents[K]>]
|
|
|
|
) => void;
|
2022-03-20 17:30:08 +00:00
|
|
|
layer.nodes = ref({});
|
2022-04-06 03:16:40 +00:00
|
|
|
layer.id = id;
|
2022-01-28 04:47:26 +00:00
|
|
|
|
2022-04-06 03:16:40 +00:00
|
|
|
addingLayers.push(id);
|
|
|
|
persistentRefs[id] = new Set();
|
2022-02-27 19:49:34 +00:00
|
|
|
layer.minimized = persistent(false);
|
2022-05-24 04:34:59 +00:00
|
|
|
Object.assign(layer, optionsFunc.call(layer as BaseLayer));
|
2022-04-06 03:16:40 +00:00
|
|
|
if (
|
|
|
|
addingLayers[addingLayers.length - 1] == null ||
|
|
|
|
addingLayers[addingLayers.length - 1] !== id
|
|
|
|
) {
|
|
|
|
throw `Adding layers stack in invalid state. This should not happen\nStack: ${addingLayers}\nTrying to pop ${layer.id}`;
|
|
|
|
}
|
|
|
|
addingLayers.pop();
|
2022-03-13 23:55:47 +00:00
|
|
|
|
2022-02-27 19:49:34 +00:00
|
|
|
processComputable(layer as T, "color");
|
|
|
|
processComputable(layer as T, "display");
|
|
|
|
processComputable(layer as T, "name");
|
|
|
|
setDefault(layer, "name", layer.id);
|
|
|
|
processComputable(layer as T, "minWidth");
|
|
|
|
setDefault(layer, "minWidth", 600);
|
|
|
|
processComputable(layer as T, "minimizable");
|
|
|
|
setDefault(layer, "minimizable", true);
|
2022-01-28 04:47:26 +00:00
|
|
|
|
2022-02-27 19:49:34 +00:00
|
|
|
return layer as unknown as Layer<T>;
|
2022-01-28 04:47:26 +00:00
|
|
|
});
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Enables a layer object, so it will be updated every tick.
|
|
|
|
* Note that accessing a layer/its properties does NOT require it to be enabled.
|
2022-07-10 08:00:08 +00:00
|
|
|
* For dynamic layers you can call this function and {@link removeLayer} as necessary. Just make sure {@link data/projEntry.getInitialLayers} will provide an accurate list of layers based on the player data object.
|
|
|
|
* For static layers just make {@link data/projEntry.getInitialLayers} return all the layers.
|
2022-07-10 05:43:34 +00:00
|
|
|
* @param layer The layer to add.
|
|
|
|
* @param player The player data object, which will have a data object for this layer.
|
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
export function addLayer(
|
|
|
|
layer: GenericLayer,
|
|
|
|
player: { layers?: Record<string, Record<string, unknown>> }
|
|
|
|
): void {
|
2022-01-25 04:23:30 +00:00
|
|
|
console.info("Adding layer", layer.id);
|
|
|
|
if (layers[layer.id]) {
|
2022-01-14 04:25:47 +00:00
|
|
|
console.error(
|
|
|
|
"Attempted to add layer with same ID as existing layer",
|
2021-08-18 05:18:23 +00:00
|
|
|
layer.id,
|
2022-01-14 04:25:47 +00:00
|
|
|
layers[layer.id]
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
);
|
2022-01-14 04:25:47 +00:00
|
|
|
return;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
setDefault(player, "layers", {});
|
|
|
|
if (player.layers[layer.id] == null) {
|
|
|
|
player.layers[layer.id] = {};
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
2022-01-14 04:25:47 +00:00
|
|
|
layers[layer.id] = layer;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
globalBus.emit("addLayer", layer, player.layers[layer.id]);
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for getting a layer by its ID with correct typing.
|
|
|
|
* @param layerID The ID of the layer to get.
|
|
|
|
*/
|
2022-01-28 04:47:26 +00:00
|
|
|
export function getLayer<T extends GenericLayer>(layerID: string): T {
|
|
|
|
return layers[layerID] as T;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Disables a layer, so it will no longer be updated every tick.
|
|
|
|
* Note that accessing a layer/its properties does NOT require it to be enabled.
|
|
|
|
* @param layer The layer to remove.
|
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
export function removeLayer(layer: GenericLayer): void {
|
2022-01-25 04:23:30 +00:00
|
|
|
console.info("Removing layer", layer.id);
|
2022-01-14 04:25:47 +00:00
|
|
|
globalBus.emit("removeLayer", layer);
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
|
2022-01-25 04:23:30 +00:00
|
|
|
layers[layer.id] = undefined;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for removing and immediately re-adding a layer.
|
|
|
|
* This is useful for layers with dynamic content, to ensure persistent refs are correctly configured.
|
|
|
|
* @param layer Layer to remove and then re-add
|
|
|
|
*/
|
2022-01-14 04:25:47 +00:00
|
|
|
export function reloadLayer(layer: GenericLayer): void {
|
|
|
|
removeLayer(layer);
|
|
|
|
|
|
|
|
// Re-create layer
|
|
|
|
addLayer(layer, player);
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-17 04:30:54 +00:00
|
|
|
}
|
2022-01-25 04:23:30 +00:00
|
|
|
|
2022-07-10 05:43:34 +00:00
|
|
|
/**
|
2022-07-10 08:00:08 +00:00
|
|
|
* Utility function for creating a modal that display's a {@link LayerOptions.display}.
|
2022-07-10 05:43:34 +00:00
|
|
|
* Returns the modal itself, which can be rendered anywhere you need, as well as a function to open the modal.
|
|
|
|
* @param layer The layer to display in the modal.
|
|
|
|
*/
|
2022-02-27 23:06:38 +00:00
|
|
|
export function setupLayerModal(layer: GenericLayer): {
|
|
|
|
openModal: VoidFunction;
|
|
|
|
modal: JSXFunction;
|
|
|
|
} {
|
|
|
|
const showModal = ref(false);
|
|
|
|
return {
|
|
|
|
openModal: () => (showModal.value = true),
|
|
|
|
modal: jsx(() => (
|
|
|
|
<Modal
|
|
|
|
modelValue={showModal.value}
|
|
|
|
onUpdate:modelValue={value => (showModal.value = value)}
|
|
|
|
v-slots={{
|
|
|
|
header: () => <h2>{unref(layer.name)}</h2>,
|
|
|
|
body: unref(layer.display)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-25 04:23:30 +00:00
|
|
|
globalBus.on("update", function updateLayers(diff) {
|
|
|
|
Object.values(layers).forEach(layer => {
|
|
|
|
layer?.emit("preUpdate", diff);
|
|
|
|
});
|
|
|
|
Object.values(layers).forEach(layer => {
|
|
|
|
layer?.emit("update", diff);
|
|
|
|
});
|
|
|
|
Object.values(layers).forEach(layer => {
|
|
|
|
layer?.emit("postUpdate", diff);
|
|
|
|
});
|
|
|
|
});
|