Skip to content

Commit c0b56ca

Browse files
committed
support new VSA urls
1 parent 5dcbe3f commit c0b56ca

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

editor/base64.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const decode = s => Uint8Array.from(atob(s), c => c.charCodeAt(0));
2+
export const encode = b => btoa(String.fromCharCode(...new Uint8Array(b)));
3+
export const decodeToString = s => new TextDecoder().decode(decode(s));
4+
export const encodeString = s => encode(new TextEncoder().encode(s));

editor/compressor.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* global LZMA */
2+
3+
const compressor = new LZMA( 'js/lzma_worker.js' );
4+
export default compressor;

editor/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/* global LZMA */
21
/* global WavMaker */
32
import '../js/scrollbars.js';
43
import * as twgl from '../js/twgl-full.module.js';
5-
4+
import compressor from './compressor.js';
65
import { createElem as el } from './elem.js';
76

87
import ByteBeatNode from '../src/ByteBeatNode.js';
@@ -66,7 +65,6 @@ let visualTypeElem;
6665
let saveElem;
6766
let compileStatusElem;
6867
let canvas;
69-
let compressor;
7068
let controls;
7169
let doNotSetURL = true;
7270
const g_slow = false;
@@ -134,7 +132,6 @@ const setVisualizer = ndx => {
134132
};
135133

136134
async function main() {
137-
compressor = new LZMA( 'js/lzma_worker.js' );
138135
canvas = $('visualization');
139136
controls = $('controls');
140137

editor/visualizers/effects/VSAEffect.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
import * as twgl from '../../../js/twgl-full.module.js';
3+
import {
4+
decode,
5+
} from '../../base64.js';
6+
import compressor from '../../compressor.js';
37

48
const m4 = twgl.m4;
59

@@ -305,11 +309,19 @@ export default class VSAEffect {
305309
this.currentUrl = this.pendingUrl;
306310
this.pendingUrl = undefined;
307311
this.compiling = true;
308-
const mungedUrl = url.includes('vertexshaderart.com')
309-
? `${url}/art.json`
310-
: url;
311-
const req = await fetch(mungedUrl);
312-
const vsa = await req.json();
312+
let vsa;
313+
if (u.hash.includes('s=')) {
314+
const q = new URLSearchParams(u.hash.substring(1));
315+
const bytes = decode(q.get('s'));
316+
const text = await new Promise((resolve, reject) => compressor.decompress(bytes, resolve, () => {}, reject));
317+
vsa = JSON.parse(text);
318+
} else {
319+
const mungedUrl = url.includes('vertexshaderart.com')
320+
? `${url}/art.json`
321+
: url;
322+
const req = await fetch(mungedUrl);
323+
vsa = await req.json();
324+
}
313325
const gl = this.gl;
314326
const vs = applyTemplateToShader(vsa.settings.shader);
315327
const programInfo = await twgl.createProgramInfoAsync(gl, [vs, s_fs]);

0 commit comments

Comments
 (0)