summaryrefslogtreecommitdiff
path: root/2026/index.html
blob: 9327020f071da41777ffa59b007928641af81328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <script type="module" src="./games.js"></script>
    <title>Jam Framing Test</title>
    <style>
      body {
          overflow: hidden;
          margin: 0px;
          width: 100vw;
          height: 100vh;
          background-color: darkgrey;
      }
      .jam-hidden {
          visibility: hidden;
      }
      #jam-titlescreen {
          position: fixed;
          top: 0px;
          bottom: 0px;
          right: 0px;
          left: 0px;
          color: white;
          background-color: black;
          z-index: 2;
      }
      #jam-iframe-parent {
          display: grid;
          grid-template-columns: 100%;
          grid-template-rows: 100%;
          justify-items: center;
          align-items: center;
          width: 100%;
          height: 100%;
          margin: 0px;
      }
      #jam-iframe-parent iframe {
          grid-area: 1 / 1 / 2 / 2;
          transform-origin: center;
          transform: scale(1);
          padding: 0px;
          border: 0px;
      }
      #jam-framing-iframe {
          z-index: 1;
          pointer-events: none;
      }
    </style>
  </head>
  <body>
    <div id="jam-titlescreen">
      click to continue
    </div>
    <div id="jam-iframe-parent">
      <iframe id="jam-framing-iframe" width="480" height="320" src="./framing/dist/index.html"></iframe>
    </div>
    <script type="module">
      let microgames = window.MICROGAMES.map(g => ({url: g, loaded: null, ready: false}));
      let framing = document.getElementById("jam-framing-iframe");
      let microgame_index = 0;
      let waiting_to_start = null;
      let iframe_parent = document.getElementById("jam-iframe-parent");
      let iframes =[ ...Array(5).keys()].map(i => {
          let elem = document.createElement("iframe")
          elem.id = `jam-game-iframe-${i}`;
          elem.classList.add("jam-hidden");
          elem.width = 240;
          elem.height = 160;
          elem.src = "about:blank";
          iframe_parent.appendChild(elem);
          return elem;
      });
      function resizeView() {
          let least_ratio = Math.min(Math.floor(window.innerWidth / 480), Math.floor(window.innerHeight / 320));
          let factor = Math.max(1, least_ratio);
          for (let i of iframes) {
              i.style["transform"] = `scale(${factor})`;
          }
          framing.style["transform"] = `scale(${factor})`;
      }

      function loadGame(i) {
          if (!microgames[i].loaded) {
              console.log(`loading: ${i}`)
              for (let iframe of iframes) {
                  if (iframe.src == "about:blank") {
                      iframe.src = microgames[i].url;
                      console.log(`setting src ${iframe.src}`); 
                      microgames[i].loaded = iframe;
                      return;
                  }
              }
          }
      }
      function unloadGame(i) {
          if (microgames[i] && microgames[i].loaded) {
              console.log(`unloading: ${i}`)
              microgames[i].loaded.src = "about:blank";
              microgames[i].loaded = null;
              microgames[i].ready = false;
          }
      }
      function loadUpcomingGames() {
          let first = true;
          let to_load = Math.min(5, microgames.length);
          for (let i = (microgame_index + to_load) % microgames.length; i != microgame_index; i = (i + 1) % microgames.length) {
              unloadGame(i)
          }
          for (let off = 0; off < to_load; ++off) {
              let i = (microgame_index + off) % microgames.length;
              loadGame(i)
          }
      }

      function startGame(idx) {
          console.log(`actually starting game: ${idx}`);
          waiting_to_start = null;
          const resp = {op: "start", difficulty: 1.0};
          microgames[idx].loaded.contentWindow.postMessage(resp);
          microgames[idx].loaded.contentWindow.lcolonqJamStart = resp.difficulty;
          microgames[idx].loaded.classList.remove("jam-hidden");
      }
      function startNextGameIfReady() {
          loadUpcomingGames();
          for (let i of iframes) { i.classList.add("jam-hidden"); }
          microgame_index += 1;
          microgame_index %= microgames.length;
          console.log(`attempting to start next game: ${microgame_index}`);
          if (microgames[microgame_index].ready) {
              startGame(microgame_index);
          } else {
              console.log(`delaying start until game is ready!`);
              waiting_to_start = microgame_index;
          }
      }

      resizeView();
      window.addEventListener("resize", resizeView);
      for (let i of iframes) {
          i.addEventListener("load", () => {
              i.contentDocument.body.style["overflow"] = "hidden";
              i.contentDocument.body.style["image-rendering"] = "pixelated";
          });
      }

      window.addEventListener("message", ev => {
          console.log(`received message: ${ev.data.op} (from ${ev.source.location.href})`);
          switch (ev.data.op) {
          case "ready":
              for (let mi = 0; mi < microgames.length; ++mi) {
                  let mg = microgames[mi];
                  if (mg.loaded && ev.source.location.href === mg.loaded.src) {
                      mg.ready = true;
                      if (waiting_to_start === mi) {
                          console.log(`delayed game is ready, starting...`);
                          startGame(mi);
                      }
                  }
              }
              break;
          case "started":
              framing.contentWindow.postMessage({op: "startgame"});
              microgames[microgame_index].loaded.contentWindow.focus();
              break;
          case "done":
              framing.contentWindow.postMessage({op: "endgame", win: ev.data.win});
              startNextGameIfReady();
              break;
          default: console.log(`unknown event: ${ev}`); break;
          }
      });

      let titlescreen = document.getElementById("jam-titlescreen");
      titlescreen.addEventListener("click", () => {
          titlescreen.classList.add("jam-hidden");
          startNextGameIfReady();
      });
    </script>
  </body>
</html>