summaryrefslogtreecommitdiff
path: root/public/SomhairlesDream.Shared/Domain.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/SomhairlesDream.Shared/Domain.js')
-rw-r--r--public/SomhairlesDream.Shared/Domain.js114
1 files changed, 114 insertions, 0 deletions
diff --git a/public/SomhairlesDream.Shared/Domain.js b/public/SomhairlesDream.Shared/Domain.js
new file mode 100644
index 0000000..5384715
--- /dev/null
+++ b/public/SomhairlesDream.Shared/Domain.js
@@ -0,0 +1,114 @@
+import { Record } from "../fable_modules/fable-library-js.4.24.0/Types.js";
+import { bool_type, option_type, class_type, enum_type, array_type, string_type, int32_type, record_type, float64_type } from "../fable_modules/fable-library-js.4.24.0/Reflection.js";
+import { item, collect } from "../fable_modules/fable-library-js.4.24.0/Array.js";
+import { singleton, append, collect as collect_1, delay, toArray } from "../fable_modules/fable-library-js.4.24.0/Seq.js";
+import { rangeDouble } from "../fable_modules/fable-library-js.4.24.0/Range.js";
+import { op_Subtraction } from "../fable_modules/fable-library-js.4.24.0/DateOffset.js";
+
+export class Vector3 extends Record {
+ constructor(X, Y, Z) {
+ super();
+ this.X = X;
+ this.Y = Y;
+ this.Z = Z;
+ }
+}
+
+export function Vector3_$reflection() {
+ return record_type("SomhairlesDream.Shared.Vector3", [], Vector3, () => [["X", float64_type], ["Y", float64_type], ["Z", float64_type]]);
+}
+
+export class MeshSnapshot extends Record {
+ constructor(Version, Label, Vertices, Faces) {
+ super();
+ this.Version = (Version | 0);
+ this.Label = Label;
+ this.Vertices = Vertices;
+ this.Faces = Faces;
+ }
+}
+
+export function MeshSnapshot_$reflection() {
+ return record_type("SomhairlesDream.Shared.MeshSnapshot", [], MeshSnapshot, () => [["Version", int32_type], ["Label", string_type], ["Vertices", array_type(Vector3_$reflection())], ["Faces", array_type(array_type(int32_type))]]);
+}
+
+export class LiveSnapshot extends Record {
+ constructor(ProjectId, RunId, Status, CurrentVersion, TargetVersion, HeartbeatAt, UpdatedAt, Message, Mesh, NextDesignRunScheduled) {
+ super();
+ this.ProjectId = ProjectId;
+ this.RunId = RunId;
+ this.Status = (Status | 0);
+ this.CurrentVersion = (CurrentVersion | 0);
+ this.TargetVersion = (TargetVersion | 0);
+ this.HeartbeatAt = HeartbeatAt;
+ this.UpdatedAt = UpdatedAt;
+ this.Message = Message;
+ this.Mesh = Mesh;
+ this.NextDesignRunScheduled = NextDesignRunScheduled;
+ }
+}
+
+export function LiveSnapshot_$reflection() {
+ return record_type("SomhairlesDream.Shared.LiveSnapshot", [], LiveSnapshot, () => [["ProjectId", string_type], ["RunId", string_type], ["Status", enum_type("SomhairlesDream.Shared.RunStatus", int32_type, [["Idle", 0], ["Queued", 1], ["Running", 2], ["Succeeded", 3], ["Failed", 4], ["Stale", 5]])], ["CurrentVersion", int32_type], ["TargetVersion", int32_type], ["HeartbeatAt", option_type(class_type("System.DateTimeOffset"))], ["UpdatedAt", class_type("System.DateTimeOffset")], ["Message", string_type], ["Mesh", option_type(MeshSnapshot_$reflection())], ["NextDesignRunScheduled", bool_type]]);
+}
+
+export function MeshData_positionData(mesh) {
+ return collect((vertex) => (new Float64Array([vertex.X, vertex.Y, vertex.Z])), mesh.Vertices, Float64Array);
+}
+
+export function MeshData_triangleIndices(mesh) {
+ return collect((face) => {
+ if (face.length < 3) {
+ return new Int32Array([]);
+ }
+ else {
+ return toArray(delay(() => collect_1((index) => append(singleton(item(0, face)), delay(() => append(singleton(item(index, face)), delay(() => singleton(item(index + 1, face)))))), rangeDouble(1, 1, face.length - 2))));
+ }
+ }, mesh.Faces, Int32Array);
+}
+
+export function RunState_initial(projectId, runId, now) {
+ return new LiveSnapshot(projectId, runId, 0, 0, 0, undefined, now, "等待设计运行", undefined, false);
+}
+
+export function RunState_start(now, state) {
+ const targetVersion = (state.TargetVersion + 1) | 0;
+ return new LiveSnapshot(state.ProjectId, state.RunId, 2, state.CurrentVersion, targetVersion, now, now, `正在生成第 ${targetVersion} 版几何`, state.Mesh, false);
+}
+
+export function RunState_heartbeat(now, state) {
+ if (state.Status === 2) {
+ return new LiveSnapshot(state.ProjectId, state.RunId, state.Status, state.CurrentVersion, state.TargetVersion, now, now, state.Message, state.Mesh, state.NextDesignRunScheduled);
+ }
+ else {
+ return state;
+ }
+}
+
+export function RunState_statusAt(timeout, now, state) {
+ const matchValue = state.HeartbeatAt;
+ let matchResult, heartbeatAt_1;
+ if (matchValue != null) {
+ if ((state.Status === 2) && (op_Subtraction(now, matchValue) > timeout)) {
+ matchResult = 0;
+ heartbeatAt_1 = matchValue;
+ }
+ else {
+ matchResult = 1;
+ }
+ }
+ else {
+ matchResult = 1;
+ }
+ switch (matchResult) {
+ case 0:
+ return new LiveSnapshot(state.ProjectId, state.RunId, 5, state.CurrentVersion, state.TargetVersion, state.HeartbeatAt, now, "心跳超时,等待重连", state.Mesh, state.NextDesignRunScheduled);
+ default:
+ return state;
+ }
+}
+
+export function RunState_publish(now, mesh, state) {
+ return new LiveSnapshot(state.ProjectId, state.RunId, 3, mesh.Version, state.TargetVersion, now, now, `已发布${mesh.Label}`, mesh, false);
+}
+