@iniesta8888/agent-live 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/CODE_OF_CONDUCT.md +7 -0
  2. package/CONTRIBUTING.md +56 -0
  3. package/LICENSE +21 -0
  4. package/README.md +92 -0
  5. package/SECURITY.md +13 -0
  6. package/dist/adapter-sdk/index.d.ts +45 -0
  7. package/dist/adapter-sdk/index.d.ts.map +1 -0
  8. package/dist/adapter-sdk/index.js +106 -0
  9. package/dist/adapter-sdk/index.js.map +1 -0
  10. package/dist/content/compiler.d.ts +31 -0
  11. package/dist/content/compiler.d.ts.map +1 -0
  12. package/dist/content/compiler.js +218 -0
  13. package/dist/content/compiler.js.map +1 -0
  14. package/dist/content/graph-validator.d.ts +56 -0
  15. package/dist/content/graph-validator.d.ts.map +1 -0
  16. package/dist/content/graph-validator.js +226 -0
  17. package/dist/content/graph-validator.js.map +1 -0
  18. package/dist/content/library.d.ts +4 -0
  19. package/dist/content/library.d.ts.map +1 -0
  20. package/dist/content/library.js +45 -0
  21. package/dist/content/library.js.map +1 -0
  22. package/dist/content/registry.d.ts +34 -0
  23. package/dist/content/registry.d.ts.map +1 -0
  24. package/dist/content/registry.js +130 -0
  25. package/dist/content/registry.js.map +1 -0
  26. package/dist/content/runtime-content.d.ts +63 -0
  27. package/dist/content/runtime-content.d.ts.map +1 -0
  28. package/dist/content/runtime-content.js +78 -0
  29. package/dist/content/runtime-content.js.map +1 -0
  30. package/dist/content/schema.d.ts +142 -0
  31. package/dist/content/schema.d.ts.map +1 -0
  32. package/dist/content/schema.js +280 -0
  33. package/dist/content/schema.js.map +1 -0
  34. package/dist/content/validator.d.ts +35 -0
  35. package/dist/content/validator.d.ts.map +1 -0
  36. package/dist/content/validator.js +205 -0
  37. package/dist/content/validator.js.map +1 -0
  38. package/dist/core/agents.d.ts +56 -0
  39. package/dist/core/agents.d.ts.map +1 -0
  40. package/dist/core/agents.js +148 -0
  41. package/dist/core/agents.js.map +1 -0
  42. package/dist/core/limits.d.ts +15 -0
  43. package/dist/core/limits.d.ts.map +1 -0
  44. package/dist/core/limits.js +16 -0
  45. package/dist/core/limits.js.map +1 -0
  46. package/dist/core/mapping.d.ts +17 -0
  47. package/dist/core/mapping.d.ts.map +1 -0
  48. package/dist/core/mapping.js +94 -0
  49. package/dist/core/mapping.js.map +1 -0
  50. package/dist/core/protocol.d.ts +105 -0
  51. package/dist/core/protocol.d.ts.map +1 -0
  52. package/dist/core/protocol.js +6 -0
  53. package/dist/core/protocol.js.map +1 -0
  54. package/dist/core/state.d.ts +49 -0
  55. package/dist/core/state.d.ts.map +1 -0
  56. package/dist/core/state.js +216 -0
  57. package/dist/core/state.js.map +1 -0
  58. package/dist/creator/commands.d.ts +19 -0
  59. package/dist/creator/commands.d.ts.map +1 -0
  60. package/dist/creator/commands.js +44 -0
  61. package/dist/creator/commands.js.map +1 -0
  62. package/dist/creator/mode.d.ts +10 -0
  63. package/dist/creator/mode.d.ts.map +1 -0
  64. package/dist/creator/mode.js +23 -0
  65. package/dist/creator/mode.js.map +1 -0
  66. package/dist/creator/service.d.ts +199 -0
  67. package/dist/creator/service.d.ts.map +1 -0
  68. package/dist/creator/service.js +159 -0
  69. package/dist/creator/service.js.map +1 -0
  70. package/dist/index.d.ts +14 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +10 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/runtime/agent-live-runtime.d.ts +17 -0
  75. package/dist/runtime/agent-live-runtime.d.ts.map +1 -0
  76. package/dist/runtime/agent-live-runtime.js +50 -0
  77. package/dist/runtime/agent-live-runtime.js.map +1 -0
  78. package/dist/runtime/content-service.d.ts +75 -0
  79. package/dist/runtime/content-service.d.ts.map +1 -0
  80. package/dist/runtime/content-service.js +60 -0
  81. package/dist/runtime/content-service.js.map +1 -0
  82. package/dist/runtime/resource-guard.d.ts +17 -0
  83. package/dist/runtime/resource-guard.d.ts.map +1 -0
  84. package/dist/runtime/resource-guard.js +54 -0
  85. package/dist/runtime/resource-guard.js.map +1 -0
  86. package/dist/runtime/server.d.ts +39 -0
  87. package/dist/runtime/server.d.ts.map +1 -0
  88. package/dist/runtime/server.js +286 -0
  89. package/dist/runtime/server.js.map +1 -0
  90. package/dist/web/app.d.ts +1 -0
  91. package/dist/web/app.js +1317 -0
  92. package/dist/web/index.html +45 -0
  93. package/dist/web/office.js +350 -0
  94. package/dist/web/sprites.js +185 -0
  95. package/dist/web/style.css +288 -0
  96. package/dist/web/v2/bootstrap.js +276 -0
  97. package/dist/web/v2/content/README.md +17 -0
  98. package/dist/web/v2/content/agent-skins/studio-team.json +33 -0
  99. package/dist/web/v2/content/agent-skins/tiny-developers.json +33 -0
  100. package/dist/web/v2/content/atmospheres/default.json +13 -0
  101. package/dist/web/v2/content/atmospheres/rainy-night.json +37 -0
  102. package/dist/web/v2/content/catalog.json +14 -0
  103. package/dist/web/v2/content/component-library/activity-implementations.json +873 -0
  104. package/dist/web/v2/content/component-library/activity-recipes.json +25 -0
  105. package/dist/web/v2/content/component-library/agent-profile-templates.json +18 -0
  106. package/dist/web/v2/content/component-library/catalog.json +38 -0
  107. package/dist/web/v2/content/component-library/npc-templates.json +42 -0
  108. package/dist/web/v2/content/component-library/props.json +41 -0
  109. package/dist/web/v2/content/environments/local-office.json +31 -0
  110. package/dist/web/v2/content/environments/rainy-night.json +28 -0
  111. package/dist/web/v2/content/environments/static-office.json +27 -0
  112. package/dist/web/v2/content/layouts/boardroom-office.json +122 -0
  113. package/dist/web/v2/content/layouts/demo-office.json +88 -0
  114. package/dist/web/v2/content/layouts/lively-office.json +96 -0
  115. package/dist/web/v2/content/layouts/old-school-office.json +154 -0
  116. package/dist/web/v2/content/layouts/tech-open-office.json +132 -0
  117. package/dist/web/v2/content/life-activities/boardroom-routines.json +67 -0
  118. package/dist/web/v2/content/life-activities/none.json +10 -0
  119. package/dist/web/v2/content/life-activities/office-basics.json +39 -0
  120. package/dist/web/v2/content/life-activities/old-school-routines.json +74 -0
  121. package/dist/web/v2/content/life-activities/tech-office-routines.json +148 -0
  122. package/dist/web/v2/content/npcs/boardroom-staff.json +54 -0
  123. package/dist/web/v2/content/npcs/none.json +10 -0
  124. package/dist/web/v2/content/npcs/office-staff.json +25 -0
  125. package/dist/web/v2/content/npcs/old-school-staff.json +39 -0
  126. package/dist/web/v2/content/npcs/tech-office-staff.json +40 -0
  127. package/dist/web/v2/content/official-offices/boardroom-office.json +25 -0
  128. package/dist/web/v2/content/official-offices/old-school-office.json +25 -0
  129. package/dist/web/v2/content/official-offices/tech-open-office.json +25 -0
  130. package/dist/web/v2/content/presets/boardroom-office.json +21 -0
  131. package/dist/web/v2/content/presets/cozy-studio.json +19 -0
  132. package/dist/web/v2/content/presets/demo-office.json +19 -0
  133. package/dist/web/v2/content/presets/lively-office.json +19 -0
  134. package/dist/web/v2/content/presets/night-shift.json +19 -0
  135. package/dist/web/v2/content/presets/old-school-office.json +20 -0
  136. package/dist/web/v2/content/presets/refined-demo.json +20 -0
  137. package/dist/web/v2/content/presets/tech-open-office.json +21 -0
  138. package/dist/web/v2/content/props/default-office.json +23 -0
  139. package/dist/web/v2/content/props/extended-office.json +39 -0
  140. package/dist/web/v2/content/props/tech-office.json +28 -0
  141. package/dist/web/v2/content/styles/pixel-classic.json +160 -0
  142. package/dist/web/v2/content/styles/warm-studio.json +150 -0
  143. package/dist/web/v2/environment-runtime.d.ts +1 -0
  144. package/dist/web/v2/environment-runtime.js +138 -0
  145. package/dist/web/v2/graph-validator.d.ts +55 -0
  146. package/dist/web/v2/graph-validator.js +225 -0
  147. package/dist/web/v2/i18n.js +54 -0
  148. package/dist/web/v2/locales/en.json +209 -0
  149. package/dist/web/v2/locales/zh-CN.json +52 -0
  150. package/dist/web/v2/office-engine.d.ts +1 -0
  151. package/dist/web/v2/office-engine.js +145 -0
  152. package/dist/web/v2/office-renderer.d.ts +1 -0
  153. package/dist/web/v2/office-renderer.js +843 -0
  154. package/dist/web/v2/parity.html +10 -0
  155. package/dist/web/v2/parity.js +82 -0
  156. package/dist/web/v2/sprite-renderer.d.ts +1 -0
  157. package/dist/web/v2/sprite-renderer.js +242 -0
  158. package/dist/web/v2/static-content.js +48 -0
  159. package/dist/web/v2/style.css +140 -0
  160. package/dist/web/v2.html +68 -0
  161. package/docs/ADAPTER-DEVELOPMENT.md +328 -0
  162. package/docs/ADAPTER-SDK.md +109 -0
  163. package/docs/ARCHITECTURE.md +223 -0
  164. package/docs/COMPONENT-LIBRARY.md +212 -0
  165. package/docs/CUSTOMIZATION.md +163 -0
  166. package/docs/DEVELOPER.md +186 -0
  167. package/docs/DSH-ADAPTER-DESIGN.md +173 -0
  168. package/docs/OFFICE-THEMES.md +516 -0
  169. package/docs/PRESET-CONFIG.md +460 -0
  170. package/docs/RELEASE-CHECK.md +23 -0
  171. package/docs/TECHNICAL.md +515 -0
  172. package/docs/USING-CODEX.md +24 -0
  173. package/docs/USING-DSH.md +44 -0
  174. package/docs/USING-PI.md +50 -0
  175. package/docs/VISION.md +146 -0
  176. package/examples/adapter/local-office.mjs +52 -0
  177. package/package.json +89 -0
  178. package/skills/agent-live-adapter-builder/SKILL.md +30 -0
  179. package/skills/agent-live-adapter-builder/agents/openai.yaml +4 -0
  180. package/skills/agent-live-adapter-builder/references/investigation.md +9 -0
  181. package/skills/agent-live-adapter-builder/references/review.md +7 -0
  182. package/skills/agent-live-adapter-builder/scripts/create-adapter.mjs +26 -0
