LordXido commited on
Commit
39b38b8
·
verified ·
1 Parent(s): 8bee28f

Update main.js

Browse files
Files changed (1) hide show
  1. main.js +118 -35
main.js CHANGED
@@ -1,56 +1,139 @@
1
- import { updateWorld } from "./world.js";
2
- import { updateAgents, spawnAgent } from "./agents.js";
3
- import { loadURL, scrapeDOM } from "./web.js";
 
 
 
 
 
4
  import { llmIntent } from "./llm.js";
5
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  const log = document.getElementById("log");
7
  const input = document.getElementById("input");
8
 
9
- export let Psi = 0.5;
10
- export let sigma = 0.5;
 
 
11
 
12
- function print(m){ log.innerHTML += m+"<br/>"; log.scrollTop=log.scrollHeight; }
 
 
 
13
 
14
- function parseIntent(text){
15
- if(text.startsWith("open")) return {type:"web", url:text.split(" ").pop()};
16
- if(text.includes("spawn")) return {type:"agent"};
17
- if(text.includes("brighter")) return {type:"inject", v:1.5};
18
- return {type:"llm", text};
19
- }
 
 
 
20
 
21
- async function route(intent){
22
- if(intent.type==="web"){
23
- loadURL(intent.url);
24
- print("Web opened: "+intent.url);
25
  }
26
- if(intent.type==="agent"){
27
- spawnAgent();
28
- print("Agent spawned");
 
 
 
 
29
  }
30
- if(intent.type==="inject"){
31
- Psi = intent.v;
32
- print("Ψ updated");
33
  }
34
- if(intent.type==="llm"){
35
- const cmd = await llmIntent(intent.text);
36
- route(cmd);
 
 
 
 
37
  }
 
 
38
  }
39
 
40
- input.addEventListener("keydown", e=>{
41
- if(e.key==="Enter"){
42
- const t=input.value;
43
- print("> "+t);
44
- route(parseIntent(t));
45
- input.value="";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  }
47
  });
48
 
49
- function loop(){
50
- updateWorld(Psi, sigma);
51
- updateAgents();
 
 
 
 
 
52
  requestAnimationFrame(loop);
53
  }
54
 
55
- print("CodexReality3D v9+ ONLINE");
56
  loop();
 
1
+ // ===============================
2
+ // CodexReality3D v9-HA MAIN ENGINE
3
+ // ===============================
4
+
5
+ // ---- Imports ----
6
+ import { initWorld, updateWorld, renderWorld } from "./world.js";
7
+ import { spawnAgent, updateAgents } from "./agents.js";
8
+ import { loadURL } from "./web.js";
9
  import { llmIntent } from "./llm.js";
10
 
11
+ // ---- Canvas ----
12
+ const canvas = document.getElementById("viewport");
13
+ const ctx = canvas.getContext("2d");
14
+
15
+ function resize() {
16
+ canvas.width = canvas.clientWidth;
17
+ canvas.height = canvas.clientHeight;
18
+ }
19
+ window.addEventListener("resize", resize);
20
+ resize();
21
+
22
+ // ---- Console ----
23
  const log = document.getElementById("log");
24
  const input = document.getElementById("input");
25
 
26
+ function print(msg) {
27
+ log.innerHTML += msg + "<br/>";
28
+ log.scrollTop = log.scrollHeight;
29
+ }
30
 
31
+ // ---- Core Parameters ----
32
+ let Psi = 0.5; // Intent injection
33
+ let sigma = 0.25; // Diffusion / superposition
34
+ let running = true;
35
 
36
+ // ---- World Init ----
37
+ initWorld();
38
+ print("CodexReality3D v9-HA ONLINE");
39
+ print("World initialized");
40
+ print("Type `help` or natural language");
41
+
42
+ // ---- Intent Parsing ----
43
+ function parseIntent(text) {
44
+ const t = text.toLowerCase();
45
 
46
+ if (t.startsWith("open") || t.startsWith("browse")) {
47
+ return { type: "web", url: text.split(" ").pop() };
 
 
48
  }
49
+
50
+ if (t.includes("spawn")) {
51
+ return { type: "agent" };
52
+ }
53
+
54
+ if (t.includes("brighter")) {
55
+ return { type: "inject", value: Psi + 0.2 };
56
  }
57
+
58
+ if (t.includes("pause")) {
59
+ return { type: "pause" };
60
  }
61
+
62
+ if (t.includes("resume")) {
63
+ return { type: "resume" };
64
+ }
65
+
66
+ if (t === "help") {
67
+ return { type: "help" };
68
  }
69
+
70
+ return { type: "llm", text };
71
  }
72
 
73
+ // ---- Command Router ----
74
+ async function route(intent) {
75
+ switch (intent.type) {
76
+
77
+ case "web":
78
+ print("Opening web → " + intent.url);
79
+ loadURL(intent.url);
80
+ break;
81
+
82
+ case "agent":
83
+ spawnAgent();
84
+ print("Agent spawned");
85
+ break;
86
+
87
+ case "inject":
88
+ Psi = intent.value;
89
+ print("Ψ updated → " + Psi.toFixed(2));
90
+ break;
91
+
92
+ case "pause":
93
+ running = false;
94
+ print("Simulation paused");
95
+ break;
96
+
97
+ case "resume":
98
+ running = true;
99
+ print("Simulation resumed");
100
+ break;
101
+
102
+ case "help":
103
+ print("Commands:");
104
+ print(" open <url>");
105
+ print(" spawn agent");
106
+ print(" make it brighter");
107
+ print(" pause / resume");
108
+ break;
109
+
110
+ case "llm":
111
+ const cmd = await llmIntent(intent.text);
112
+ route(cmd);
113
+ break;
114
+ }
115
+ }
116
+
117
+ // ---- Input Handling ----
118
+ input.addEventListener("keydown", e => {
119
+ if (e.key === "Enter") {
120
+ const text = input.value.trim();
121
+ if (!text) return;
122
+ print("> " + text);
123
+ route(parseIntent(text));
124
+ input.value = "";
125
  }
126
  });
127
 
128
+ // ---- Main Loop ----
129
+ function loop() {
130
+ if (running) {
131
+ updateWorld(Psi, sigma);
132
+ updateAgents();
133
+ }
134
+
135
+ renderWorld(ctx, canvas);
136
  requestAnimationFrame(loop);
137
  }
138
 
 
139
  loop();