Browse Source

sketch.js works in dev mode and in seni.indy.io

Inderjit Gill 1 month ago
parent
commit
9579d3307f
3 changed files with 24 additions and 22 deletions
  1. 1
    1
      client/www/css/indyio.css
  2. 6
    2
      client/www/sketch.html
  3. 17
    19
      client/www/sketch.js

+ 1
- 1
client/www/css/indyio.css View File

@@ -2964,7 +2964,7 @@ figure.highlight,
2964 2964
     position: absolute;
2965 2965
     top: 0;
2966 2966
     left: 0;
2967
-  }
2967
+}
2968 2968
 
2969 2969
   .sketch-content-wrap {
2970 2970
     display: block;

+ 6
- 2
client/www/sketch.html View File

@@ -45,7 +45,9 @@
45 45
             </div>
46 46
 
47 47
           </div>
48
-            <div class="seni-content markdown" itemprop="articleBody">
48
+
49
+
50
+          <div class="seni-content markdown" itemprop="articleBody">
49 51
               <div id="sketch-content" class="sketch-content-wrap">
50 52
                 <div class="sketch-holder">
51 53
 
@@ -62,10 +64,12 @@
62 64
                   </div>
63 65
 
64 66
                   <div id="seni-sketch-controls">
65
-                    <input id="sketch-load-id" type="number" value="62">
66 67
                     <button id="sketch-eval-variation" class="navbar-button eval-btn seni-button">Generate variation</button>
67 68
                     <button id="sketch-eval-original" class="navbar-button eval-btn seni-button" disabled>Show Original</button>
68 69
                     <button id="sketch-eval-slideshow" class="navbar-button eval-btn seni-button">Slideshow</button>
70
+                    <!--
71
+                    <button id="sketch-eval-download" class="navbar-button eval-btn seni-button">Download Image...</button>
72
+                     -->
69 73
                     <input id="sketch-seed" style="display: none;" type="number" value="3">
70 74
                   </div> <!-- seni-sketch-controls -->
71 75
 

+ 17
- 19
client/www/sketch.js View File

@@ -332,10 +332,10 @@ function handleTextureLoaded(gl, image, texture) {
332 332
   gl.bindTexture(gl.TEXTURE_2D, texture);
333 333
 }
334 334
 
335
-function createRenderTexture(gl, config) {
335
+function createRenderTexture(gl) {
336 336
   // create to render to
337
-  const targetTextureWidth = config.render_texture_width;
338
-  const targetTextureHeight = config.render_texture_height;
337
+  const targetTextureWidth = gState.render_texture_width;
338
+  const targetTextureHeight = gState.render_texture_height;
339 339
 
340 340
   const targetTexture = gl.createTexture();
341 341
   gl.bindTexture(gl.TEXTURE_2D, targetTexture);
@@ -389,11 +389,6 @@ function checkFramebufferStatus(gl) {
389 389
   }
390 390
 }
391 391
 
392
-const gConfig = {
393
-  render_texture_width: 1024,
394
-  render_texture_height: 1024,
395
-};
396
-
397 392
 class GLRenderer {
398 393
   constructor(canvasElement) {
399 394
     this.glDomElement = canvasElement;
@@ -414,7 +409,7 @@ class GLRenderer {
414 409
     this.mvMatrix = Matrix.create();
415 410
     this.pMatrix = Matrix.create();
416 411
 
417
-    this.renderTexture = createRenderTexture(gl, gConfig);
412
+    this.renderTexture = createRenderTexture(gl);
418 413
     this.framebuffer = createFrameBuffer(gl, this.renderTexture);
419 414
 
420 415
     // render to the canvas
@@ -806,7 +801,8 @@ const jobSimplifyScript = 'SIMPLIFY_SCRIPT';
806 801
 
807 802
 // --------------------------------------------------------------------------------
808 803
 
809
-const PAGE = "sketch.html";
804
+const RUNNING_ON_STATIC_SITE = false;
805
+const PAGE = RUNNING_ON_STATIC_SITE ? "index.html" : "sketch.html";
810 806
 
811 807
 const URI_SEED = "seed";
812 808
 const URI_MODE = "mode";
@@ -928,7 +924,9 @@ function normalize_bitmap_url(url) {
928 924
   // todo: this should:
929 925
   // 1. do nothing if the url is a valid url
930 926
   // 2. if it's just a filename, prefix the img/ path (specific to seni web app)
931
-  return "img/" + url;
927
+
928
+  // note: setting an absolute path as this works with static site generation for seni.indy.io
929
+  return "/img/" + url;
932 930
 }
933 931
 
934 932
 async function renderJob(parameters) {
@@ -1031,7 +1029,7 @@ async function performSlideshow() {
1031 1029
     seedElement.value = parseInt(newSeed, 10);
1032 1030
     gState.seed = getSeedValue(seedElement);
1033 1031
 
1034
-    updateURIFromGlobals();
1032
+    updateURIFromGlobals(false);
1035 1033
     await updateSketch(DISPLAY_FADE);
1036 1034
     gState.timeoutId = window.setTimeout(performSlideshow, gState.slideshowDelay);
1037 1035
   }
@@ -1201,7 +1199,7 @@ function updateGlobalsFromURI() {
1201 1199
   }
1202 1200
 }
1203 1201
 
1204
-function updateURIFromGlobals() {
1202
+function updateURIFromGlobals(updateHistory) {
1205 1203
   let params = [];
1206 1204
   if (gState.mode != MODE_NORMAL) {
1207 1205
     params.push("mode=" + gState.mode);
@@ -1215,7 +1213,7 @@ function updateURIFromGlobals() {
1215 1213
     search = "?" + params.join("&");
1216 1214
   }
1217 1215
 
1218
-  if (window.location.search !== search) {
1216
+  if (updateHistory && window.location.search !== search) {
1219 1217
     // desired uri is different from current one
1220 1218
     const page_uri = PAGE + search;
1221 1219
     history.pushState({}, null, page_uri);
@@ -1279,7 +1277,7 @@ async function main() {
1279 1277
     gState.seed = undefined;
1280 1278
     updateToMode(MODE_NORMAL);
1281 1279
 
1282
-    updateURIFromGlobals();
1280
+    updateURIFromGlobals(true);
1283 1281
 
1284 1282
     await updateSketch(DISPLAY_FADE);
1285 1283
   });
@@ -1295,7 +1293,7 @@ async function main() {
1295 1293
       // only call updateSketch if we're actually switching to SLIDESHOW mode as this will create a settimeout
1296 1294
       gState.timeoutId = window.setTimeout(performSlideshow, 0);
1297 1295
     }
1298
-    updateURIFromGlobals();
1296
+    updateURIFromGlobals(true);
1299 1297
 
1300 1298
   });
1301 1299
 
@@ -1309,7 +1307,7 @@ async function main() {
1309 1307
 
1310 1308
     updateToMode(MODE_NORMAL);
1311 1309
 
1312
-    updateURIFromGlobals();
1310
+    updateURIFromGlobals(true);
1313 1311
 
1314 1312
     await updateSketch(DISPLAY_FADE);
1315 1313
   });
@@ -1322,7 +1320,7 @@ async function main() {
1322 1320
   canvasImageElement1.addEventListener('click', async () => {
1323 1321
     updateToMode(MODE_NORMAL);
1324 1322
 
1325
-    updateURIFromGlobals();
1323
+    updateURIFromGlobals(true);
1326 1324
 
1327 1325
     await updateSketch(DISPLAY_SNAP);
1328 1326
   });
@@ -1333,7 +1331,7 @@ async function main() {
1333 1331
 
1334 1332
       updateToMode(MODE_NORMAL);
1335 1333
 
1336
-      updateURIFromGlobals();
1334
+      updateURIFromGlobals(true);
1337 1335
 
1338 1336
       await updateSketch(DISPLAY_SNAP);
1339 1337
 

Loading…
Cancel
Save