@@ -0,0 +1,843 @@
1
+ import { createOfficeEngine } from "./office-engine.js";
2
+
3
+ /** Build the V2 Canvas renderer from content data and the shared world engine. */
4
+ export function createOfficeRenderer(content, environment = null) {
5
+ const engine = createOfficeEngine(content, environment);
6
+ const localize = (value) => window.AgentLiveI18n?.text(value) ?? value;
7
+ const layout = content.layout;
8
+ const propTypes = content.props.types;
9
+ const C = { ...content.style.tokens.canvas, ...(content.atmosphere.styleOverrides?.canvas ?? {}) };
10
+ const UI = content.style.tokens.css ?? {};
11
+ const renderMode = content.preset.render?.detail ?? content.style.tokens.render?.detail ?? "classic";
12
+ const rich = renderMode === "rich";
13
+ const { W, H, WALL_H, SEATS, TARGETS, AMBIENT_EFFECTS } = engine;
14
+ const AREAS = [...(layout.areas ?? [])];
15
+ // Fit immutable room signage once, then reuse on every animation frame.
16
+ let signs;
17
+ function drawSigns(c) {
18
+ c.save();
19
+ c.textAlign = "center";
20
+ c.textBaseline = "middle";
21
+ signs ??= (layout.textSlots ?? []).map((slot) => {
22
+ const treatment = slot.id === "company"
23
+ ? { font: 'bold 7px ui-monospace, "PingFang SC", monospace', ink: UI.accent ?? C.activeAccent, rule: UI.accent ?? C.activeAccent }
24
+ : slot.id === "slogan"
25
+ ? { font: '600 6px ui-monospace, "PingFang SC", monospace', ink: UI.dim ?? C.boardTextDim, rule: UI.line ?? C.wallTrim }
26
+ : { font: '600 6px ui-monospace, "PingFang SC", monospace', ink: UI.ink ?? C.paper, rule: UI.think ?? C.activeThink };
27
+ let text = String(slot.text ?? slot.defaultText ?? "");
28
+ const original = text;
29
+ c.font = treatment.font;
30
+ while (text && c.measureText(text + (text !== original ? "…" : "")).width > slot.width - 8) text = [...text].slice(0, -1).join("");
31
+ return { ...slot, ...treatment, text: text + (text !== original && text ? "…" : "") };
32
+ });
33
+ for (const slot of signs) {
34
+ if (!slot.text) continue;
35
+ // Treat room text as physical versions of the surrounding UI panels:
36
+ // square pixel shadow, line border, inset panel and one semantic rule.
37
+ px(c, slot.x + 2, slot.y + 2, slot.width, slot.height, C.objectShadow ?? "rgba(0,0,0,.3)");
38
+ px(c, slot.x, slot.y, slot.width, slot.height, UI.line ?? C.outline);
39
+ px(c, slot.x + 1, slot.y + 1, slot.width - 2, slot.height - 2, UI.panel ?? C.wallBase ?? C.woodDark);
40
+ px(c, slot.x + 2, slot.y + 2, slot.width - 4, 1, UI["panel-2"] ?? C.wallHighlight);
41
+ px(c, slot.x + 2, slot.y + slot.height - 2, slot.width - 4, 1, slot.rule);
42
+ c.save();
43
+ c.beginPath();
44
+ c.rect(slot.x + 4, slot.y + 2, slot.width - 8, slot.height - 4);
45
+ c.clip();
46
+ c.font = slot.font;
47
+ c.fillStyle = slot.ink;
48
+ c.fillText(slot.text, slot.x + slot.width / 2, slot.y + slot.height / 2);
49
+ c.restore();
50
+ }
51
+ c.restore();
52
+ }
53
+ const instances = layout.propInstances.map((instance) => {
54
+ const type = propTypes[instance.type];
55
+ return {
56
+ ...instance,
57
+ w: instance.width ?? type.size.width,
58
+ h: instance.height ?? type.size.height,
59
+ capabilities: type.capabilities,
60
+ renderer: type.renderer,
61
+ };
62
+ });
63
+ const byRenderer = (renderer) => instances.filter((instance) => instance.renderer === renderer);
64
+ const first = (renderer) => byRenderer(renderer)[0];
65
+ const FURNITURE = {
66
+ archive: first("archive-cabinet"),
67
+ server: first("server-rack"),
68
+ coffee: first("coffee-machine"),
69
+ phone: first("phone-table"),
70
+ whiteboard: first("whiteboard"),
71
+ meeting: first("meeting-table"),
72
+ };
73
+
74
+ const px = (c, x, y, w, h, color) => {
75
+ c.fillStyle = color;
76
+ c.fillRect(x | 0, y | 0, w | 0, h | 0);
77
+ };
78
+ const poly = (c, points, color) => {
79
+ c.beginPath();
80
+ c.moveTo(points[0][0] | 0, points[0][1] | 0);
81
+ for (let i = 1; i < points.length; i++) c.lineTo(points[i][0] | 0, points[i][1] | 0);
82
+ c.closePath();
83
+ c.fillStyle = color;
84
+ c.fill();
85
+ };
86
+ const noise = (x, y, salt = 0) => {
87
+ let value = Math.imul((x | 0) + 17, 374761393) ^ Math.imul((y | 0) + 31, 668265263) ^ salt;
88
+ value = Math.imul(value ^ (value >>> 13), 1274126177);
89
+ return (value ^ (value >>> 16)) >>> 0;
90
+ };
91
+ const outline = (c, x, y, w, h, color = C.outline ?? C.woodDark) => {
92
+ px(c, x, y, w, 1, color);
93
+ px(c, x, y + h - 1, w, 1, color);
94
+ px(c, x, y, 1, h, color);
95
+ px(c, x + w - 1, y, 1, h, color);
96
+ };
97
+ const pixelLine = (c, x0, y0, x1, y1, color) => {
98
+ x0 |= 0;
99
+ y0 |= 0;
100
+ x1 |= 0;
101
+ y1 |= 0;
102
+ const dx = Math.abs(x1 - x0);
103
+ const sx = x0 < x1 ? 1 : -1;
104
+ const dy = -Math.abs(y1 - y0);
105
+ const sy = y0 < y1 ? 1 : -1;
106
+ let error = dx + dy;
107
+ while (true) {
108
+ px(c, x0, y0, 1, 1, color);
109
+ if (x0 === x1 && y0 === y1) break;
110
+ const twice = 2 * error;
111
+ if (twice >= dy) {
112
+ error += dy;
113
+ x0 += sx;
114
+ }
115
+ if (twice <= dx) {
116
+ error += dx;
117
+ y0 += sy;
118
+ }
119
+ }
120
+ };
121
+ const currentEnvironment = engine.currentEnvironment;
122
+
123
+ function drawFloor(c) {
124
+ px(c, 0, WALL_H, W, H - WALL_H, C.floorA);
125
+ if (rich) {
126
+ const plankH = 8;
127
+ const plankW = 32;
128
+ for (let y = WALL_H; y < H; y += plankH) {
129
+ const row = ((y - WALL_H) / plankH) | 0;
130
+ const offset = row % 2 ? -(plankW >> 1) : 0;
131
+ for (let x = offset; x < W; x += plankW) {
132
+ const tone = noise(x, y, 91) % 3;
133
+ px(c, x + 1, y + 1, plankW - 1, plankH - 1, tone === 0 ? C.floorA : tone === 1 ? C.floorB : C.floorC);
134
+ px(c, x + 5 + (noise(x, y, 17) % 15), y + 3, 8 + (noise(x, y, 33) % 8), 1, C.floorGrain);
135
+ }
136
+ px(c, 0, y, W, 1, C.floorLine);
137
+ }
138
+ } else {
139
+ for (let y = WALL_H; y < H; y += 16) {
140
+ for (let x = 0; x < W; x += 16) {
141
+ if (((x / 16) | 0) % 2 === ((y / 16) | 0) % 2) px(c, x, y, 16, 16, C.floorB);
142
+ }
143
+ }
144
+ for (let y = WALL_H; y < H; y += 16) px(c, 0, y, W, 1, C.floorLine);
145
+ for (let x = 0; x < W; x += 16) px(c, x, WALL_H, 1, H - WALL_H, C.floorLine);
146
+ }
147
+ for (const rug of byRenderer("rug")) {
148
+ if (rich) px(c, rug.x + 2, rug.y + 3, rug.w, rug.h, C.objectShadow);
149
+ px(c, rug.x, rug.y, rug.w, rug.h, C.rug);
150
+ px(c, rug.x, rug.y, rug.w, 1, C.rugEdge);
151
+ px(c, rug.x, rug.y + rug.h - 1, rug.w, 1, C.rugEdge);
152
+ px(c, rug.x, rug.y, 1, rug.h, C.rugEdge);
153
+ px(c, rug.x + rug.w - 1, rug.y, 1, rug.h, C.rugEdge);
154
+ }
155
+ }
156
+
157
+ function drawWall(c, t, officeTime) {
158
+ const timedSky = {
159
+ morning: C.skyMorning ?? "#7faec7",
160
+ noon: C.skyNoon ?? "#91cde0",
161
+ evening: C.skyEvening ?? "#d98262",
162
+ night: C.skyNight ?? "#17243c",
163
+ }[officeTime.phase];
164
+ const sky = officeTime.dynamicTime ? timedSky : C.glass;
165
+ px(c, 0, 0, W, WALL_H, C.wall);
166
+ px(c, 0, 0, W, 6, C.wallTop);
167
+ px(c, 0, WALL_H - 3, W, 3, C.wallTrim);
168
+ if (rich) {
169
+ px(c, 0, 6, W, 2, C.wallShade);
170
+ for (let x = 0; x < W; x += 48) {
171
+ px(c, x, 7, 2, WALL_H - 10, C.wallSeam);
172
+ px(c, x + 2, 7, 1, WALL_H - 10, C.wallHighlight);
173
+ }
174
+ px(c, 0, WALL_H - 7, W, 4, C.wallBase);
175
+ px(c, 0, WALL_H - 7, W, 1, C.wallHighlight);
176
+ }
177
+ for (const door of byRenderer("door")) {
178
+ if (rich) px(c, door.x - 3, door.y - 3, door.w + 6, door.h + 4, C.outline);
179
+ px(c, door.x, door.y, door.w, door.h, C.door);
180
+ px(c, door.x, door.y, door.w, 2, C.doorDark);
181
+ px(c, door.x + door.w - 3, door.y, 3, door.h, C.doorDark);
182
+ px(c, door.x + 4, door.y + 4, door.w - 11, door.h - 8, C.doorPanel);
183
+ if (rich) {
184
+ outline(c, door.x + 5, door.y + 5, door.w - 12, Math.max(6, (door.h >> 1) - 5), C.doorDark);
185
+ outline(c, door.x + 5, door.y + (door.h >> 1) + 1, door.w - 12, Math.max(6, (door.h >> 1) - 5), C.doorDark);
186
+ px(c, door.x + 7, door.y + 7, door.w - 16, 1, C.doorLite);
187
+ }
188
+ px(c, door.x + door.w - 9, door.y + 16, 2, 3, C.paper);
189
+ }
190
+ for (const window of byRenderer("window")) {
191
+ if (rich) px(c, window.x - 4, window.y - 4, window.w + 8, window.h + 7, C.outline);
192
+ px(c, window.x - 2, window.y - 2, window.w + 4, window.h + 4, C.wallTrim);
193
+ px(c, window.x, window.y, window.w, window.h, sky);
194
+ px(c, window.x, window.y, window.w, 8, officeTime.dynamicTime && officeTime.phase === "night" ? (C.skyNightLite ?? C.glass) : C.glassLite);
195
+ if (rich) {
196
+ px(c, window.x + 2, window.y + 2, window.w - 4, 2, C.glassShine);
197
+ px(c, window.x + 3, window.y + 5, 2, window.h - 8, C.glassShine);
198
+ px(c, window.x - 3, window.y + window.h + 2, window.w + 6, 3, C.wallBase);
199
+ }
200
+ px(c, window.x + (window.w >> 1), window.y, 1, window.h, C.wallTrim);
201
+ px(c, window.x, window.y + (window.h >> 1), window.w, 1, C.wallTrim);
202
+ if (!officeTime.dynamicTime && Math.sin(t / 900 + window.x) > 0.7) px(c, window.x + 6, window.y + 14, 2, 2, C.windowSpark);
203
+ if (officeTime.dynamicTime && officeTime.phase === "morning") px(c, window.x + 6, window.y + 11, 5, 5, C.skySun ?? C.windowSpark);
204
+ if (officeTime.dynamicTime && officeTime.phase === "noon" && Math.sin(t / 900 + window.x) > 0.7) px(c, window.x + 6, window.y + 14, 2, 2, C.windowSpark);
205
+ if (officeTime.dynamicTime && officeTime.phase === "evening") px(c, window.x + 1, window.y + window.h - 6, window.w - 2, 5, C.skyHorizon ?? C.activeRed);
206
+ if (officeTime.dynamicTime && officeTime.phase === "night") {
207
+ px(c, window.x + 7, window.y + 12, 2, 2, C.skyStar ?? C.windowSpark);
208
+ px(c, window.x + window.w - 10, window.y + 6, 1, 1, C.skyStar ?? C.windowSpark);
209
+ for (let bx = window.x + 4; bx < window.x + window.w - 3; bx += 7) {
210
+ const height = 3 + (noise(bx, window.y, 47) % 6);
211
+ px(c, bx, window.y + window.h - height, 5, height, C.skyBuilding ?? C.wallTop);
212
+ if (noise(bx, window.y, 19) % 2) px(c, bx + 2, window.y + window.h - height + 2, 1, 1, C.skyWindow ?? C.windowSpark);
213
+ }
214
+ }
215
+ drawWindowWeather(c, window, t, officeTime);
216
+ }
217
+ for (const window of byRenderer("venetian-window")) {
218
+ px(c, window.x - 2, window.y - 2, window.w + 4, window.h + 4, C.wallTrim);
219
+ px(c, window.x, window.y, window.w, window.h, sky);
220
+ px(c, window.x + (window.w >> 1), window.y, 1, window.h, C.wallTrim);
221
+ drawWindowWeather(c, window, t, officeTime);
222
+ for (let y = window.y + 3; y < window.y + window.h - 1; y += 4) {
223
+ px(c, window.x + 1, y, window.w - 2, 1, C.paperLine);
224
+ }
225
+ }
226
+ }
227
+
228
+ function drawWindowWeather(c, window, t, officeTime) {
229
+ const condition = officeTime.dynamicWeather ? officeTime.weather : AMBIENT_EFFECTS.has("rain-window") ? "rain" : "clear";
230
+ if (condition === "cloudy") {
231
+ px(c, window.x + 5, window.y + 8, Math.max(8, window.w - 18), 3, C.cloud ?? C.paper);
232
+ px(c, window.x + 12, window.y + 5, Math.max(5, window.w - 25), 4, C.cloud ?? C.paper);
233
+ }
234
+ if (condition === "rain") {
235
+ for (let i = 0; i < 4; i++) {
236
+ const rx = window.x + 5 + ((i * 11 + ((t / 180) | 0) * 3) % Math.max(8, window.w - 10));
237
+ const ry = window.y + 3 + ((i * 7 + ((t / 95) | 0) * 2) % Math.max(6, window.h - 7));
238
+ px(c, rx, ry, 1, 4, C.rain ?? C.waterActive);
239
+ }
240
+ }
241
+ if (condition === "snow") {
242
+ for (let i = 0; i < 5; i++) {
243
+ const sx = window.x + 4 + ((i * 13 + ((t / 260) | 0)) % Math.max(7, window.w - 8));
244
+ const sy = window.y + 3 + ((i * 7 + ((t / 180) | 0)) % Math.max(5, window.h - 6));
245
+ px(c, sx, sy, 2, 2, C.snow ?? C.paper);
246
+ }
247
+ }
248
+ }
249
+
250
+ function drawWhiteboard(c, item, hot, t) {
251
+ px(c, item.x - 2, item.y - 2, item.w + 4, item.h + 4, C.boardFrame);
252
+ px(c, item.x, item.y, item.w, item.h, C.board);
253
+ px(c, item.x + 5, item.y + 4, 34, 1, C.boardText);
254
+ px(c, item.x + 5, item.y + 8, 46, 1, C.boardText);
255
+ px(c, item.x + 5, item.y + 12, 26, 1, C.boardTextDim);
256
+ if (hot.has("whiteboard")) {
257
+ const n = 4 + (((t / 140) | 0) % 24);
258
+ px(c, item.x + 5, item.y + 16, n, 1, C.activeRed);
259
+ px(c, item.x + 5, item.y + 20, Math.max(2, n - 9), 1, C.activeBlue);
260
+ } else {
261
+ px(c, item.x + 5, item.y + 16, 18, 1, C.boardIdle);
262
+ }
263
+ }
264
+
265
+ function drawDesk(c, seat, hot) {
266
+ const { deskX: x, deskY: y, deskW: w, deskH: h } = seat;
267
+ if (rich) px(c, x + 3, y + 5, w, h + 3, C.objectShadow);
268
+ px(c, x, y + h, w, 3, C.woodDark);
269
+ if (rich) outline(c, x - 1, y - 1, w + 2, h + 3);
270
+ px(c, x, y, w, h, C.deskTop);
271
+ px(c, x, y, w, 2, C.deskLite);
272
+ px(c, x + 2, y + h - 2, w - 4, 2, C.woodDark);
273
+ if (rich) {
274
+ px(c, x + 5, y + 5, w - 10, 1, C.woodGrain);
275
+ px(c, x + 3, y + h, 4, 6, C.woodDark);
276
+ px(c, x + w - 7, y + h, 4, 6, C.woodDark);
277
+ }
278
+ const mx = seat.cx - 9;
279
+ const my = y - 11;
280
+ if (rich) px(c, mx - 2, my - 2, 22, 15, C.outline);
281
+ px(c, mx - 1, my - 1, 20, 13, C.metalDark);
282
+ px(c, mx, my, 18, 11, C.screen);
283
+ if (rich) px(c, mx + 2, my + 2, 14, 1, C.screenGlow);
284
+ if (hot.has(`desk${seat.index}`)) {
285
+ px(c, mx + 2, my + 2, 14, 1, C.activeGreen);
286
+ px(c, mx + 2, my + 4, 10, 1, C.activeThink);
287
+ px(c, mx + 2, my + 6, 12, 1, C.activeThink);
288
+ px(c, mx + 2, my + 8, 6, 1, C.activeAccent);
289
+ } else {
290
+ px(c, mx + 2, my + 3, 8, 1, C.screenIdle);
291
+ px(c, mx + 2, my + 6, 11, 1, C.screenIdle);
292
+ }
293
+ px(c, seat.cx - 2, my + 12, 4, 2, C.metalDark);
294
+ if (rich) {
295
+ px(c, seat.cx - 7, y + 9, 15, 3, C.keyboard);
296
+ for (let key = 0; key < 6; key++) px(c, seat.cx - 6 + key * 2, y + 10, 1, 1, C.keyboardKey);
297
+ const accessory = seat.index % 4;
298
+ if (accessory === 0) {
299
+ px(c, x + 4, y + 4, 3, 4, C.mug);
300
+ px(c, x + 7, y + 5, 1, 2, C.mugLite);
301
+ } else if (accessory === 1) {
302
+ px(c, x + 4, y + 6, 5, 3, C.pot);
303
+ px(c, x + 5, y + 2, 1, 5, C.plantDark);
304
+ px(c, x + 3, y + 2, 3, 3, C.plantLite);
305
+ px(c, x + 6, y + 1, 3, 4, C.plantHighlight);
306
+ } else if (accessory === 2) {
307
+ px(c, x + 3, y + 4, 7, 5, C.activeAccent);
308
+ px(c, x + 4, y + 3, 2, 2, C.activeAccent);
309
+ px(c, x + 7, y + 3, 2, 2, C.activeAccent);
310
+ px(c, x + 4, y + 5, 1, 1, C.faceInk ?? C.outline);
311
+ px(c, x + 8, y + 5, 1, 1, C.faceInk ?? C.outline);
312
+ } else {
313
+ px(c, x + 3, y + 5, 8, 5, C.paper);
314
+ px(c, x + 4, y + 6, 6, 1, C.activeThink);
315
+ px(c, x + 4, y + 8, 4, 1, C.paperLine);
316
+ }
317
+ }
318
+ px(c, seat.cx + 12, y + 4, 7, 5, C.paper);
319
+ px(c, seat.cx + 12, y + 4, 7, 1, C.paperLine);
320
+ }
321
+
322
+ function drawChair(c, seat, occupied) {
323
+ const x = seat.cx - 7;
324
+ const y = seat.deskY + 21;
325
+ if (rich) px(c, x + 2, y + 3, 14, 11, C.objectShadow);
326
+ px(c, x, y, 14, 9, occupied ? C.chairDark : C.chair);
327
+ if (rich) {
328
+ outline(c, x - 1, y - 1, 16, 11);
329
+ px(c, x + 2, y + 2, 10, 2, occupied ? C.chair : C.chairLite);
330
+ }
331
+ px(c, x, y + 9, 14, 2, C.chairDark);
332
+ px(c, x + 5, y + 11, 4, 3, C.metalDark);
333
+ }
334
+
335
+ function drawCubicleSeat(c, seat, hot) {
336
+ const { deskX: x, deskY: y, deskW: w, deskH: h } = seat;
337
+ px(c, x, y + h, w, 3, C.woodDark);
338
+ px(c, x, y, w, h, C.deskTop);
339
+ px(c, x, y, w, 2, C.deskLite);
340
+ const mx = seat.cx - 8;
341
+ const my = seat.anchor.dir === "down" ? y + h - 1 : y - 13;
342
+ px(c, mx - 1, my - 1, 18, 13, C.metalDark);
343
+ px(c, mx, my, 16, 10, C.screen);
344
+ if (hot.has(`desk${seat.index}`)) {
345
+ px(c, mx + 2, my + 2, 12, 1, C.activeGreen);
346
+ px(c, mx + 2, my + 5, 8, 1, C.activeThink);
347
+ px(c, mx + 2, my + 7, 11, 1, C.activeAccent);
348
+ } else {
349
+ px(c, mx + 2, my + 3, 8, 1, C.screenIdle);
350
+ px(c, mx + 2, my + 6, 11, 1, C.screenIdle);
351
+ }
352
+ px(c, mx + 6, my + 11, 4, 2, C.metalDark);
353
+ px(c, x + w - 10, y + 4, 7, 5, C.phoneDevice);
354
+ px(c, x + 3, y + 5, 8, 5, C.paper);
355
+ }
356
+
357
+ function drawBoardroomSeat(c, seat, hot, occupied) {
358
+ const { deskX: x, deskY: y, deskW: w, deskH: h } = seat;
359
+ px(c, x - 1, y - 1, w + 2, h + 2, C.metalDark);
360
+ px(c, x, y, w, h, C.screen);
361
+ px(c, x + 2, y + 2, w - 4, 1, hot.has(`desk${seat.index}`) ? C.activeGreen : C.screenIdle);
362
+ px(c, x + 2, y + 5, Math.max(3, w - 7), 1, hot.has(`desk${seat.index}`) ? C.activeThink : C.screenIdle);
363
+ px(c, x + 2, y + h, w - 4, 2, C.metalDark);
364
+ const a = seat.anchor;
365
+ const chairSeat = { ...seat, deskY: a.y - 21 };
366
+ if (a.dir === "up" || a.dir === "down") {
367
+ drawChair(c, chairSeat, occupied);
368
+ } else {
369
+ const color = occupied ? C.chairDark : C.chair;
370
+ px(c, a.x - 4, a.y - 7, 8, 14, color);
371
+ px(c, a.x + (a.dir === "right" ? -6 : 4), a.y - 5, 2, 10, C.metalDark);
372
+ px(c, a.x - 1, a.y + 7, 2, 3, C.metalDark);
373
+ }
374
+ }
375
+
376
+ function drawArchive(c, item, hot, t) {
377
+ if (rich) px(c, item.x + 3, item.y + 4, item.w, item.h, C.objectShadow);
378
+ px(c, item.x, item.y, item.w, item.h, C.metal);
379
+ if (rich) outline(c, item.x - 1, item.y - 1, item.w + 2, item.h + 2);
380
+ px(c, item.x, item.y, item.w, 2, C.metalLite);
381
+ const open = hot.has("archive") ? ((t / 260) | 0) % 3 : -1;
382
+ for (let i = 0; i < 3; i++) {
383
+ const dy = item.y + 4 + i * 9;
384
+ px(c, item.x + 3, dy, item.w - 6, 7, C.metalDark);
385
+ px(c, item.x + 3, dy, item.w - 6, 1, C.drawerLite);
386
+ px(c, item.x + (item.w >> 1) - 5, dy + 3, 10, 1, C.drawerHandle);
387
+ if (i === open) {
388
+ px(c, item.x + 3, dy, item.w - 6, 7, C.drawerOpen);
389
+ px(c, item.x + 5, dy + 1, item.w - 10, 5, C.paper);
390
+ }
391
+ }
392
+ }
393
+
394
+ function drawServerRack(c, item, hot, t) {
395
+ if (rich) px(c, item.x + 3, item.y + 4, item.w, item.h, C.objectShadow);
396
+ px(c, item.x, item.y, item.w, item.h, C.rack);
397
+ if (rich) outline(c, item.x - 1, item.y - 1, item.w + 2, item.h + 2);
398
+ px(c, item.x, item.y, item.w, 2, C.rackTrim);
399
+ const fast = hot.has("server");
400
+ for (let i = 0; i < 3; i++) {
401
+ const dy = item.y + 5 + i * 9;
402
+ px(c, item.x + 3, dy, item.w - 6, 7, C.rackPanel);
403
+ px(c, item.x + 5, dy + 3, item.w - 24, 1, C.rackLine);
404
+ const on = Math.sin((fast ? t / 90 : t / 520) + i * 1.7) > 0;
405
+ px(c, item.x + item.w - 12, dy + 2, 2, 2, on ? C.signalOn : C.signalOff);
406
+ px(c, item.x + item.w - 8, dy + 2, 2, 2, on ? C.signalOff : C.signalOn);
407
+ }
408
+ }
409
+
410
+ function drawCoffee(c, item, hot, t) {
411
+ px(c, item.x, item.y, item.w, item.h, C.metalDark);
412
+ px(c, item.x, item.y, item.w, 2, C.metal);
413
+ px(c, item.x + 4, item.y + 5, item.w - 8, 8, C.coffeePanel);
414
+ px(c, item.x + 6, item.y + 7, 6, 4, hot.has("coffee") ? C.coffeeHot : C.coffeeIdle);
415
+ px(c, item.x + 5, item.y + item.h - 5, item.w - 10, 3, C.metal);
416
+ if (hot.has("coffee") && ((t / 240) | 0) % 2) px(c, item.x + 9, item.y - 3, 2, 3, C.steam);
417
+ }
418
+
419
+ function drawWaterCooler(c, item, hot, t) {
420
+ const active = hot.has("water");
421
+ px(c, item.x + 2, item.y, item.w - 4, 11, C.waterGlass);
422
+ px(c, item.x + 3, item.y + 2, item.w - 6, 6, active ? C.waterActive : C.waterLevel);
423
+ px(c, item.x + 1, item.y + 10, item.w - 2, item.h - 10, C.waterBody);
424
+ px(c, item.x + 1, item.y + item.h - 3, item.w - 2, 3, C.waterDark);
425
+ px(c, item.x + 4, item.y + 14, 3, 2, C.activeBlue);
426
+ px(c, item.x + item.w - 7, item.y + 14, 3, 2, C.activeRed);
427
+ px(c, item.x + 5, item.y + 18, item.w - 10, 4, C.waterDark);
428
+ if (active && ((t / 180) | 0) % 2) px(c, item.x - 2, item.y + 17, 2, 4, C.waterActive);
429
+ }
430
+
431
+ function drawPhoneTable(c, item, hot, t) {
432
+ px(c, item.x, item.y, item.w, item.h, C.wood);
433
+ px(c, item.x, item.y, item.w, 2, C.phoneTop);
434
+ px(c, item.x + 8, item.y - 7, 16, 8, C.phoneDevice);
435
+ px(c, item.x + 10, item.y - 5, 12, 3, hot.has("phone") ? C.signalOn : C.phoneIdle);
436
+ if (hot.has("phone") && ((t / 200) | 0) % 2) {
437
+ px(c, item.x + 4, item.y - 11, 2, 2, C.activeAccent);
438
+ px(c, item.x + 26, item.y - 11, 2, 2, C.activeAccent);
439
+ }
440
+ }
441
+
442
+ function drawMeetingTable(c, item) {
443
+ if (rich) px(c, item.x + 4, item.y + 5, item.w, item.h + 2, C.objectShadow);
444
+ px(c, item.x, item.y + item.h, item.w, 3, C.woodDark);
445
+ if (rich) outline(c, item.x - 1, item.y - 1, item.w + 2, item.h + 3);
446
+ px(c, item.x, item.y, item.w, item.h, C.deskTop);
447
+ px(c, item.x, item.y, item.w, 2, C.deskLite);
448
+ if (rich) {
449
+ px(c, item.x + 7, item.y + 5, item.w - 14, 1, C.woodGrain);
450
+ px(c, item.x + 3, item.y + item.h, 5, 7, C.woodDark);
451
+ px(c, item.x + item.w - 8, item.y + item.h, 5, 7, C.woodDark);
452
+ }
453
+ px(c, item.x + 8, item.y + 8, 12, 8, C.paper);
454
+ px(c, item.x + item.w - 24, item.y + 6, 10, 10, C.meetingPaper);
455
+ px(c, item.x + (item.w >> 1) - 4, item.y + 9, 8, 6, C.meetingDevice);
456
+ }
457
+
458
+ function drawLoungeSofa(c, item) {
459
+ px(c, item.x + 4, item.y + 5, item.w, item.h + 2, C.objectShadow);
460
+ px(c, item.x, item.y, item.w, item.h, C.outline);
461
+ px(c, item.x + 3, item.y + 3, item.w - 6, item.h - 6, C.chair);
462
+ px(c, item.x + 3, item.y + 3, item.w - 6, 7, C.chairDark);
463
+ px(c, item.x + 2, item.y + 4, 7, item.h - 8, C.chairDark);
464
+ px(c, item.x + item.w - 9, item.y + 4, 7, item.h - 8, C.chairDark);
465
+ const cushionWidth = Math.floor((item.w - 22) / 3);
466
+ for (let i = 0; i < 3; i++) {
467
+ const x = item.x + 10 + i * cushionWidth;
468
+ px(c, x, item.y + 11, cushionWidth - 2, item.h - 15, C.chairLite);
469
+ px(c, x, item.y + 11, cushionWidth - 2, 1, C.metalLite);
470
+ }
471
+ px(c, item.x + 8, item.y + item.h, 5, 3, C.chairDark);
472
+ px(c, item.x + item.w - 13, item.y + item.h, 5, 3, C.chairDark);
473
+ }
474
+
475
+ function drawDumbbell(c, item) {
476
+ const vertical = item.orientation === "vertical";
477
+ if (vertical) {
478
+ px(c, item.x + 5, item.y, 6, 3, C.outline);
479
+ px(c, item.x + 6, item.y + 1, 4, 2, C.metalLite);
480
+ px(c, item.x + 7, item.y + 3, 2, item.h + 3, C.metal);
481
+ px(c, item.x + 5, item.y + item.h + 4, 6, 3, C.outline);
482
+ px(c, item.x + 6, item.y + item.h + 4, 4, 2, C.metalLite);
483
+ return;
484
+ }
485
+ px(c, item.x, item.y + 1, 4, item.h - 2, C.outline);
486
+ px(c, item.x + 1, item.y + 2, 3, item.h - 4, C.metalLite);
487
+ px(c, item.x + 4, item.y + 3, item.w - 8, 2, C.metal);
488
+ px(c, item.x + item.w - 4, item.y + 1, 4, item.h - 2, C.outline);
489
+ px(c, item.x + item.w - 4, item.y + 2, 3, item.h - 4, C.metalLite);
490
+ }
491
+
492
+ function drawPlant(c, item) {
493
+ if (rich) px(c, item.x - 5, item.y + 4, 12, 5, C.objectShadow);
494
+ px(c, item.x - 4, item.y, 8, 7, C.pot);
495
+ px(c, item.x - 4, item.y, 8, 2, C.potLite);
496
+ px(c, item.x - 1, item.y - 5, 2, 5, C.plantDark);
497
+ px(c, item.x - 6, item.y - 11, 12, 7, C.plant);
498
+ px(c, item.x - 4, item.y - 14, 8, 4, C.plant);
499
+ px(c, item.x - 6, item.y - 11, 5, 3, C.plantDark);
500
+ if (rich) {
501
+ px(c, item.x - 7, item.y - 9, 4, 3, C.plantLite);
502
+ px(c, item.x + 2, item.y - 13, 5, 4, C.plantLite);
503
+ px(c, item.x - 1, item.y - 16, 3, 5, C.plantHighlight);
504
+ px(c, item.x - 3, item.y + 2, 6, 1, C.potLite);
505
+ }
506
+ }
507
+
508
+ let floorLayer = null;
509
+ function drawCachedFloor(c) {
510
+ if (!floorLayer) {
511
+ floorLayer = document.createElement("canvas");
512
+ floorLayer.width = W;
513
+ floorLayer.height = H;
514
+ const floorContext = floorLayer.getContext("2d", { alpha: false });
515
+ floorContext.imageSmoothingEnabled = false;
516
+ drawFloor(floorContext);
517
+ }
518
+ c.drawImage(floorLayer, 0, 0);
519
+ }
520
+
521
+ function drawCubicleCell(c, item) {
522
+ px(c, item.x, item.y, item.w, 5, C.metalDark);
523
+ px(c, item.x + 1, item.y, item.w - 2, 3, C.metal);
524
+ px(c, item.x, item.y, 5, item.h, C.metalDark);
525
+ px(c, item.x + 1, item.y + 1, 3, item.h - 2, C.metal);
526
+ px(c, item.x + item.w - 5, item.y, 5, item.h, C.metalDark);
527
+ px(c, item.x + item.w - 4, item.y + 1, 3, item.h - 2, C.metal);
528
+ }
529
+
530
+ function drawExecutiveDesk(c, item, hot) {
531
+ px(c, item.x, item.y + item.h, item.w, 5, C.woodDark);
532
+ px(c, item.x, item.y, item.w, item.h, C.deskTop);
533
+ px(c, item.x, item.y, item.w, 2, C.deskLite);
534
+ px(c, item.x + 20, item.y + 4, 26, item.h - 7, C.plantDark);
535
+ px(c, item.x + 4, item.y - 12, 17, 13, C.metalDark);
536
+ px(c, item.x + 5, item.y - 11, 15, 10, C.screen);
537
+ const active = hot.has(`desk${item.seatIndex ?? 0}`);
538
+ px(c, item.x + 7, item.y - 8, active ? 11 : 7, 1, active ? C.activeGreen : C.screenIdle);
539
+ px(c, item.x + item.w - 15, item.y + 4, 9, 5, C.phoneDevice);
540
+ px(c, item.x + item.w - 24, item.y - 9, 2, 11, C.activeAccent);
541
+ px(c, item.x + item.w - 29, item.y - 11, 12, 4, C.plantDark);
542
+ }
543
+
544
+ function drawCopyStation(c, item, hot, t) {
545
+ px(c, item.x, item.y + 12, item.w, item.h - 12, C.waterBody);
546
+ px(c, item.x + 2, item.y, item.w - 4, 14, C.metalDark);
547
+ px(c, item.x + 4, item.y + 2, item.w - 8, 8, C.screen);
548
+ px(c, item.x + item.w - 6, item.y + 17, 3, 2, hot.has("archive") && ((t / 240) | 0) % 2 ? C.signalOn : C.signalOff);
549
+ px(c, item.x + item.w - 2, item.y + 17, 7, 3, C.paper);
550
+ px(c, item.x + item.w - 2, item.y + 17, 1, 10, C.paperLine);
551
+ }
552
+
553
+ function drawReceptionDesk(c, item, hot) {
554
+ px(c, item.x, item.y, item.w, item.h, C.woodDark);
555
+ px(c, item.x + 2, item.y + 2, item.w - 4, item.h - 4, C.wood);
556
+ px(c, item.x, item.y, item.w, 3, C.deskLite);
557
+ px(c, item.x + 8, item.y - 12, 18, 13, C.metalDark);
558
+ px(c, item.x + 10, item.y - 10, 14, 9, C.screen);
559
+ px(c, item.x + 12, item.y - 7, hot.has("phone") ? 10 : 6, 1, hot.has("phone") ? C.signalOn : C.screenIdle);
560
+ px(c, item.x + item.w - 16, item.y - 6, 9, 7, C.phoneDevice);
561
+ }
562
+
563
+ function drawPresentationScreen(c, item, hot, t) {
564
+ px(c, item.x, item.y, item.w, item.h, C.metalDark);
565
+ px(c, item.x + 2, item.y + 2, item.w - 4, item.h - 4, C.screen);
566
+ px(c, item.x + 7, item.y + 8, item.w / 2 - 14, 3, C.paper);
567
+ for (let row = 0; row < 3; row++) {
568
+ const y = item.y + 17 + row * 6;
569
+ px(c, item.x + 7, y, 22, 2, [C.activeBlue, C.activeAccent, C.activeGreen][row]);
570
+ px(c, item.x + 33, y, item.w / 2 - 42, 2, C.rackLine);
571
+ const width = hot.has("whiteboard") ? 20 + (((t / 260) | 0) + row * 9) % 24 : 18 + row * 8;
572
+ px(c, item.x + 33, y, width, 2, [C.activeBlue, C.activeAccent, C.activeGreen][row]);
573
+ }
574
+ px(c, item.x + item.w - 47, item.y + 9, 38, 24, C.rackPanel);
575
+ for (let row = 0; row < 4; row++) {
576
+ px(c, item.x + item.w - 42, item.y + 13 + row * 5, 6, 2, row % 2 ? C.activeRed : C.activeGreen);
577
+ px(c, item.x + item.w - 32, item.y + 13 + row * 5, 18, 2, C.rackLine);
578
+ }
579
+ }
580
+
581
+ function drawBoardroomTable(c, item) {
582
+ const inset = Math.max(16, Math.round(item.w * 0.25));
583
+ const cx = item.x + (item.w >> 1);
584
+ px(c, cx - 6, item.y - 15, 12, 13, C.chairDark);
585
+ px(c, cx - 4, item.y - 13, 8, 9, C.chair);
586
+ px(c, cx - 8, item.y - 12, 2, 10, C.metalDark);
587
+ px(c, cx + 6, item.y - 12, 2, 10, C.metalDark);
588
+ if (rich) poly(c, [[item.x + inset + 4, item.y + 5], [item.x + item.w - inset + 4, item.y + 5], [item.x + item.w + 5, item.y + item.h + 5], [item.x + 5, item.y + item.h + 5]], C.objectShadow);
589
+ poly(c, [[item.x + inset, item.y], [item.x + item.w - inset, item.y], [item.x + item.w, item.y + item.h], [item.x, item.y + item.h]], C.woodDark);
590
+ poly(c, [[item.x + inset + 3, item.y], [item.x + item.w - inset - 3, item.y], [item.x + item.w - 7, item.y + item.h - 6], [item.x + 7, item.y + item.h - 6]], C.deskTop);
591
+ poly(c, [[item.x + inset + 7, item.y + 4], [item.x + item.w - inset - 7, item.y + 4], [item.x + item.w - 18, item.y + item.h - 13], [item.x + 18, item.y + item.h - 13]], C.deskLite);
592
+ poly(c, [[cx - 4, item.y + 10], [cx + 4, item.y + 10], [cx + 12, item.y + item.h - 20], [cx - 12, item.y + item.h - 20]], C.woodDark);
593
+ if (rich) {
594
+ for (let y = item.y + 18; y < item.y + item.h - 18; y += 20) {
595
+ px(c, item.x + 25, y, item.w - 50, 1, C.woodGrain);
596
+ }
597
+ for (const [x, y, flip] of [
598
+ [item.x + 43, item.y + 31, false],
599
+ [item.x + item.w - 55, item.y + 31, true],
600
+ [item.x + 27, item.y + 77, false],
601
+ [item.x + item.w - 39, item.y + 77, true],
602
+ ]) {
603
+ px(c, x, y, 11, 7, C.meetingPaper);
604
+ px(c, x + 2, y + 2, 7, 1, C.paperLine);
605
+ px(c, x + (flip ? -3 : 12), y + 1, 1, 6, C.activeBlue);
606
+ px(c, x + (flip ? 13 : -5), y + 1, 4, 4, C.waterGlass);
607
+ px(c, x + (flip ? 14 : -4), y + 2, 2, 1, C.waterLevel);
608
+ }
609
+ for (const y of [item.y + 22, item.y + 92]) {
610
+ px(c, cx - 15, y, 30, 3, C.woodDark);
611
+ px(c, cx - 11, y, 22, 1, C.activeAccent);
612
+ }
613
+ }
614
+ const deviceY = item.y + Math.round(item.h * 0.56);
615
+ px(c, cx - 11, deviceY, 22, 12, C.meetingDevice);
616
+ px(c, cx - 5, deviceY + 3, 10, 5, C.phoneDevice);
617
+ px(c, cx - 8, deviceY + 2, 2, 2, C.signalOn);
618
+ px(c, cx + 6, deviceY + 2, 2, 2, C.signalOff);
619
+ }
620
+
621
+ function drawAvConsole(c, item, hot, t) {
622
+ px(c, item.x, item.y, item.w, item.h, C.rack);
623
+ px(c, item.x, item.y, item.w, 2, C.rackTrim);
624
+ px(c, item.x + 6, item.y + 6, Math.floor(item.w * .42), 15, C.screen);
625
+ px(c, item.x + 9, item.y + 10, Math.floor(item.w * .32), 2, hot.has("server") ? C.activeGreen : C.screenIdle);
626
+ px(c, item.x + 9, item.y + 15, Math.floor(item.w * .23), 2, C.activeBlue);
627
+ for (let x = item.x + 7; x < item.x + item.w - 7; x += 8) {
628
+ px(c, x, item.y + item.h - 15, 4, 4, Math.sin(t / 190 + x) > 0 ? C.signalOn : C.signalOff);
629
+ }
630
+ px(c, item.x + 6, item.y + item.h - 7, item.w - 12, 4, C.metal);
631
+ }
632
+
633
+ function drawSideboard(c, item) {
634
+ px(c, item.x, item.y, item.w, item.h, C.wood);
635
+ px(c, item.x, item.y, item.w, 3, C.deskLite);
636
+ px(c, item.x, item.y + item.h - 3, item.w, 3, C.woodDark);
637
+ for (let x = item.x + 6; x < item.x + item.w - 6; x += 14) px(c, x, item.y - 4, 5, 5, C.paper);
638
+ }
639
+
640
+ function drawVendingMachine(c, item) {
641
+ px(c, item.x, item.y, item.w, item.h, C.activeRed);
642
+ px(c, item.x + 3, item.y + 3, item.w - 6, Math.max(8, item.h - 12), C.screen);
643
+ for (let y = item.y + 6; y < item.y + item.h - 8; y += 5) px(c, item.x + 5, y, item.w - 10, 2, y % 2 ? C.activeAccent : C.activeGreen);
644
+ px(c, item.x + 4, item.y + item.h - 6, item.w - 8, 3, C.phoneDevice);
645
+ }
646
+
647
+ function drawNoticeBoard(c, item) {
648
+ px(c, item.x - 2, item.y - 2, item.w + 4, item.h + 4, C.woodDark);
649
+ px(c, item.x, item.y, item.w, item.h, C.activeRed);
650
+ px(c, item.x + 3, item.y + 3, item.w - 6, 2, C.activeAccent);
651
+ for (let x = item.x + 5; x < item.x + item.w - 8; x += 14) {
652
+ px(c, x, item.y + 8, 10, 11, C.paper);
653
+ px(c, x + 2, item.y + 10, 6, 1, C.paperLine);
654
+ px(c, x + 2, item.y + 13, 5, 1, C.paperLine);
655
+ px(c, x + 2, item.y + 16, 7, 1, C.activeRed);
656
+ }
657
+ }
658
+
659
+ function drawWallCalendar(c, item) {
660
+ px(c, item.x - 1, item.y - 1, item.w + 2, item.h + 2, C.woodDark);
661
+ px(c, item.x, item.y, item.w, 5, C.activeRed);
662
+ px(c, item.x + 2, item.y + 2, item.w - 4, 1, C.activeAccent);
663
+ px(c, item.x, item.y + 5, item.w, item.h - 5, C.paper);
664
+ for (let y = item.y + 8; y < item.y + item.h - 2; y += 4) {
665
+ for (let x = item.x + 2; x < item.x + item.w - 2; x += 4) px(c, x, y, 2, 2, C.paperLine);
666
+ }
667
+ }
668
+
669
+ function drawCoatRack(c, item) {
670
+ const cx = item.x + (item.w >> 1);
671
+ px(c, cx - 1, item.y + 3, 3, item.h - 6, C.woodDark);
672
+ px(c, cx - 5, item.y + 5, 11, 2, C.woodDark);
673
+ px(c, item.x + 1, item.y + 4, 2, 6, C.woodDark);
674
+ px(c, item.x + item.w - 3, item.y + 4, 2, 6, C.woodDark);
675
+ px(c, item.x + 1, item.y + 9, 5, 14, C.chairDark);
676
+ px(c, item.x, item.y + 11, 3, 9, C.chair);
677
+ px(c, cx - 5, item.y + item.h - 3, 11, 3, C.woodDark);
678
+ }
679
+
680
+ function drawFloorFan(c, item, t) {
681
+ const cx = item.x + (item.w >> 1);
682
+ const cy = item.y + 8;
683
+ px(c, cx - 7, cy - 7, 15, 15, C.metalDark);
684
+ px(c, cx - 5, cy - 5, 11, 11, C.metalLite);
685
+ px(c, cx, cy, 1, 1, C.phoneDevice);
686
+ const flip = ((t / 260) | 0) % 2;
687
+ if (flip) {
688
+ px(c, cx - 4, cy - 1, 4, 2, C.chairDark);
689
+ px(c, cx + 1, cy, 4, 2, C.chairDark);
690
+ px(c, cx - 1, cy - 4, 2, 4, C.chairDark);
691
+ } else {
692
+ px(c, cx - 3, cy - 4, 3, 4, C.chairDark);
693
+ px(c, cx, cy + 1, 3, 4, C.chairDark);
694
+ px(c, cx - 4, cy + 1, 4, 2, C.chairDark);
695
+ }
696
+ px(c, cx, cy + 8, 2, item.h - 12, C.metalDark);
697
+ px(c, cx - 5, item.y + item.h - 4, 12, 4, C.metalDark);
698
+ }
699
+
700
+ function drawOfficeClock(c, item, officeTime) {
701
+ const { now } = officeTime;
702
+ px(c, item.x, item.y, item.w, item.h, C.outline ?? C.woodDark);
703
+ px(c, item.x + 2, item.y + 1, item.w - 4, item.h - 2, C.paper);
704
+ px(c, item.x + 1, item.y + 2, item.w - 2, item.h - 4, C.paper);
705
+ const cx = item.x + (item.w >> 1);
706
+ const cy = item.y + (item.h >> 1);
707
+ px(c, cx, item.y + 2, 1, 1, C.boardText);
708
+ px(c, cx, item.y + item.h - 3, 1, 1, C.boardText);
709
+ px(c, item.x + 2, cy, 1, 1, C.boardText);
710
+ px(c, item.x + item.w - 3, cy, 1, 1, C.boardText);
711
+ const minuteAngle = (now.getMinutes() / 60) * Math.PI * 2 - Math.PI / 2;
712
+ const hourAngle = (((now.getHours() % 12) + now.getMinutes() / 60) / 12) * Math.PI * 2 - Math.PI / 2;
713
+ pixelLine(c, cx, cy, cx + Math.round(Math.cos(hourAngle) * 3), cy + Math.round(Math.sin(hourAngle) * 3), C.phoneDevice);
714
+ pixelLine(c, cx, cy, cx + Math.round(Math.cos(minuteAngle) * 5), cy + Math.round(Math.sin(minuteAngle) * 5), C.activeRed);
715
+ px(c, cx, cy, 1, 1, C.outline ?? C.phoneDevice);
716
+ }
717
+
718
+ function drawRestroomDoor(c, item) {
719
+ px(c, item.x - 2, item.y - 2, item.w + 4, item.h + 4, C.outline);
720
+ px(c, item.x, item.y, item.w, item.h, C.door);
721
+ px(c, item.x + 3, item.y + 3, item.w - 6, item.h - 6, C.doorPanel);
722
+ px(c, item.x + item.w - 6, item.y + 16, 2, 3, C.paper);
723
+ const cx = item.x + (item.w >> 1);
724
+ px(c, cx - 2, item.y + 7, 5, 5, C.paper);
725
+ px(c, cx - 1, item.y + 12, 3, 7, C.paper);
726
+ px(c, cx - 4, item.y + 13, 3, 2, C.paper);
727
+ px(c, cx + 2, item.y + 13, 3, 2, C.paper);
728
+ px(c, cx - 3, item.y + 19, 2, 5, C.paper);
729
+ px(c, cx + 2, item.y + 19, 2, 5, C.paper);
730
+ }
731
+
732
+ function drawBossDesk(c, item) {
733
+ px(c, item.x + 3, item.y + 4, item.w, item.h + 3, C.objectShadow);
734
+ outline(c, item.x - 1, item.y - 1, item.w + 2, item.h + 3);
735
+ px(c, item.x, item.y, item.w, item.h, C.deskTop);
736
+ px(c, item.x, item.y, item.w, 2, C.deskLite);
737
+ px(c, item.x + 3, item.y + item.h, 4, 5, C.woodDark);
738
+ px(c, item.x + item.w - 7, item.y + item.h, 4, 5, C.woodDark);
739
+ px(c, item.x + 4, item.y - 11, 17, 12, C.outline);
740
+ px(c, item.x + 5, item.y - 10, 15, 9, C.screen);
741
+ px(c, item.x + 7, item.y - 7, 10, 1, C.activeGreen);
742
+ px(c, item.x + 7, item.y - 4, 7, 1, C.activeBlue);
743
+ px(c, item.x + 24, item.y + 4, 6, 6, C.mug);
744
+ px(c, item.x + 29, item.y + 5, 2, 3, C.mugLite);
745
+ }
746
+
747
+ function drawAutomaticLighting(c, officeTime) {
748
+ if (!officeTime.dynamicTime) return;
749
+ if (officeTime.phase === "night") px(c, 0, WALL_H, W, H - WALL_H, "rgba(8,13,29,0.16)");
750
+ if (!officeTime.lightingOn) return;
751
+ c.save();
752
+ c.globalCompositeOperation = "screen";
753
+ px(c, 0, WALL_H, W, H - WALL_H, officeTime.phase === "night" ? (C.roomLightNight ?? "rgba(255,210,112,0.13)") : (C.roomLightEvening ?? "rgba(255,220,150,0.07)"));
754
+ c.restore();
755
+ }
756
+
757
+ function drawAreaLabels(c) {
758
+ if (!AREAS.length) return;
759
+ c.save();
760
+ c.font = 'bold 7px ui-monospace, "PingFang SC", "Microsoft YaHei", sans-serif';
761
+ c.textAlign = "left";
762
+ c.textBaseline = "top";
763
+ for (const area of AREAS) {
764
+ const name = localize(area.name);
765
+ const width = Math.ceil(c.measureText(name).width) + 6;
766
+ px(c, area.x, area.y, width, 10, C.outline);
767
+ px(c, area.x + 1, area.y + 1, width - 2, 8, C.wallBase ?? C.woodDark);
768
+ px(c, area.x + 2, area.y + 2, 1, 6, C.activeAccent);
769
+ c.fillStyle = C.paper;
770
+ c.fillText(name, area.x + 4, area.y + 1);
771
+ }
772
+ c.restore();
773
+ }
774
+
775
+ function drawServiceCart(c, item) {
776
+ px(c, item.x, item.y, item.w, item.h, C.metal);
777
+ px(c, item.x, item.y, item.w, 2, C.metalLite);
778
+ for (let y = item.y + 5; y < item.y + item.h - 4; y += 7) {
779
+ px(c, item.x + 4, y, item.w - 8, 4, C.paper);
780
+ px(c, item.x + 7, y + 1, Math.floor(item.w * .4), 1, C.activeBlue);
781
+ }
782
+ px(c, item.x + 5, item.y + item.h, 4, 3, C.phoneDevice);
783
+ px(c, item.x + item.w - 9, item.y + item.h, 4, 3, C.phoneDevice);
784
+ }
785
+
786
+ function drawRoom(c, t, hot, occupiedSeats) {
787
+ const officeTime = currentEnvironment();
788
+ drawCachedFloor(c);
789
+ drawWall(c, t, officeTime);
790
+ for (const item of byRenderer("restroom-door")) drawRestroomDoor(c, item);
791
+ for (const item of byRenderer("whiteboard")) drawWhiteboard(c, item, hot, t);
792
+ for (const item of byRenderer("phone-table")) drawPhoneTable(c, item, hot, t);
793
+ for (const item of byRenderer("archive-cabinet")) drawArchive(c, item, hot, t);
794
+ for (const item of byRenderer("server-rack")) drawServerRack(c, item, hot, t);
795
+ for (const item of byRenderer("coffee-machine")) drawCoffee(c, item, hot, t);
796
+ for (const item of byRenderer("water-cooler")) drawWaterCooler(c, item, hot, t);
797
+ for (const item of byRenderer("meeting-table")) drawMeetingTable(c, item);
798
+ for (const item of byRenderer("lounge-sofa")) drawLoungeSofa(c, item);
799
+ for (const item of byRenderer("dumbbell")) drawDumbbell(c, item);
800
+ for (const item of byRenderer("plant")) drawPlant(c, item);
801
+ for (const item of byRenderer("cubicle-cell")) drawCubicleCell(c, item);
802
+ for (const item of byRenderer("executive-desk")) drawExecutiveDesk(c, item, hot);
803
+ for (const item of byRenderer("copy-station")) drawCopyStation(c, item, hot, t);
804
+ for (const item of byRenderer("reception-desk")) drawReceptionDesk(c, item, hot);
805
+ for (const item of byRenderer("presentation-screen")) drawPresentationScreen(c, item, hot, t);
806
+ for (const item of byRenderer("boardroom-table")) drawBoardroomTable(c, item);
807
+ for (const item of byRenderer("av-console")) drawAvConsole(c, item, hot, t);
808
+ for (const item of byRenderer("sideboard")) drawSideboard(c, item);
809
+ for (const item of byRenderer("vending-machine")) drawVendingMachine(c, item);
810
+ for (const item of byRenderer("notice-board")) drawNoticeBoard(c, item);
811
+ for (const item of byRenderer("wall-calendar")) drawWallCalendar(c, item);
812
+ for (const item of byRenderer("coat-rack")) drawCoatRack(c, item);
813
+ for (const item of byRenderer("floor-fan")) drawFloorFan(c, item, t);
814
+ for (const item of byRenderer("office-clock")) drawOfficeClock(c, item, officeTime);
815
+ for (const item of byRenderer("service-cart")) drawServiceCart(c, item);
816
+ for (const item of byRenderer("boss-desk")) drawBossDesk(c, item);
817
+ for (const seat of SEATS) {
818
+ if (seat.renderer === "cubicle-workstation") {
819
+ drawCubicleSeat(c, seat, hot);
820
+ drawChair(c, seat, occupiedSeats.has(seat.index));
821
+ } else if (seat.renderer === "boardroom-seat") {
822
+ drawBoardroomSeat(c, seat, hot, occupiedSeats.has(seat.index));
823
+ } else if (seat.renderer === "executive-seat") {
824
+ drawChair(c, seat, occupiedSeats.has(seat.index));
825
+ } else {
826
+ drawDesk(c, seat, hot);
827
+ drawChair(c, seat, occupiedSeats.has(seat.index));
828
+ }
829
+ }
830
+ drawAreaLabels(c);
831
+ drawSigns(c);
832
+ drawAutomaticLighting(c, officeTime);
833
+ }
834
+
835
+ return Object.freeze({
836
+ ...engine,
837
+ FURNITURE,
838
+ colors: C,
839
+ px,
840
+ drawRoom,
841
+ content,
842
+ });
843
+ }