mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-02 08:28:18 +00:00
URL state
This commit is contained in:
1 parent
66b746f4d2
commit
cd3bb6a3f2
4 files changed
+40
-9
No files matched your search
@@ -1,13 +1,25 @@
|
||||
#!/bin/bash
|
||||
# Upload everything to the server.
|
||||
|
||||
# Sound Library
|
||||
pushd ~/Dropbox/jungle.horse
|
||||
rsync -utrv sounds bt@jungle.horse:/home/bt/dev/trumpet
|
||||
popd
|
||||
|
||||
# Config and Dictionaries
|
||||
rsync -utrv dictionary bt@jungle.horse:/home/bt/dev/trumpet
|
||||
rsync -utrv config.toml bt@jungle.horse:/home/bt/dev/trumpet
|
||||
|
||||
# Frontend
|
||||
rsync -utrv web/*css bt@jungle.horse:/home/bt/dev/trumpet/web
|
||||
rsync -utrv web/*html bt@jungle.horse:/home/bt/dev/trumpet/web
|
||||
pushd frontend
|
||||
webpack
|
||||
popd
|
||||
gulp
|
||||
rsync -utrv web/output bt@jungle.horse:/home/bt/dev/trumpet/web/output
|
||||
|
||||
# Server
|
||||
cargo build --release
|
||||
rsync -utrv target/release/trumpet bt@jungle.horse:/home/bt/dev/trumpet
|
||||
rsync -utrv target/release/trumpet bt@jungle.horse:/home/bt/dev/trumpet
|
||||
|
||||
@@ -5,7 +5,9 @@ These words need improvement
|
||||
"^^ obama's
|
||||
"^^^ again (BAD)
|
||||
"^^^ by (BAD)
|
||||
"^^^ ha, haha, hahaha"
|
||||
"^^^ how (THIS IS SO BAD)
|
||||
"^^^ rigging
|
||||
"^^^ then (BAD)
|
||||
"do you?"
|
||||
"for you"
|
||||
|
||||
+23
-5
@@ -3,15 +3,14 @@
|
||||
declare var $: any;
|
||||
|
||||
import Audio from "./audio";
|
||||
import decode_url_hash from "./url";
|
||||
import get_audio_api_url from "./url";
|
||||
import set_url_hash from "./url";
|
||||
import { decode_url_hash, get_audio_api_url, set_url_hash } from "./url";
|
||||
import { RawSentence, FilteredSentence } from "./sentence";
|
||||
|
||||
$(function() {
|
||||
console.log('installing...');
|
||||
window.audio = new Audio();
|
||||
install_events();
|
||||
initialize_from_url();
|
||||
});
|
||||
|
||||
function install_events() {
|
||||
@@ -20,15 +19,24 @@ function install_events() {
|
||||
sentence = new RawSentence(input),
|
||||
filtered = sentence.filter();
|
||||
|
||||
let url = get_audio_api_url(filtered);
|
||||
set_url_hash(filtered);
|
||||
|
||||
let url = get_audio_api_url(filtered);
|
||||
window.audio.playUrl(url);
|
||||
|
||||
console.log(ev);
|
||||
ev.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
$('body').on('keyup', function(ev: any): any {
|
||||
if (ev.keyCode === 27) {
|
||||
// ESC key.
|
||||
$('input#jungle').select();
|
||||
$('input#jungle').val('');
|
||||
window.audio.stop();
|
||||
}
|
||||
});
|
||||
|
||||
$('input#jungle').on('keyup', function(ev: any): any {
|
||||
var sentence = $('input#jungle').val();
|
||||
|
||||
@@ -52,3 +60,13 @@ function install_events() {
|
||||
});
|
||||
}
|
||||
|
||||
function initialize_from_url() {
|
||||
let rawSentence = decode_url_hash();
|
||||
|
||||
if (rawSentence == null) return;
|
||||
|
||||
$('input#jungle')
|
||||
.val(rawSentence.filter().value)
|
||||
.submit();
|
||||
}
|
||||
|
||||
+2
-3
@@ -7,7 +7,7 @@ declare var URI: any; // TODO: Remove dependency.
|
||||
/**
|
||||
* Sentence -> Audio generation API URL
|
||||
*/
|
||||
export default function get_audio_api_url(sentence: FilteredSentence) : string {
|
||||
export function get_audio_api_url(sentence: FilteredSentence) : string {
|
||||
// I may expand the API later, but for now this is all I'll expose.
|
||||
let encoded = encodeURIComponent(sentence.value);
|
||||
return `/speak?v=trump&vol=3&s=${encoded}`;
|
||||
@@ -28,7 +28,6 @@ export function set_url_hash(sentence: FilteredSentence) {
|
||||
urlHash = new URI('/').hash(uriEncoded).toString();
|
||||
}
|
||||
|
||||
console.log('set state, urlhash = ', urlHash);
|
||||
window.history.replaceState(null, null, urlHash);
|
||||
}
|
||||
|
||||
@@ -48,7 +47,7 @@ export function decode_url_hash(): RawSentence {
|
||||
if (!state || !('s' in state)) {
|
||||
return null;
|
||||
} else {
|
||||
new RawSentence(state['s']);
|
||||
return new RawSentence(state['s']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user