From e59dbb02175ec394a35c496201da71c90cd6a50a Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 5 Feb 2019 23:19:26 -0500 Subject: mostly working version, but confused about LayoutKeys needing to inquire value seemingly unecessarily --- src/stores/NodeCollectionStore.ts | 26 ++++++++++++++++++++++++++ src/stores/NodeStore.ts | 24 ++++++++++++++++++++++++ src/stores/StaticTextNodeStore.ts | 16 ++++++++++++++++ src/stores/VideoNodeStore.ts | 17 +++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 src/stores/NodeCollectionStore.ts create mode 100644 src/stores/NodeStore.ts create mode 100644 src/stores/StaticTextNodeStore.ts create mode 100644 src/stores/VideoNodeStore.ts (limited to 'src/stores') diff --git a/src/stores/NodeCollectionStore.ts b/src/stores/NodeCollectionStore.ts new file mode 100644 index 000000000..7fac83d51 --- /dev/null +++ b/src/stores/NodeCollectionStore.ts @@ -0,0 +1,26 @@ +import { computed, observable, action } from "mobx"; +import { NodeStore } from "./NodeStore"; +import { Document } from "../fields/Document"; + +export class NodeCollectionStore extends NodeStore { + + @observable + public Scale: number = 1; + + @observable + public Nodes: NodeStore[] = new Array(); + + @observable + public Docs: Document[] = []; + + @computed + public get Transform(): string { + const halfWidth = window.innerWidth / 2, halfHeight = window.innerHeight / 2; + return `translate(${this.X + halfWidth}px, ${this.Y + halfHeight}px) scale(${this.Scale}) translate(${-halfWidth}px, ${-halfHeight}px)`; + } + + @action + public AddNodes(stores: NodeStore[]): void { + stores.forEach(store => this.Nodes.push(store)); + } +} \ No newline at end of file diff --git a/src/stores/NodeStore.ts b/src/stores/NodeStore.ts new file mode 100644 index 000000000..6a734cf44 --- /dev/null +++ b/src/stores/NodeStore.ts @@ -0,0 +1,24 @@ +import { computed, observable } from "mobx"; +import { Utils } from "../Utils"; + +export class NodeStore { + + public Id: string = Utils.GenerateGuid(); + + @observable + public X: number = 0; + + @observable + public Y: number = 0; + + @observable + public Width: number = 0; + + @observable + public Height: number = 0; + + @computed + public get Transform(): string { + return "translate(" + this.X + "px, " + this.Y + "px)"; + } +} \ No newline at end of file diff --git a/src/stores/StaticTextNodeStore.ts b/src/stores/StaticTextNodeStore.ts new file mode 100644 index 000000000..7c342a7a2 --- /dev/null +++ b/src/stores/StaticTextNodeStore.ts @@ -0,0 +1,16 @@ +import { observable } from "mobx"; +import { NodeStore } from "./NodeStore"; + +export class StaticTextNodeStore extends NodeStore { + + constructor(initializer: Partial) { + super(); + Object.assign(this, initializer); + } + + @observable + public Title: string = ""; + + @observable + public Text: string = ""; +} \ No newline at end of file diff --git a/src/stores/VideoNodeStore.ts b/src/stores/VideoNodeStore.ts new file mode 100644 index 000000000..e5187ab07 --- /dev/null +++ b/src/stores/VideoNodeStore.ts @@ -0,0 +1,17 @@ +import { observable } from "mobx"; +import { NodeStore } from "./NodeStore"; + +export class VideoNodeStore extends NodeStore { + + constructor(initializer: Partial) { + super(); + Object.assign(this, initializer); + } + + @observable + public Title: string = ""; + + @observable + public Url: string = ""; + +} \ No newline at end of file -- cgit v1.2.3-70-g09d2