2022-03-04 03:39:48 +00:00
|
|
|
import Modal from "components/Modal.vue";
|
2022-02-27 23:06:38 +00:00
|
|
|
import {
|
|
|
|
CoercableComponent,
|
|
|
|
jsx,
|
|
|
|
JSXFunction,
|
|
|
|
Replace,
|
|
|
|
setDefault,
|
|
|
|
StyleValue
|
2022-03-04 03:39:48 +00:00
|
|
|
} from "features/feature";
|
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
|
|
|
import {
|
2022-01-14 04:25:47 +00:00
|
|
|
Computable,
|
|
|
|
GetComputableType,
|
|
|
|
GetComputableTypeWithDefault,
|
|
|
|
processComputable,
|
|
|
|
ProcessedComputable
|
2022-03-04 03:39:48 +00:00
|
|
|
} from "util/computed";
|
|
|
|
import { createLazyProxy } from "util/proxies";
|
2022-01-14 04:25:47 +00:00
|
|
|
import { createNanoEvents, Emitter } from "nanoevents";
|
2022-03-20 18:57:45 +00:00
|
|
|
import { InjectionKey, Ref, ref, unref } from "vue";
|
2022-01-25 04:23:30 +00:00
|
|
|
import { globalBus } from "./events";
|
2022-02-27 22:18:13 +00:00
|
|
|
import { persistent, PersistentRef } from "./persistence";
|
2022-01-14 04:25:47 +00:00
|
|
|
import player from "./player";
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RegisterNodeInjectionKey: InjectionKey<(id: string, element: HTMLElement) => void> =
|
|
|
|
Symbol("RegisterNode");
|
|
|
|
export const UnregisterNodeInjectionKey: InjectionKey<(id: string) => void> =
|
|
|
|
Symbol("UnregisterNode");
|
|
|
|
export const NodesInjectionKey: InjectionKey<Ref<Record<string, FeatureNode | undefined>>> =
|
|
|
|
Symbol("Nodes");
|
|
|
|
|
2022-01-25 04:23:30 +00:00
|
|
|
export interface LayerEvents {
|
|
|
|
// Generation
|
2022-03-11 20:02:41 +00:00
|
|
|
preUpdate: (diff: number) => void;
|
2022-01-25 04:23:30 +00:00
|
|
|
// Actions (e.g. automation)
|
2022-03-11 20:02:41 +00:00
|
|
|
update: (diff: number) => void;
|
2022-01-25 04:23:30 +00:00
|
|
|
// Effects (e.g. milestones)
|
2022-03-11 20:02:41 +00:00
|
|
|
postUpdate: (diff: number) => void;
|
2022-01-25 04:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const 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" {
|
|
|
|
interface CSSProperties {
|
|
|
|
"--layer-color"?: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 04:25:47 +00:00
|
|
|
export interface Position {
|
|
|
|
x: number;
|
|
|
|
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-01-14 04:25:47 +00:00
|
|
|
export interface LayerOptions {
|
|
|
|
id: string;
|
|
|
|
color?: Computable<string>;
|
|
|
|
display: Computable<CoercableComponent>;
|
|
|
|
classes?: Computable<Record<string, boolean>>;
|
|
|
|
style?: Computable<StyleValue>;
|
|
|
|
name?: Computable<string>;
|
|
|
|
minimizable?: Computable<boolean>;
|
|
|
|
forceHideGoBack?: Computable<boolean>;
|
|
|
|
minWidth?: Computable<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-01-14 04:25:47 +00:00
|
|
|
export interface BaseLayer {
|
|
|
|
minimized: PersistentRef<boolean>;
|
|
|
|
emitter: Emitter<LayerEvents>;
|
|
|
|
on: OmitThisParameter<Emitter<LayerEvents>["on"]>;
|
|
|
|
emit: <K extends keyof LayerEvents>(event: K, ...args: Parameters<LayerEvents[K]>) => void;
|
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-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"]>;
|
|
|
|
name: GetComputableTypeWithDefault<T["name"], T["id"]>;
|
|
|
|
minWidth: GetComputableTypeWithDefault<T["minWidth"], 600>;
|
|
|
|
minimizable: GetComputableTypeWithDefault<T["minimizable"], true>;
|
|
|
|
forceHideGoBack: GetComputableType<T["forceHideGoBack"]>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
|
|
|
export type GenericLayer = Replace<
|
|
|
|
Layer<LayerOptions>,
|
|
|
|
{
|
|
|
|
name: ProcessedComputable<string>;
|
|
|
|
minWidth: ProcessedComputable<number>;
|
|
|
|
minimizable: ProcessedComputable<boolean>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
2022-03-13 23:55:47 +00:00
|
|
|
export function createLayer<T extends LayerOptions>(
|
|
|
|
optionsFunc: (() => T) & ThisType<BaseLayer>
|
|
|
|
): 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);
|
|
|
|
layer.emit = emitter.emit.bind(emitter);
|
2022-03-20 17:30:08 +00:00
|
|
|
layer.nodes = ref({});
|
2022-01-28 04:47:26 +00:00
|
|
|
|
2022-02-27 19:49:34 +00:00
|
|
|
layer.minimized = persistent(false);
|
2022-01-28 04:47:26 +00:00
|
|
|
|
2022-03-13 23:55:47 +00:00
|
|
|
Object.assign(layer, optionsFunc.call(layer));
|
|
|
|
|
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-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-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-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-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-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);
|
|
|
|
});
|
|
|
|
});
|