Skip to content

Commit

Permalink
improvements: strings won't glitch, poop indicator is orange, autosav…
Browse files Browse the repository at this point in the history
…es are every 8 mutations
  • Loading branch information
delanni committed Jul 23, 2024
1 parent de2bbe3 commit 4ab39c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
21 changes: 12 additions & 9 deletions amakit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ class Amakit {
constructor() {
this.table = "hydralisk-drafts";
this.AWS = window.AWS;
this.AWS.config.update({ region: 'eu-west-1' });
this.docClient = new this.AWS.DynamoDB.DocumentClient({
apiVersion: '2012-08-10',
region: 'eu-west-1'
});
if (this.AWS) {
this.AWS.config.update({ region: 'eu-west-1' });
this.docClient = new this.AWS.DynamoDB.DocumentClient({
apiVersion: '2012-08-10',
region: 'eu-west-1'
});
}
}

loadDrafts = () => {
return this.getAllDrafts().then((drafts) => {
loadDrafts = async () => {
try {
const drafts = await this.getAllDrafts();
this.draftCache = drafts;
return drafts;
}).catch((err) => {
} catch (err) {
console.error("Error loading drafts: ", err);
});
}
}

getCredentials = () => {
Expand Down
45 changes: 27 additions & 18 deletions bundle.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -47149,7 +47149,7 @@
const memory = {
saveSlot: null,
autoSaves: [],
_autosaveCulling: 10,
_autosaveCulling: 8,
_autosaveIndex: 0,

quickSave: (code) => {
Expand Down Expand Up @@ -47292,7 +47292,7 @@
- 4: turn on at 1/4x speed
- 8: turn on at 1/8x speed
*/
let automutateInterval = null
state.automutateInterval = null;
emitter.on('editor:toggleAutomutate', (evt, e) => {
// Turn off
const guessedMsPerBeat = (60000/(bpm||120));
Expand All @@ -47303,17 +47303,17 @@

let mutateTimeout = guessedMsPerBeat;
if (automutateMode === 'X' || !automutateMode) {
if (automutateInterval) {
clearInterval(automutateInterval);
automutateInterval = null;
return;
if (state.automutateInterval) {
clearInterval(state.automutateInterval);
state.automutateInterval = null;
return emitter.emit('render');
} else {
mutateTimeout = Number(prompt("How fast would you like to go? (in milliseconds)", guessedMsPerBeat)) || guessedMsPerBeat;
}
} else if (automutateMode === '0') {
clearInterval(automutateInterval);
automutateInterval = null;
return;
clearInterval(state.automutateInterval);
state.automutateInterval = null;
return emitter.emit('render');
} else if (automutateMode === '1') {
mutateTimeout = guessedMsPerBeat;
} else if (automutateMode === '2') {
Expand All @@ -47325,19 +47325,20 @@
} else if (automutateMode === '5') {
mutateTimeout = guessedMsPerBeat * 16;
} else {
return;
return emitter.emit('render')
}

const editor = state.editor.editor
const changeTransformChance = 1 - (evt.metaKey ? 0.25 : 0);
clearInterval(automutateInterval);
automutateInterval = setInterval(() => {
clearInterval(state.automutateInterval);
state.automutateInterval = setInterval(() => {
const changeTransform = Math.random() > changeTransformChance;
editor.mutator.mutate({ reroll: false, changeTransform });
editor.formatCode();
memory.autoSave(editor.getValue());
}, mutateTimeout);
memory.autoSave(editor.getValue(), true);
return emitter.emit('render');
});

// TODO: these could be replaced by codemirror combos
Expand Down Expand Up @@ -47541,10 +47542,12 @@
}
}

repl.eval(editor.getValue())
const code = editor.getValue();
repl.eval(code)
document.title = sketch.name;
sketches.saveLocally(editor.getValue());
sketches.saveLocally(code);
memory.resetAutosaves();
memory.autoSave(code, true);
})

// TODO: Copy
Expand Down Expand Up @@ -48364,6 +48367,10 @@
let traveler = makeTraveler({
go: function(node, state) {
if (node.type === 'Literal') {
// we don't want strings to be glitched
if (typeof node.value === 'string')
return;

state.literalTab.push(node);
} else if (node.type === 'MemberExpression') {
if (node.property && node.property.type === 'Literal') {
Expand Down Expand Up @@ -48398,8 +48405,9 @@
if (options.changeTransform) {
this.glitchTrans(state, options);
}
else this.glitchLiteral(state, options);

else {
this.glitchLiteral(state, options);
}
}

glitchLiteral(state, options)
Expand Down Expand Up @@ -48437,7 +48445,8 @@
glitchRelToInit(num, initVal) {
if (initVal === undefined) {
return glitchNumber(num);
} if (initVal === 0) {
}
if (initVal === 0) {
initVal = 0.5;
}

Expand Down Expand Up @@ -49836,7 +49845,7 @@
${icon("myimport", `fa-file-import ${hidden}`, "Import", 'gallery:import')}
${icon("myexport", `fa-file-export ${hidden}`, "Export", 'gallery:export')}
${icon("mutator", `fa-dice ${hidden}`, t('toolbar.random'), 'editor:randomize')}
${icon("automutate", `fa-poo ${hidden}`, "toggle automutate", 'editor:toggleAutomutate')}
${icon("automutate", `fa-poo ${hidden}`, "toggle automutate", 'editor:toggleAutomutate', state.automutateInterval ? 'color: orange' : 'color: white' )}
${icon("mylogin", `fa-key ${hidden}`, "Log in", 'remote:login', isAuthenticated ? 'color: lime' : 'color: white')}
${toggleInfo}
</div>`
Expand Down

0 comments on commit 4ab39c4

Please sign in to comment.