(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o=0) { this.listeners.splice(i,1); } } this.callHandlers=function(event,params) { for(var i=0;i ":""; if(typeof source=="object" && typeof source._logName=="string") {prepend+=source._logName;} prepend+=": "; if(!this._keep) {console.log(prepend+text);} else {this._buffer.push({action:this.message, text:text, source:source});} } }, warning:function(text, source) { if(this.verbose==this.ALL||this.verbose==this.WARNINGS_ERRORS) { var prepend=(typeof this._prepend!="undefined")?this._prepend+"> ":""; if(typeof source=="object" && typeof source._logName=="string") {prepend+=source._logName;} prepend+=": "; if(!this._keep) {console.warn(prepend+text);} else {this._buffer.push({action:this.warning, text:text, source:source});} } }, error:function(text, source) { if(this.verbose==this.ALL||this.verbose==this.ERRORS) { var prepend=(typeof this._prepend!="undefined")?this._prepend+"> ":""; if(typeof source=="object" && typeof source._logName=="string") {prepend+=source._logName;} prepend+=": "; if(!this._keep) {console.error(prepend+text);} else {this._buffer.push({action:this.error, text:text, source:source});} } }, keep:function(keep) { if(keep!=true) { keep=false; this.clearBuffer(); } this._keep = keep; }, clearBuffer:function() { this._buffer = []; }, flush:function() { for(var i=0;imaxId) { maxId = this.timeline[i]._id; } } return maxId; } //returns the duration of the story this.getDuration = function() { return this.timeline[this.timeline.length-1].time; } /** Searches all subtitles and fills the languages array with all the available languages **/ this._findLanguages = function() { this.languages = new Array(); for(var ei=0;ei=this._totalAssets) { //Story loaded! this.log.message("Story loaded!", thisobj); this._status=thisobj.STATUS_LOADED; this.onload(); } } /** This function is called repeatedly while the assets are loading to propagete the current progress **/ this.onprogress=function(assetsLoaded, totalAssets) {} /** This function is called when the requested story finishes loading and is ready for use **/ this.onload=function() {} /** This function returns true if the story is completely loaded **/ this.isLoaded = function() { if(this._status==this.STATUS_LOADED) {return true;} else {return false;} } this.addActor = function(actor) { var newActor = new MovableObject().initWithActor(actor, function() {}, this._baseURL); this.actors.push(newActor); } /** This function removes an 'Actor' from the story **/ this.removeActor = function(name) { //Remove from the actors list for(var i=0; i0) { return url.substr(0, lastSlashIndex+1); } else { return ""; } } this.addBaseToURL = function(url, baseURL) { var protocolRegex = /[a-zA-Z0-9]+:\/\//g; // Absolute paths if(url[0]=="/" || protocolRegex.exec(url)!=null) { return url; } // Relative paths else { if(baseURL==null) { return url; } else { // Remove any files from the path return this.getPathFromURL(baseURL)+url; } } } } //////////// MovableObject //////////// function MovableObject() { this._origin = null; this.name = null; this.url = null; this.image = null; this.startX = 0; this.startY = 0; this.startZ = 1; this.x; this.y; this.z; this.motion = {type:"ellipse",freq:0.1,x:0,y:0}; this.sprite = null; this.initWithZ = function(name,z) { this.name = name; this.startZ = z; this.resetPosition(); return this; } this.initWithActor = function(actor, loadHandler, assetsPath) { this._origin = actor; this.name = actor.name; this.url = actor.url; this.startX = actor.x; this.startY = actor.y; this.startZ = actor.z; this.resetPosition(); if(typeof actor.motion!="undefined") {this.motion = actor.motion;} if(typeof actor.sprite!="undefined") {this.sprite = actor.sprite;} this.image=new Image(); this.image.onload=function(){loadHandler();} if(typeof assetsPath=="undefined" || assetsPath==null) {assetsPath="";} this.image.src=assetsPath+actor.url; //add the motion object if(typeof actor.motion=="undefined") { this.resetMotion(); } else { this.motion = actor.motion; } return this; } this.changeImage = function(newImage, assetsPath) { if(typeof assetsPath=="undefined") {assetsPath="";} this.url = newImage; this.image.src = assetsPath+this.url; } this.resetMotion = function() { this.motion = {"type":null,"freq":0,"x":0,"y":0,"r":0}; } this.resetPosition = function() { this.x = this.startX; this.y = this.startY; this.z = this.startZ; } } },{"./mod-audiotrack.js":1,"./mod-log.js":3}],7:[function(require,module,exports){ //////////// Actions //////////// var actions={}; //teleport actions.teleport = { init:function(player,actor){ actor.x = actor.action.params.x; actor.y = actor.action.params.y; actor.z = actor.action.params.z; }, act:function(t,actor,params) { actor.action = null; } } //fade in actions.fadein = { init:function(player,actor){ actor.action.params.context=player.context; actor.action.params.width=player.story.width; actor.action.params.height=player.story.height; actor.action.params.a=-1/(actor.action.params.tt-player.time); actor.action.params.b=-actor.action.params.a*actor.action.params.tt; actor.action.params.st=player.time; actor.action.params.freq=1/(2*(actor.action.params.tt-player.time)); }, act:function(t,actor,params){ color=(1+Math.cos(drama.constants.PI360*(t-params.st)*params.freq))/2; params.context.fillStyle="rgba(0,0,0,"+color+")"; params.context.fillRect(0,0,params.width,params.height); if(t>=actor.action.params.tt) {actor.action=null;} } } //fade out actions.fadeout = { init:actions.fadein.init, act:function(t,actor,params){ color=(1+Math.cos(drama.constants.PI360*(t-params.st)*params.freq+drama.constants.PI180))/2; params.context.fillStyle="rgba(0,0,0,"+color+")"; params.context.fillRect(0,0,params.width,params.height); if(t>=actor.action.params.tt) {actor.action=null;} } } //fill canvas with color actions.fill = { init:function(player,actor){ actor.action.params.context=player.context; actor.action.params.width=player.story.width; actor.action.params.height=player.story.height; }, act:function(t,actor,params){ params.context.fillStyle=params.color; params.context.fillRect(0,0,params.width,params.height); if(t>=actor.action.params.tt) {actor.action=null;} } } //linear movement actions.movelin = { init:function(player,actor){ actor.action.params.ax=(actor.action.params.tx-actor.x)/(actor.action.params.tt-player.time); actor.action.params.ay=(actor.action.params.ty-actor.y)/(actor.action.params.tt-player.time); actor.action.params.bx=actor.x-actor.action.params.ax*player.time; actor.action.params.by=actor.y-actor.action.params.ay*player.time; }, act:function(t,actor,params){ actor.x=actor.action.params.ax*t+actor.action.params.bx; actor.y=actor.action.params.ay*t+actor.action.params.by; if(t>=actor.action.params.tt) { actor.x=params.tx; actor.y=params.ty; actor.action=null; } } } //sinusoid movement actions.movesin = { init:function(player,actor){ actor.action.params.st=player.time; actor.action.params.freq=1/(2*(actor.action.params.tt-player.time)); actor.action.params.sy=actor.y; actor.action.params.dy=actor.y-actor.action.params.ty; actor.action.params.sx=actor.x; actor.action.params.dx=actor.x-actor.action.params.tx; }, act:function(t,actor,params){ actor.x=params.sx-params.dx*(1-Math.cos(drama.constants.PI360*(t-params.st)*params.freq))/2; actor.y=params.sy-params.dy*(1-Math.cos(drama.constants.PI360*(t-params.st)*params.freq))/2; if(t>=actor.action.params.tt) { actor.x=params.tx; actor.y=params.ty; actor.action=null; } } } module.exports=actions; },{}],8:[function(require,module,exports){ module.exports={ PI360:2*Math.PI, PI180:Math.PI, PI90:Math.PI/2 }; },{}],9:[function(require,module,exports){ var VolumeControl=require("./dp-volumecontrol.js"); //PlayerControls module.exports = function(player) { //prototypes this.LanguageSelector = require("./dp-languageselector.js"); this.player=player; this.showTime=0; //when the controls showed up this.showDuration=1000; //how much time the controls stay visible (ms) this.visible=true; this.muted=false; this.volumeBeforeMute=0; var thisobj=this; //assets var imgPlay = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlCAYAAADFniADAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAADPSURBVFiF3ddJDsIwEETRAnEvcjQ4GeFkxaqSSJns2D2IL/XGi9ZbukFyJDmQRJYB59Lglqg0uC1UOO4IFYYrQbnjalBuuCsoc1wLygx3R3tPAB8AI4Chw74uKNUN1xOlmnEWKHUZZ4lS1TgPlCrGeaLUKS4CpXZxkSi1wt1IMhC01fsRLVj0BfACMGZATRg9RKJWGBWB2sUoT9QpRnmgijHKElWNURaoyxjVE9WMmcr4R/+baybV3WeOqUG5YUpQ7pgjVBhmCxWOWaLSYDQ/Y5CQxtZTdJkAAAAASUVORK5CYII="; var imgPause = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAlCAYAAAC+uuLPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA/SURBVFiF7c2xDQAgEMNAwxSw/3CwRdgAfUGF7DZSriUJtSawL/sAVuWoF8GniYqKioqKioqKioqKioqKfo8eMekGRuKWtU8AAAAASUVORK5CYII="; var imgStop = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAACISURBVEiJ7dY7DoAwDANQl5OVm3E0OJmZkECE0o9DFix16dA3xWkiSdyTjLuRZAALaAeik0mu50c9sAvihZmIGisiKqwKGcWakF6sC2nFhpBaTIK8YVLkSCLNunLJ9BX0Y+7YDGCTa4WR+GzOQhokpBtDWj9kn4Vs6iZUjRVRL8xEn1aMy494BwOtRMWypfpyAAAAAElFTkSuQmCC"; var imgFullscreen = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAhCAYAAACr8emlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAKESURBVFiFzdjri01RGMfxz3EdzJwhXihRxAt5hZQyOJH79e/wT/CeN/4NEVLKTHJCIiWUlESRSxqZq9tge7HW6eyOPTN7zzlb86vVs56193n296y19rPWXpUkSUTNx1qsxwp0Y8k0JeseGG8pYxltWfcM4iVeYwIqSZL0R6g1mGt26Dfe4GUlSXVhTo1jGCMpm65DFb3Rpuu9mr2cS/NS9c94FsnT5V18+DBG479rR3PRE2F7sUoYvXTZhOUgaepMkiRmSTnTgJrTZm+Urv8JWMVhnMXDWJ9W86a/Zcbqxk7UYtmqmSX+4F6eIGUBnsepKeI/wVCeQGUN8Wk8nuJ6PW+gsgCHsN/kkPW8gcp8SX4ISb1Vf3Anb5CyABfhGnZEfzR17Sm+5A1UBmADbk/0b2CjsEpRYHjpPGAXrmJv9AdwUlgu9+C5goCdTDMLcQX7on8TJ/A9+p8EyG9FgnYKcCEu40D06zieAfOxaOCiQ9yNZS1tC3AJh6J/G0fxtShMlooC7hbm1dIU3EUcif7dWM9KLzNSUcCasKb2C58FF3AsXrsnbADGOgVH8TlYi3YbXmgO931hiEczftOWivRgFZtTfgPuEQ5qbvc7qiKAfbI/qn7iV2dw/lURwNok7dtxHYvbpslQJwBhF861h5KtvC9JD7a0tL0QEnKjfOgUVFp5AfuEr/06bkX7vgygVuUFHMCGMkEmU945WNpbOp3SRx/vhJzWOFF4G+1HIceNau5M2lWXMK+rWCmcJqzWPFnYIpw4KHo2MxFBR6aw4oN7prDz8z6wkiTJA6wT1tbZpEG8qqQ6sCqANmCXCMk3bbPaWq8RtlqNc7+vk9istkG8imUE/gLhyCouJy5X6QAAAABJRU5ErkJggg=="; var imgSoundOn = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAeCAYAAADKO/UvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAACYSURBVEiJ7ZWxDcIwFAXPyBIdBQ2ZgVHYgD0YAFbIBJmEMlOwBAOgowGEImEltkXlJ/3K+td8615QKUgEetTc2apXCwB79eYrOYCDevcrSwEn9eEkc5fX6jBdXgLZqeMvgGoEzokTdsAR2KTuHLTsowCsSgEN0iANkp8IXBLvs1RQRUp/02M1UVetjGrl9Z5PjQbLPB2B/gnl1KjffFx79AAAAABJRU5ErkJggg=="; var imgSoundOff = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAcCAYAAACQ0cTtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAFbSURBVEiJ7Za9SgNBFIXPJvYRBNGwBMHWSvAF/AFfwNJ38BVsrSRIihQpUij2lpIXEBQRRSKC9iIIWn8Wu4PXdf93GiEHLuzOnJlvd6a4R4AaVAAcAr0CXwdQE9A8cEGklRxfH5gCYV3QGvDEj9JgATAwnkkd0B7wyW8lYQEwNPPPQK8KpA0ckS4LawEjMzcFQirc2QJwmQGysDYwNuOPQNftUwa0DrzkgBysDZyasXtgye4l4KBgozJaBc7N+x2wmPzwOfnRiaTd+PlW0rakt6Sp5QnmQNeSNtNAPmGSdCVpS9J7lsHXMd5I2pH0kWfy9Wf7RSCfsK8yJp93NoPNYP8MdiwpiGtZ0oOZP5O0IenVC820gC5Rs3Maxz2qSvPMLfcQErVvpxFRe68TC3JhPaJA4jQkCixNAk8mbGIWDQpAVaJcKswdYb/MAlNlQ+qfO+tUBLkqG78F6BuExuTwOsjTqwAAAABJRU5ErkJggg=="; //create elements this.container = document.createElement("div"); this.container.style.cssText = "position:absolute;bottom:0;width:100%;text-align:center;"; this.controlsPanel = document.createElement("div"); this.controlsPanel.style.cssText = "display:inline-block;background-color:rgba(0,0,0,0.3);margin-bottom:2.5%;padding:5px 20px;border-radius:15px;"+ "-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;"; this.container.appendChild(this.controlsPanel); this.mainControlsElem = document.createElement("div"); this.languageSelector = new this.LanguageSelector(); this.languageSelector.onselect = function(langIndex) { thisobj.player.setLanguage(langIndex); thisobj.controlsPanel.innerHTML=""; thisobj.controlsPanel.appendChild(thisobj.mainControlsElem); } this.player.eventsManager.addListener("ready",function() { if(thisobj.player.story.languages.length!=0) { thisobj.languageSelector.setLanguages(thisobj.player.story.languages); thisobj.languageIndicator.innerHTML = thisobj.player.story.languages[thisobj.player.getLanguage()]; } else { thisobj.languageIndicator.innerHTML = ""; } }); this.controlsPanel.appendChild(this.mainControlsElem); //this.controlsElement.style.cssText="display:inline-block;background-color:rgba(200,200,200,.2);margin-bottom:3%;padding:5px 20px;border-radius:15px;"+ // "-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;"; var controlsCss = "display:inline-block;width:40px;height:40px;margin:0 1px;cursor:pointer;"; //play this.playButton=document.createElement("div"); this.playButton.style.cssText=controlsCss+"background:url("+imgPlay+") no-repeat center;"; this.playButton.onclick=function() { if(thisobj.player.started==0) { thisobj.player.play(); thisobj.playButton.style.backgroundImage="url("+imgPause+")"; } else { thisobj.player.pause(); thisobj.playButton.style.backgroundImage="url("+imgPlay+")"; } } //stop this.stopButton=document.createElement("div"); this.stopButton.style.cssText = controlsCss+"background:url("+imgStop+") no-repeat center;"; this.stopButton.onclick = function() { thisobj.player.stop(); thisobj.playButton.style.backgroundImage="url("+imgPlay+")"; } //fullscreen this.fullscreenButton = document.createElement("div"); this.fullscreenButton.style.cssText = controlsCss+"background:url("+imgFullscreen+") no-repeat center;"; this.fullscreenButton.onclick = function() {thisobj.player.toggleFullscreen();} //mute this.muteButton=document.createElement("div"); this.muteButton.style.cssText = controlsCss+"background:url("+imgSoundOn+") no-repeat center;"; this.muteButton.onclick = function() { if(thisobj.muted) { thisobj.muted=false; thisobj.muteButton.style.backgroundImage="url("+imgSoundOn+")"; thisobj.player.setVolume(thisobj.volumeBeforeMute); } else { thisobj.muted=true; thisobj.muteButton.style.backgroundImage="url("+imgSoundOff+")"; thisobj.volumeBeforeMute = thisobj.volumeControl.value; thisobj.player.setVolume(0); } } //volume this.volumeControl=new VolumeControl(0); this.volumeControl.container.style.display="inline-block"; this.volumeControl.onvaluechange=function(value) { if(thisobj.muted) { thisobj.muted = false; thisobj.muteButton.style.backgroundImage="url("+imgSoundOn+")"; } thisobj.player.setVolume(value, false); } this.player.eventsManager.addListener("volumechange",function(volume) { if(volume!=0 && thisobj.muted==true) { thisobj.muted=false; thisobj.muteButton.style.backgroundImage="url("+imgSoundOn+")"; } thisobj.volumeControl.setValue(volume); }); //time indicator this.timeIndicator = document.createElement("span"); this.timeIndicator.style.cssText = "color:#ccc;vertical-align:top;font-family:Sans-serif;font-size:28px;margin:0 15px;line-height:40px;"; this.timeIndicator.innerHTML = "00:00"; //language indicator this.languageIndicator = document.createElement("span"); this.languageIndicator.style.cssText = "color:#fff;vertical-align:top;font-family:Sans-serif;font-size:28px;margin:0 15px;line-height:40px;cursor:pointer;"; this.languageIndicator.onclick = function() { thisobj.controlsPanel.innerHTML=""; thisobj.controlsPanel.appendChild(thisobj.languageSelector.container); } this.player.eventsManager.addListener("languagechange", function(langIndex){ thisobj.languageIndicator.innerHTML = thisobj.player.story.languages[langIndex]; }); //this.languageIndicator.innerHTML = "en"; //append controls this.mainControlsElem.appendChild(this.stopButton); this.mainControlsElem.appendChild(this.playButton); this.mainControlsElem.appendChild(this.timeIndicator); this.mainControlsElem.appendChild(this.muteButton); this.mainControlsElem.appendChild(this.volumeControl.container); this.mainControlsElem.appendChild(this.languageIndicator); this.mainControlsElem.appendChild(this.fullscreenButton); this.setTime=function() { var time=(thisobj.player.time/1000)|0; var seconds=time%60; var minutes=(time/60|0)%60; if(seconds<10) {seconds="0"+seconds;} if(minutes<10) {minutes="0"+minutes;} thisobj.timeIndicator.innerHTML=minutes+":"+seconds; } this.onmousemove=function() { thisobj.showTime=thisobj.player.time; if(!thisobj.visible) { thisobj.container.style.display="block"; thisobj.player.playerElement.style.cursor="auto"; thisobj.visible=true; } } this.refresh=function() { thisobj.setTime(); if(thisobj.visible&&thisobj.player.time-thisobj.showTime>thisobj.showDuration) { thisobj.container.style.display="none"; thisobj.player.playerElement.style.cursor="none"; thisobj.visible=false; //if not already return to the main controls thisobj.controlsPanel.innerHTML=""; thisobj.controlsPanel.appendChild(thisobj.mainControlsElem); } if(thisobj.player.started==0) { thisobj.playButton.style.backgroundImage="url("+imgPlay+")"; } else { thisobj.playButton.style.backgroundImage="url("+imgPause+")"; } } setInterval(this.refresh,1000); } },{"./dp-languageselector.js":12,"./dp-volumecontrol.js":16}],10:[function(require,module,exports){ module.exports = function() { var thisobj = this; this.items = new Array(); this.add = function(actor) { //find new actor's position in queue var i=0; while((i=this.items[i].z)) {i++;} //add the actor to the queue this.items.splice(i,0,actor); } this.remove = function(actor) { //find and remove the requested actor from the queue for(var i=0;i
"; this.fpsbox=document.createElement("div"); this.fpsbox.style.cssText="float:right;font-size:110%;"; this.timebox=document.createElement("div"); this.timebox.style.cssText="border-top:1px dotted white;"; this.messagepanel=document.createElement("div"); this.messagepanel.style.cssText="font-family:Courier,monospace;margin-top:10px;border-top:1px dotted white;"; this.container.appendChild(this.fpsbox); this.container.appendChild(this.timebox); this.container.appendChild(this.messagepanel); var thisobj=this; this.setFPS=function(fps){ //set the fps label thisobj.fpsbox.innerHTML=fps+"fps"; } this.setTime=function(msec){ //set the time label thisobj.timebox.innerHTML="time: "+Math.floor(msec/100)/10+"sec"; } this.msg_queue=new Array(); this.msg_max=22; //maximum number of messages in the queue this.print=function(txt){ //add a message in the debug console thisobj.msg_queue.push(txt); if(thisobj.msg_queue.length>this.msg_max){thisobj.msg_queue.splice(0,1);} var txt_queue=""; for(var i=0;i";} this.messagepanel.innerHTML=txt_queue; } this.refresh=function(){ var fps = thisobj.player.framesCounter - thisobj._previousTotalFrames; thisobj.setFPS(fps); thisobj.setTime(thisobj.player.time); thisobj._previousTotalFrames = thisobj.player.framesCounter; } setInterval(this.refresh,1000); this.setFPS(0); this.setTime(0); return this; } },{}],12:[function(require,module,exports){ module.exports = function() { var thisobj = this; //styles this._itemCss = "color:#fff;vertical-align:top;font-family:Sans-serif;font-size:28px;margin:0 15px;line-height:40px;cursor:pointer;"; //elements this.container = document.createElement("div"); this.onselect = null; this.setLanguages = function(languages) { //clear the container this.container.innerHTML = ""; //add the available languages for(var i=0;iactor.motion.frames) {actor.motion.current=0;} } }; },{}],15:[function(require,module,exports){ //////////// SubtitleBox //////////// module.exports = function() { this.container=document.createElement("div"); this.container.style.cssText="position:absolute;bottom:0px;width:100%;text-align:center;"; this.subtitleElement=document.createElement("span"); this.subtitleElement.style.cssText="visibility:hidden;display:inline-block;margin:30px 30px 2% 30px;padding:5px 10px;max-width:90%;font-size:2em;font-family:sans-serif;" +"color:rgba(255,255,255,0.8);text-shadow:-1px -1px 0 rgba(0,0,0,0.5), 1px -1px 0 rgba(0,0,0,0.5), -1px 1px 0 rgba(0,0,0,0.5), 1px 1px 0 rgba(0,0,0,0.5);"; this.container.appendChild(this.subtitleElement); this.defaultDuration=4000; this.timer=null; var thisobj=this; this.setText=function(text,duration) { if(!duration) {duration=this.defaultDuration;} clearInterval(this.timer); this.timer=setInterval(thisobj.hide,duration); this.subtitleElement.innerHTML=text; thisobj.subtitleElement.style.visibility="visible"; } this.hide=function() { clearInterval(thisobj.timer); thisobj.timer=null; thisobj.subtitleElement.innerHTML=""; thisobj.subtitleElement.style.visibility="hidden"; } this.setSize=function(em_size) { this.subtitleElement.style.fontSize = em_size+"em"; } } },{}],16:[function(require,module,exports){ module.exports = function(value) { //create elements this.container=document.createElement("div"); this.container.style.cssText="position:relative;overflow:hidden;cursor:pointer;width:100px;height:20px;margin:10px 0;background-color:rgba(0,0,0,0.5)"; this.handleElem=document.createElement("div"); this.handleElem.style.cssText="width:0;height:100%;background:#ddd;border-right:2px solid #fff"; this.container.appendChild(this.handleElem); this.width=parseInt(this.container.style.width); this.mouseDown=false; this.onvaluechange=null; this.value=0; var thisobj=this; //Sets the current volume for this object but does not call the //volumechange listener this.setValue=function(value) { if(value<0) {value=0;} else if(value>1) {value=1;} this.handleElem.style.width=((this.width*value)|0)+"px"; this.value=value; } this.container.onmousedown=function(event) { if(!event) {event=window.event;} thisobj.mouseDown=true; thisobj.onmousemove(event); } this.onmouseup=function(event) { if(!event) {event=window.event;} thisobj.mouseDown=false; } this.onmousemove=function(event) { if(!event) {event=window.event;} if(thisobj.mouseDown) { var relX=event.clientX-thisobj.getHorizontalOffset(); if(relX>thisobj.width) {relX=thisobj.width;} thisobj.setValue(relX/thisobj.width); if(thisobj.onvaluechange!=null) {thisobj.onvaluechange(thisobj.value);} } } this.getHorizontalOffset=function() { var offset=(this.container.clientWidth-this.width)/2; var element=this.container; do { offset+=element.offsetLeft; element=element.offsetParent; } while(element!=null); return offset; } document.addEventListener("mousemove",thisobj.onmousemove); document.addEventListener("mouseup",thisobj.onmouseup); if(value) {this.setValue(value);} } },{}],17:[function(require,module,exports){ //author: ptrgast //Create a package like hierarchy if(typeof drama=="undefined") {window.drama={};} drama.constants=require("./dp-constants.js"); drama.motion=require("./dp-motions.js"); drama.actions=require("./dp-actions.js"); //////////// The Player Object //////////// module.exports = function(containerId, options) { var thisobj = this; //--prototypes & includes--// this.log=require("./../../common/mod-log.js"); this.EventsManager=require("./../../common/mod-eventsmanager.js"); this.DrawQueue=require("./dp-drawqueue.js"); this.MessagesBox=require("./dp-messagesbox.js"); this.InfoBox=require("./dp-infobox.js"); this.Controls=require("./dp-controls.js"); this.SubtitleBox=require("./dp-subtitlebox.js"); this.Story=require("./../../common/mod-story.js"); this.OptionsManager=require("./../../common/mod-optionsmanager.js"); this.ResizeDetector=require("./../../common/mod-resizedetector.js"); //--prepare options--// this._defaultOptions = { showControls: true } //--variables--// this._logName = "Player"; this.PLAYER_VERSION = "0.34.2"; this.log.message("Version "+this.PLAYER_VERSION, this); this.eventsManager=new this.EventsManager(); this.story=null; this.loadtotal=0; this.loadcounter=0; this.loaded=false; this.loadtimer; this._playbackRate = 1.0; this.time=0; //primary time variable (ms) this.mtime=0; //secondary time variable for maintaining motion when in soft-pause mode (ms) this.mtimesec=0; //secondary time in seconds this.starttime=0; this.mstarttime=0; this.tli=0; //timeline index this.drawQueue=new this.DrawQueue(); this.framesCounter=0; this.started=0; //0:not started 1:softpause 2:started this.currentLanguage=0; this.volume=0.5; this.playerRatio=16/9; this.drawTimer; this.playbackProgressTimer = null; this.playbackProgressTimerInterval = 200; this.options = new this.OptionsManager(this._defaultOptions, options); this.resizeDetector = new this.ResizeDetector(); //--functions--// //I18N functions this.setLanguage = function(li) { this.currentLanguage=li; this.eventsManager.callHandlers("languagechange",li); } this.getLanguage = function() {return this.currentLanguage;} this.getLanguageName = function() {return this.story.languages[this.currentLanguage];} this.getLanguages = function() { if(this.story!=null) {return this.story.languages;} else {return [];} } //--elements--// // player this.playerElement=(typeof containerId=="undefined" || containerId==null)?document.createElement("div"):document.getElementById(containerId); this.playerElement.className = "drama-player"; this.playerElement.style.position="relative"; this.playerElement.style.overflow="hidden"; this.playerElement.style.backgroundColor="#000"; // player > canvas-wrapper this.canvasWrapper=document.createElement("div"); this.canvasWrapper.style.cssText="font-size:0px;text-align:center;"; // player > canvas-wrapper > canvas this.canvas=document.createElement("canvas"); this.canvas.style.cssText="background-color:#000;" this.canvas.innerHTML="

Sorry, your browser doesn't support the <canvas> element...

"; this.info=new this.InfoBox(this); this.notificationbox=new this.MessagesBox(this); this.subtitlebox=new this.SubtitleBox(); this.controlsbox=new this.Controls(this); this.playerElement.onmousemove=this.controlsbox.onmousemove; //Pass mousemove events to controlsbox this.canvasWrapper.appendChild(this.canvas); this.playerElement.appendChild(this.info.container); this.playerElement.appendChild(this.canvasWrapper); this.playerElement.appendChild(this.notificationbox.container); this.playerElement.appendChild(this.subtitlebox.container); if(this.options.get("showControls")==true) {this.playerElement.appendChild(this.controlsbox.container)}; this.context=this.canvas.getContext("2d"); //returns the current time this._now = function() { return new Date().getTime()*this._playbackRate; } //player & story dimensions this._onresize=function() { if(!this.isFullscreen) { this.playerWidth=this.playerElement.clientWidth; var requestedHeight = this.options.get("height"); if(requestedHeight==null) { this.playerHeight = this.playerWidth/this.playerRatio; this.playerElement.style.height=this.playerHeight+"px"; } else { this.playerElement.style.height = requestedHeight; this.playerHeight = this.playerElement.clientHeight; } } else { this.playerWidth=window.innerWidth; this.playerHeight=window.innerHeight; this.playerElement.style.height=this.playerHeight+"px"; } //resize canvas this._computeCanvasSize(this.playerWidth, this.playerHeight); //set subtitles size var subsize = (((this.canvas.width/400)*0.9*10)|0)/10; this.subtitlebox.setSize(subsize); this.eventsManager.callHandlers("resize"); } this._computeCanvasSize=function(containerWidth, containerHeight) { var containerRatio=containerWidth/containerHeight; if(this.story!=null) { var storyRatio=this.story.width/this.story.height; if(containerRatio>storyRatio) { this.canvas.height=containerHeight; this.canvas.width=containerHeight*storyRatio; this.canvasWrapper.style.paddingTop="0px"; } else { this.canvas.width=containerWidth; this.canvas.height=containerWidth/storyRatio; this.canvasWrapper.style.paddingTop=(containerHeight-this.canvas.height)/2+"px"; } scalefactor=this.canvas.width/this.story.width; this.context.scale(scalefactor,scalefactor); } } this.playerElement.onresize = function() {thisobj._onresize();} this.resizeDetector.watchElement(this.playerElement); this._onresize(); window.addEventListener("resize",function() { if(thisobj.playerElement.scrollWidth!=thisobj.playerWidth) { thisobj._onresize(); } }); //loadStory() //Loads a new story to the player (url or story object) this.loadStory=function(source) { // stop playback if(this.started!=0) { this.stop(); this.drawQueue.reset(); //stop resets the draw queue but add the default actor back in this.controlsbox.refresh(); } this.eventsManager.callHandlers("loading"); this.story=new this.Story(); this.story.onprogress=this.refreshProgress; this.story.onload=function() { thisobj._onresize(); thisobj.setVolume(thisobj.volume); thisobj.eventsManager.callHandlers("ready"); } this.time=0; this.mtime=0; this.loaded=false; if(typeof source=="string") { this.story.load(source); } else { this.story.loadFromObject(source); } this.drawQueue.add(this.story.stagecurtain); this.drawQueue.add(this.story.viewport); } // play() // Starts the story playback. this.play=function(){ //set the time variables if(this.started!=2) {this.eventsManager.callHandlers("play");} this.started=2; if(this.loaded) {this.notificationbox.set();} else {this.log.warning("Story not loaded!");} this.starttime=this._now()-this.time; this.mstarttime=this._now()-this.mtime; //play audio tracks for(trki=0;trki=this.story.timeline[this.tli].time) { var currentEvent = this.story.timeline[this.tli]; this.time = currentEvent.time; if(currentEvent.action=="show") { //Add the actor to the drawing queue according to the z factor var actor=this.story.actors[currentEvent.index]; this.drawQueue.add(actor); } else if(currentEvent.action=="hide") { //Remove the actor from the drawing queue var actor=this.story.actors[currentEvent.index]; this.drawQueue.remove(actor); } else if(currentEvent.action!=null && currentEvent.action.params!=null && currentEvent.action.params.tx!=null) { var actor = this.story.actors[currentEvent.index]; if(currentEvent.action.params.ttnewTime) { //Found an ongoing audiotrack audiotrack.play(); if(currentState==0) {audiotrack.pause();} audiotrack.seek(newTime-currentEvent.time); } } else if(currentEvent.audiotrack!=null && currentEvent.action=="stop") { var audiotrack = this.story.audiotracks[currentEvent.index]; audiotrack.stop(); } this.tli++; } //Stop the audiotracks that remained paused for(var i=0;i=totalAssets) { thisobj.loaded=true; if(thisobj.started==0) {thisobj.notificationbox.set(thisobj.story.title);} else {thisobj.notificationbox.set();} } } //getPlayerElement() //Returns the root container. this.getPlayerElement=function() {//returns the player element return this.playerElement; } //draw() //This function is responsible for drawing the story. this.draw=function(){ if(this.loaded&&this.started>0) { this.mtime=this._now()-this.mstarttime; this.mtimesec=this.mtime/1000; if(this.started>1) { this.time=this._now()-this.starttime; //timeline while(this.tli=this.story.timeline[this.tli].time) { //this.info.print("timeline action at "+this.time); if(typeof this.story.timeline[this.tli].action=="object" && this.story.timeline[this.tli].action!=null && this.story.timeline[this.tli].action.type=="show") { //add the actor to the drawing queue according to the z factor var actor=this.story.actors[this.story.timeline[this.tli].index]; this.drawQueue.add(actor); } else if(typeof this.story.timeline[this.tli].action=="object" && this.story.timeline[this.tli].action!=null && this.story.timeline[this.tli].action.type=="hide") { //remove the actor from the drawing queue var actor=this.story.actors[this.story.timeline[this.tli].index]; this.drawQueue.remove(actor); } else if(this.story.timeline[this.tli].action=="play") { var track=this.story.audiotracks[this.story.timeline[this.tli].index]; track.setVolume(this.volume); track.play(); } else if(this.story.timeline[this.tli].action=="stop") { var track=this.story.audiotracks[this.story.timeline[this.tli].index]; track.stop(); } else if(this.story.timeline[this.tli].action!=null&&this.story.timeline[this.tli].actor!=null) { var actor=this.story.actors[this.story.timeline[this.tli].index]; actor.action=this.story.timeline[this.tli].action; drama.actions[actor.action.type].init(this,actor); } else if(this.story.timeline[this.tli].action!=null&&this.story.timeline[this.tli].audiotrack!=null) { var track=this.story.audiotracks[this.story.timeline[this.tli].index]; track.action=this.story.timeline[this.tli].action; } else if(this.story.timeline[this.tli].subtitle!=null) { var subtitle=this.story.timeline[this.tli].subtitle; var lang=this.story.languages[this.currentLanguage]; if(typeof subtitle[lang]!="undefined") { this.subtitlebox.setText(subtitle[lang], subtitle.duration); } } this.tli++; if(this.tli>=this.story.timeline.length) { //end of story if(this.controlsbox) {this.controlsbox.stopButton.onclick();} else {this.stop();} this.log.message("Story ended.",this); return; } } } //draw actors this._drawActors(); this.framesCounter++; } } this._drawActors = function() { for(var i=0;iparams.storyheight) { params.particles[i].y=params.viewport.y-params.storyheight*Math.random(); params.particles[i].x=params.viewport.x+params.storywidth*Math.random(); } } } },{"./../../common/mod-eventsmanager.js":2,"./../../common/mod-log.js":3,"./../../common/mod-optionsmanager.js":4,"./../../common/mod-resizedetector.js":5,"./../../common/mod-story.js":6,"./dp-actions.js":7,"./dp-constants.js":8,"./dp-controls.js":9,"./dp-drawqueue.js":10,"./dp-infobox.js":11,"./dp-messagesbox.js":13,"./dp-motions.js":14,"./dp-subtitlebox.js":15}],18:[function(require,module,exports){ //Create a package like hierarchy if(typeof drama=="undefined") {window.drama={};} drama.Player = require("./modules/player-main.js"); },{"./modules/player-main.js":17}]},{},[18]);