Skip to content

Commit

Permalink
add audio // changing scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
loofa committed Oct 18, 2017
1 parent 61a4163 commit 71bd200
Show file tree
Hide file tree
Showing 29 changed files with 350 additions and 188 deletions.
Empty file modified .gitignore 100644 → 100755
Empty file.
Empty file modified LICENSE.md 100644 → 100755
Empty file.
Empty file modified Makefile 100644 → 100755
Empty file.
Empty file modified docs/icampus_final_round_poster.ppt 100644 → 100755
Empty file.
Empty file modified docs/icampus_final_round_pres.ppt 100644 → 100755
Empty file.
Empty file modified docs/level_map.gv 100644 → 100755
Empty file.
Empty file modified docs/level_map.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/level_map.sublime-project 100644 → 100755
Empty file.
Empty file modified docs/level_map.sublime-workspace 100644 → 100755
Empty file.
Empty file modified docs/terminal_screenshot.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/terminus_screenshot1.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions gulpfile.js 100644 → 100755
Expand Up @@ -57,6 +57,25 @@ function _js(){
/*
* JS (without dialogs)
*/

/* uncomment this for debuging */
// gulp.src([
// 'src/js/engine/js.js',
// 'src/js/engine/Gettext.js',
// 'src/js/engine/Cookie.js',
// 'src/js/engine/GameState.js',
// 'src/js/engine/EventTarget.js',
// 'src/js/engine/Sound.js',
// 'src/js/engine/Music.js',
// 'src/js/engine/VTerm.js',
// 'src/js/engine/Pic.js',
// 'src/js/engine/Item.js',
// 'src/js/engine/Room.js',
// 'src/js/terminus.js'
// ])
// .pipe(concat('min.js'))
// .pipe(gulp.dest("./"))
// ;
return gulp.src([
'src/js/engine/js.js',
'src/js/engine/Gettext.js',
Expand Down
Empty file modified package.json 100644 → 100755
Empty file.
Empty file modified readme.md 100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions src/css/terminus.css
Expand Up @@ -7,6 +7,18 @@ body {
font-size: 1.4rem;
font-stretch:condensed;
}
.color-cmd {
color:red;
}
.color-room {
color:orange;
}
.color-people {
color:blue;
}
.color-item {
color:green;
}
.notifications{
position:fixed;
z-index:0;
Expand Down
Empty file modified src/img/badge.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified src/img/item_vimbook.jpg 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/index.html
Expand Up @@ -20,6 +20,7 @@
<!-- inject:js -->
<iframe id="pogen" style="display:none;"></iframe>
<script type="text/javascript" src="./js/_build/terminus.dialog.fr.js"></script>
<script type="text/javascript" src="./js/engine/howler.core.js"></script>
<script type="text/javascript" src="./js/engine/js.js"></script>
<script type="text/javascript" src="./js/engine/pogen.js"></script>
<script type="text/javascript" src="./js/engine/Gettext.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/js/_build/terminus.dialog.fr.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/js/engine/EventTarget.js
Expand Up @@ -28,6 +28,7 @@ EventTarget.prototype = {

if (this._listeners[event.type] instanceof Array){
var listeners = this._listeners[event.type];
console.log(listeners);
for (var i=0, len=listeners.length; i < len; i++){
listeners[i].call(this, event);
}
Expand Down
7 changes: 5 additions & 2 deletions src/js/engine/GameState.js
Expand Up @@ -8,13 +8,16 @@ GameState.prototype = {
getCurrentRoom : function() {
return window[this.params['']];
},
setCurrentRoom : function(newRoom){
this.params['']=newRoom.name;
saveCookie: function(){
//when you call this function, set the cookie in the browser
if (this.cookie) {
this.cookie.write(this.params);
}
},
setCurrentRoom : function(newRoom){
this.params['']=newRoom.name;
this.saveCookie();
},
add : function(param_name, fun){
this.actions[param_name]=fun;
},
Expand Down
34 changes: 31 additions & 3 deletions src/js/engine/Gettext.js
Expand Up @@ -29,9 +29,33 @@ function objToMsg(o){
}


var type_decorations={
people:'<span class="color-people">%s</span>',
item:'<span class="color-item">%s</span>',
room:'<span class="color-room">%s</span>',
cmd:'<span class="color-cmd">%s</span>'
};
function guess_gettext_mod(txt){
typ=txt.split('_')[0];
console.log(txt,typ);
return {
decorate:type_decorations[typ]
};
}

var poe=(typeof pogen == 'function' );
var var_regexp=/\{\{\w+\}\}/g;
var var_resolve=function(a){return _(a.substring(2,a.length-2));}
var var_regexp=/\{\{\w+(,\[([^,]*(,)?)\])?\}\}/g;
var var_vars_regexp=/\[([^,]*(,)?)\]/g;
function var_resolve(a){
a=a.substring(2,a.length-2);
if (var_vars_regexp.test(a)){
vars=JSON.parse(a.match(var_vars_regexp));
a=a.split(',')[0];
} else {
vars=[];
}
return _(a,vars,guess_gettext_mod(a));
}
function _(str,vars,args) {
if (!def(str)) return '';
if (typeof vars !== 'object' || vars.length === 0 ){
Expand All @@ -45,7 +69,7 @@ function _(str,vars,args) {
if (poe){
pogen(str);
}
if (args.or && or in dialog) {
if (args.or && args.or in dialog) {
str=ret;
ret=dialog[args.or];
} else {
Expand All @@ -61,5 +85,9 @@ function _(str,vars,args) {
// if (poe){
// return ret + "#" + str +"#" ;
// }
if (args.decorate){
console.log('decorate',args.decorate);
ret=args.decorate.printf([ret]);
}
return ret;
}
26 changes: 23 additions & 3 deletions src/js/engine/Item.js
Expand Up @@ -51,10 +51,17 @@ Item.prototype = {
setPo:function(name,vars){
this.name=_(this.poprefix+name,vars);
this.cmd_text.less=_(this.poprefix+name+POSUFFIX_DESC,vars);
this.poid=name;
this.poid=this.poprefix+name;
this.povars=vars;
return this;
},
checkTextIdx : function(textidx) {
return dialog.hasOwnProperty(this.poid+POSUFFIX_DESC+textidx);
},
setTextIdx : function(textidx,vars) {
this.cmd_text.less = _(this.poid+POSUFFIX_DESC+textidx,vars,{or:this.poid+POSUFFIX_DESC});
return this;
},
setPoDelta:function(delta){
if (typeof delta == 'string'){
this.setPo(this.poid+delta,this.povars);
Expand All @@ -80,6 +87,11 @@ Item.prototype = {
this.ev.addListener(name,fun);
return this;
},
addState : function(name,fun){
this.ev.addListener(name,state.Event);
state.add(name,fun);
return this;
},
addStates : function(h){
for (var i in h) {
if (h.hasOwnProperty(i)){
Expand All @@ -97,10 +109,14 @@ Item.prototype = {
this.cmd_event[cmd] = fun;
return this;
},
addCmdText : function(cmd, text) {
setCmdText : function(cmd, text) {
this.cmd_text[cmd] = text;
return this;
},
unsetCmdText : function(cmd){
delete this.cmd_text[cmd];
return this;
},
addValidCmd : function(cmd){
this.valid_cmds.push(cmd);
return this;
Expand All @@ -125,11 +141,15 @@ People.prototype.getName = Item.prototype.getName;
People.prototype.setName = Item.prototype.setName;
People.prototype.setPo = Item.prototype.setPo;
People.prototype.setPoDelta = Item.prototype.setPoDelta;
People.prototype.addCmdText = Item.prototype.addCmdText;
People.prototype.checkTextIdx = Item.prototype.checkTextIdx;
People.prototype.setTextIdx = Item.prototype.setTextIdx;
People.prototype.setCmdText = Item.prototype.setCmdText;
People.prototype.unsetCmdText = Item.prototype.unsetCmdText;
People.prototype.addCmdEvent = Item.prototype.addCmdEvent;
People.prototype.removeCmdEvent = Item.prototype.removeCmdEvent;
People.prototype.addListener = Item.prototype.addListener;
People.prototype.addStates = Item.prototype.addStates;
People.prototype.addState = Item.prototype.addState;
People.prototype.addValidCmd = Item.prototype.addValidCmd;
People.prototype.moveTo = Item.prototype.moveTo;
People.prototype.disappear = Item.prototype.disappear;
Expand Down
28 changes: 2 additions & 26 deletions src/js/engine/Music.js
Expand Up @@ -2,27 +2,10 @@
function Music(soundbank){
this.current=0;
this.soundbank=soundbank;
this.loop=false;
}

function listenerAudioLoop() {
this.currentTime = 0;
this.play();
}
function setAudioLoop(audio,bool){
audio.setAttribute('loop','true');
if (typeof audio.loop == 'boolean')
{
audio.loop = bool;
}
else
{
if (bool){
audio.addEventListener('ended',listenerAudioLoop, false);
} else {
audio.removeEventListener('ended',listenerAudioLoop, false);
}
}
audio._loop = bool;
}
function setAudioFade(audio,fade){
steps=fade[3]/100;
Expand All @@ -31,14 +14,7 @@ function setAudioFade(audio,fade){
// console.log(fade);
for (var i=steps;i>0;i--){
setTimeout(function(){
// audio.volume=1/i+0.01
// console.log(
// parseFloat(((fade[1]-fade[3])*(i/steps))+fade[3]).toPrecision(4),
// fade[1],fade[3],i,steps,(i/steps)
//
// );
audio.volume=parseFloat(((fade[1]-fade[3])*(i/steps))+fade[3]).toPrecision(4);
// ;
},i*100);
}
setTimeout(function(){
Expand All @@ -47,7 +23,7 @@ function setAudioFade(audio,fade){
}
Music.prototype = {
set:function(ref,file,exts){
this.soundbank.set(ref,file,exts,false);
this.soundbank.set(ref,file,exts,{required:false});
},
play:function(ref,attrs){
attrs=d(attrs,{});
Expand Down

0 comments on commit 71bd200

Please sign in to comment.