/* babblebot Copyright (C) 2008 Alex McLean This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ import js.Dom; class JsClient { static var cnx = null; static function main() { var ctx = new haxe.remoting.Context(); ctx.addObject("JsClient",JsClient); cnx = haxe.remoting.ExternalConnection.flashConnect("default","Synth",ctx); } static function play(dur) { cnx.Synth.play.call([dur]); } static function playSentence(s) { cnx.Synth.playSentence.call([s]); } static function setDelaySz(sz) { cnx.Synth.setDelaySz.call([sz]); } static function playingWord(n, words) { var element = untyped js.Lib.document.getElementById('current'); words[n] = '' + words[n] + ''; haxe.Timer.delay(function() {element.innerHTML = words.join(' ');}, 250 ); } static function send() { var element = untyped js.Lib.document.getElementById('privacy'); if (!element.checked) { var element = untyped js.Lib.document.getElementById('sentence'); var s = element.value; var http = new haxe.Http("www/index.php"); http.setHeader("Content-Type","text/plain; charset=ISO-8859-1"); http.setParameter("s",s); // send as GET http.request(false); } } static function makeSyllable() { var consonants = 'bcdfghjklmnpqrstvwxyz'; var vowels = 'aeiou'; var result = pickChar(consonants); while(Math.random() > 0.6) { result += pickChar(consonants); } result += pickChar(vowels); while(Math.random() > 0.75) { result += pickChar(vowels); } return(result); } static function makeWord() { var result = makeSyllable(); while(Math.random() > 0.6) { result += makeSyllable(); } return(result); } static function makeSentence() { var words = 1 + randInt(9); var result = []; for (i in 0 ... words) { result.push(makeWord()); while(Math.random() > 0.6) { result.push('-'); } } return(result.join(' ')); } static function generate() { var s = makeSentence(); var element = untyped js.Lib.document.getElementById('sentence'); element.value = s; playSentence(s); } static function pickChar(s) { return(s.charAt(randInt(s.length))); } static function randInt(max) { return(Math.floor(Math.random() * max)); } }