define(["sugar-web/graphics/palette","sugar-web/env","webL10n","sugar-web/datastore","sugar-web/activity/activity"], function (palette,env,l10n,datastore,activity) { var canvas = document.getElementById("canvas"); var ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight-55; var windowWidth = canvas.getBoundingClientRect().width; var windowHeight = canvas.getBoundingClientRect().height; var shiftY = 45; var radiusEye = Math.min(windowWidth,windowHeight)/6.5; var radiusEyeball = Math.min(windowWidth,windowHeight)/28; var eyePos = [{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]; var mouthStart = {x:windowWidth*1.35/4,y:shiftY+windowHeight*2/3.0}; var mouthEnd = {x:windowWidth*2.65/4,y:shiftY+windowHeight*2/3.0}; var noOfEyes = 2; var colors; var awake = true; var idletimer; activity.getXOColor(function (error, retcolors) { colors = retcolors; }); function idleTimer() { awake = true; clearInterval(idletimer); idletimer = setInterval(function () { awake = false; var language = document.getElementById('speaklang').innerHTML; var text = l10n.get("Sleepy"); speech.playVoice(language, text); clearInterval(idletimer); },60000*2) } $(window).resize(function() { canvas.width = window.innerWidth; canvas.height = window.innerHeight-55; windowWidth = canvas.getBoundingClientRect().width; windowHeight = canvas.getBoundingClientRect().height; mouthStart = {x:windowWidth*1.35/4,y:shiftY+windowHeight*2/3.0}; mouthEnd = {x:windowWidth*2.65/4,y:shiftY+windowHeight*2/3.0}; radiusEye = Math.min(windowWidth,windowHeight)/6.5; radiusEyeball = Math.min(windowWidth,windowHeight)/28; setEyes(); }) canvas.addEventListener('mousemove', function(evt) { setMousePosition(canvas, evt); }, false); // Detect if the browser is IE or not var IE = document.all?true:false var mouseX = -1,mouseY = -1; var mouthYdiff = 0.0; var mouthDirection = 1; var mouthTimeout; var speech = null; var sugarSettings = {}; var first = true; function init(){ speech = Speech(); env.getEnvironment(function(err, environment) { var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language; if (!environment.user) environment.user = { language: defaultLanguage }; sugarSettings = environment.user; speech.init(sugarSettings); // If not IE, setup mouse for capture if (!IE){ document.captureEvents(Event.MOUSEMOVE) } var FPS = 30; setInterval(function() { updateCanvas(); }, 1000/FPS); window.addEventListener('localized', function() { if (first) { l10n.language.code = sugarSettings.language; first = false; return; } else { localize(); var timer = window.setTimeout(function() { window.clearTimeout(timer); var language = document.getElementById('speaklang').innerHTML; var text = l10n.get("TypeSomething", {name:sugarSettings.name}); document.getElementById("combo-box").title = l10n.get("SavedTalk"); // Localized Saved talk title. document.getElementsByClassName("dropdown").title = l10n.get("SavedTalk"); // Localized Saved talk title. speech.playVoice(language, text); moveMouth(text); }, 100); } }); }); idleTimer(); } function hidePalettes(){ var palettes = document.getElementsByClassName('palette'); for(var i=0;i40){ mouthDirection = 1; } } } function startMouthAnim(){ var speed = document.getElementById('rate').innerHTML; var interval = 0.01; document.getElementById('speaking').innerHTML = 1; mouthTimeout = setInterval(function(){ animateMouth(speed); },interval*1000); } function moveMouth(text){ if(text != ""){ if(document.getElementById('mode').innerHTML=="2"){ setTimeout(function(){ startMouthAnim(); }, 4000); } else{ startMouthAnim(); } } } function drawMouth(){ ctx.beginPath(); ctx.moveTo(mouthStart.x,mouthStart.y); ctx.bezierCurveTo(mouthStart.x+100,mouthStart.y+mouthYdiff,mouthEnd.x-100,mouthEnd.y+mouthYdiff,mouthEnd.x,mouthEnd.y); ctx.lineWidth = 10; ctx.stroke(); ctx.closePath(); ctx.beginPath(); ctx.moveTo(mouthStart.x,mouthStart.y); ctx.bezierCurveTo(mouthStart.x+100,mouthStart.y-mouthYdiff,mouthEnd.x-100,mouthEnd.y-mouthYdiff,mouthEnd.x,mouthEnd.y); ctx.lineWidth = 10; ctx.stroke(); ctx.closePath(); } function updateCanvas(){ clearCanvas(); noOfEyes = parseInt(document.getElementById('numeyes').innerHTML); setEyes(noOfEyes); drawEyes(); drawEyeballs(); drawMouth(); } function clearCanvas(){ ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.beginPath(); ctx.rect(0, 0, canvas.width, canvas.height); ctx.fillStyle = colors["fill"]; ctx.fill(); } function localize() { document.getElementById('gamemode1-button').title = l10n.get("TypeSomethingToHear"); document.getElementById('gamemode2-button').title = l10n.get("AskRobot"); document.getElementById('gamemode3-button').title = l10n.get("VoiceChat"); document.getElementById('language-button').title = l10n.get("Language"); document.getElementById('speech-button').title = l10n.get("Speech"); document.getElementById('face-button').title = l10n.get("Face"); document.getElementById('ratelabel').innerHTML = l10n.get("ratelabel"); document.getElementById('pitchlabel').innerHTML = l10n.get("pitchlabel"); document.getElementById('eyesnumber').innerHTML = l10n.get("eyesnumber"); document.getElementById('eyes').title = l10n.get("eyes"); document.getElementById('glasses').title = l10n.get("glasses"); document.getElementById('speakText').title = l10n.get("speak"); document.getElementById('lang-en').innerHTML = l10n.get('langen'); document.getElementById('lang-ca').innerHTML = l10n.get('langca'); document.getElementById('lang-cs').innerHTML = l10n.get('langcs'); document.getElementById('lang-de').innerHTML = l10n.get('langde'); document.getElementById('lang-el').innerHTML = l10n.get('langel'); document.getElementById('lang-eo').innerHTML = l10n.get('langeo'); document.getElementById('lang-es').innerHTML = l10n.get('langes'); document.getElementById('lang-fi').innerHTML = l10n.get('langfi'); document.getElementById('lang-fr').innerHTML = l10n.get('langfr'); document.getElementById('lang-hu').innerHTML = l10n.get('langhu'); document.getElementById('lang-it').innerHTML = l10n.get('langit'); document.getElementById('lang-kn').innerHTML = l10n.get('langkn'); document.getElementById('lang-la').innerHTML = l10n.get('langla'); document.getElementById('lang-lv').innerHTML = l10n.get('langlv'); document.getElementById('lang-nl').innerHTML = l10n.get('langnl'); document.getElementById('lang-pl').innerHTML = l10n.get('langpl'); document.getElementById('lang-pt').innerHTML = l10n.get('langpt'); document.getElementById('lang-ro').innerHTML = l10n.get('langro'); document.getElementById('lang-sk').innerHTML = l10n.get('langsk'); document.getElementById('lang-sv').innerHTML = l10n.get('langsv'); document.getElementById('lang-tr').innerHTML = l10n.get('langtr'); document.getElementById('lang-zh').innerHTML = l10n.get('langzh'); } init(); });