Skip to content

Commit

Permalink
Merge branch 'debug'
Browse files Browse the repository at this point in the history
  • Loading branch information
luffah committed Feb 18, 2020
2 parents 77b162f + 0dc5dcc commit b2e7327
Show file tree
Hide file tree
Showing 19 changed files with 408 additions and 343 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
bak
#trashes
_trash
.build

#report files
*.pdf
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ NODEJS=nodejs
LANGS?=fr en

all: .npm
test -L src/js/.build || (cd src/js; ln -s ../../.build .build)
python3 Makefile.py ${LANGS}

.npm:
npm install && touch .npm

_LINK=src/js/.build
clean:
rm -rf webroot .build .npm
test -L ${_LINK} && unlink ${_LINK} || (test -e ${_LINK} && echo ! Warning ! ${_LINK} shall be removed || true)

server: all
xterm -e "cd webroot; python -mSimpleHTTPServer" &
10 changes: 8 additions & 2 deletions Makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def unifyjs(dest, lines=[], jssrc=[]):
with open(tmp, "w") as buf:
buf.writelines(ret)

nodebin('uglifyjs', '-o', dest, tmp, '-c', '-m')
nodebin('uglifyjs', '-o', dest, tmp, '-c', '-m')

with open(dest, "r") as buf:
return buf.readlines()
Expand All @@ -119,6 +119,7 @@ def postcss(fpath):


def make_all(lang):
print("-%s-" % lang)
os.makedirs(WEBROOT, exist_ok=True)
os.makedirs(TMPDIR, exist_ok=True)
os.makedirs(IMAGEDIR, exist_ok=True)
Expand Down Expand Up @@ -152,12 +153,17 @@ def make_all(lang):
'src/js/terminus.run.js',
]

pojsfile = os.path.join(TMPDIR, 'terminus.dialog.%s.js' % lang)
pojs=po2json('src/lang/terminus.%s.po' % lang)
with open(pojsfile, "w") as buf:
buf.writelines(pojs)

htmlinject(
'src/index.html',
WEBROOT + '/' + LANG_TO_INDEX[lang],
jscontent=unifyjs(
TMPDIR + '/min.js',
lines=po2json('src/lang/terminus.%s.po' % lang),
lines=pojs,
jssrc=jssrc),
csscontent=postcss('src/css/terminus.css')
)
Expand Down
24 changes: 21 additions & 3 deletions src/css/terminus.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ body {
position:absolute;
width:100%;
}
#term {
font-family: term;
}
.color-ok {
color:lightgreen;
}
.color-ko {
color:red;
}
.color-pass {
color:orange;
}
.color-cmd {
color:chartreuse;
}
Expand All @@ -41,6 +47,9 @@ color:palevioletred;
.color-item {
color:magenta;
}
.color-item.color-executable {
color:blueviolet;
}
.mesg {
color:grey;
}
Expand All @@ -56,9 +65,10 @@ color:grey;
.badge {
position:relative;
text-align:center;
font-family:inherit;
}
.badge-title {
font-size:1.4em;
font-size:1.2em;
}
.badge img {
width:16ch;
Expand Down Expand Up @@ -121,8 +131,16 @@ color:grey;
.msg pre{
display:inline;
}
.passinput:before {
content:'#>';
/*
* .input .input-wrapper:before {
* content:'#> ';
* }
*/
#term .passinput .input-wrapper {
opacity:20%;
}
#term .passinput .input-wrapper input {
max-width:40ch;
}
.choicebox {
border: 10px solid #efefef;
Expand Down
8 changes: 4 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<!-- <div id="pics"><img id="scene"></img></div>-->
<!-- 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/.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/Gettext.js"></script>
Expand All @@ -46,9 +46,9 @@
<script type="text/javascript" src="./js/terminus.level1.js"></script>
<script type="text/javascript" src="./js/terminus.level2.js"></script>
<script type="text/javascript" src="./js/terminus.run.js"></script>
<script type="text/javascript" src="./js/tests/test_academy.js"></script>
<script type="text/javascript" src="./js/tests/test_commands.js"></script>
<script type="text/javascript" src="./js/tests/test_level2.js"></script>
<!--<script type="text/javascript" src="./js/tests/test_academy.js"></script>-->
<!--<script type="text/javascript" src="./js/tests/test_commands.js"></script>-->
<!--<script type="text/javascript" src="./js/tests/test_level2.js"></script>-->
<!--<script type="text/javascript" src="./js/tests/test_battlescene.js"></script>-->
<!-- <script type="text/javascript" src="./js/engine/autoexplore.js"></script>-->
<!-- endinject -->
Expand Down
3 changes: 0 additions & 3 deletions src/js/_build/terminus.dialog.en.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/js/_build/terminus.dialog.fr.js

This file was deleted.

47 changes: 25 additions & 22 deletions src/js/engine/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ _setupCommand('less',null,[ARGT.strictfile],function(args,vt){// event arg -> ob
if (room){
var item=tgt.item;
if (item) {
vt.push_img(item.picture,{index:ret.length}); // Display image of item
room.fire_event(vt,'less',args,i);
item.fire_event(vt,'less',args,i);
ret.push(cmd_done(vt,[[room,0],[item,i+0]], item.cmd_text.less,'less',args)) ;
if (item.readable || r.sudo){
vt.push_img(item.picture,{index:ret.length}); // Display image of item
room.fire_event(vt,'less',args,i);
item.fire_event(vt,'less',args,i);
ret.push(cmd_done(vt,[[room,0],[item,i+0]], item.cmd_text.less,'less',args)) ;
} else {
item.fire_event(vt, 'unreadable', args, i);
}
} else {
room.fire_event(vt,'destination_unreachable',args,i);
ret.push(_("item_not_exists",args));
Expand All @@ -31,7 +35,7 @@ _lnCommand('more','less');
_setupCommand('ls','dir', [ARGT.dir], function(args,vt){
var t=vt.getContext();
var pic;
console.log(t);
// console.log(t);
function printLS(room,render_classes){
var ret='',pics={},i;
render_classes=render_classes|| {item:'item',people:'people',subroom:'inside-room'};
Expand Down Expand Up @@ -66,15 +70,17 @@ _setupCommand('ls','dir', [ARGT.dir], function(args,vt){
}
}
if (items.length > 0){
ret+= _('items', ["\t" + items.map(function(n){return span('color-item',n.toString());}).join("\n\t")]) + "\t\n";
ret+= _('items', ["\t" + items.map(function(n){
return span('color-item' + (n.executable?' color-executable':''),n.toString());
}).join("\n\t")]) + "\t\n";
}
return {txt:ret,pics:pics};
}

if (args.length > 0){
var room=t.traversee(args[0]).room;
if (room) {
if (!room.readable){
if (!(room.readable||t.sudo)){
return _("permission_denied")+' '+_("room_unreadable");
}
if (room.children.length === 0 && room.items.length === 0 ){
Expand All @@ -86,7 +92,9 @@ _setupCommand('ls','dir', [ARGT.dir], function(args,vt){
pic.addChildren(prtls.pics);
pic.setOneShotRenderClass('room');
vt.push_img(pic); // Display image of room
return prtls.txt;

return cmd_done(vt,[[room, 0]], prtls.txt, 'ls', args) ;
// return prtls.txt;
} else {
return _("room_unreachable");
}
Expand All @@ -96,7 +104,8 @@ _setupCommand('ls','dir', [ARGT.dir], function(args,vt){
pic.addChildren(prtls.pics);
pic.setOneShotRenderClass('room');
vt.push_img(pic); // Display image of room
return prtls.txt;
// return prtls.txt;
return cmd_done(vt,[[t, 0]], prtls.txt, 'ls', args) ;
}
});
_setupCommand('cd','dir',[ARGT.dir],function(args,vt){
Expand Down Expand Up @@ -200,7 +209,7 @@ _setupCommand('cp',null,[ARGT.file,ARGT.filenew], function(args,vt){//event arg
}
});
_setupCommand('mv',null,[ARGT.strictfile,ARGT.file],function(args,vt){// event arg -> object (source)
console.log(args);
// console.log(args);
var t=vt.getContext();
var ret=[],
src,
Expand Down Expand Up @@ -318,6 +327,7 @@ _setupCommand('grep',null,[ARGT.pattern,ARGT.strictfile],function(args,vt){
var item_to_find_in_text = tgt.item.cmd_text.less;
var line_array = [];
var found = false;
if (tgt.item.readable||t.sudo){
if (tgt.item.cmd_text.grep) {
var longest_word = '';
if ( word_to_find.length > 2) {
Expand All @@ -335,6 +345,9 @@ _setupCommand('grep',null,[ARGT.pattern,ARGT.strictfile],function(args,vt){
continue;
}
}
} else {
tgt.item.fire_event(vt, 'unreadable');
}
line_array = item_to_find_in_text.split("\n");
var return_arr = line_array.filter(function(line){ return (line.indexOf(word_to_find) >= 0);});
if (return_arr.length > 0) ret.push(return_arr.join("\n"));
Expand All @@ -344,6 +357,7 @@ _setupCommand('grep',null,[ARGT.pattern,ARGT.strictfile],function(args,vt){
}
return ret.join("\n");
});

_setupCommand('touch',null,[ARGT.filenew],function(args,vt){
var t=vt.getContext();
if (args.length < 1){
Expand All @@ -366,7 +380,6 @@ _setupCommand('touch',null,[ARGT.filenew],function(args,vt){
}
});


_setupCommand('mkdir',null,[ARGT.dirnew],function(args,vt){//event arg -> created dir
var t=vt.getContext();
if (args.length === 1 ){
Expand All @@ -383,6 +396,7 @@ _setupCommand('mkdir',null,[ARGT.dirnew],function(args,vt){//event arg -> create
}
return _("incorrect_syntax");
});

_setupCommand('unzip',null,[ARGT.file.concat(['*.zip'])], function(args,vt){
var t=vt.getContext();
if (args.length === 1){
Expand All @@ -396,14 +410,3 @@ _setupCommand('unzip',null,[ARGT.file.concat(['*.zip'])], function(args,vt){
}
return _("incorrect_syntax");
});
_setupCommand('sudo',null,[ARGT.cmd], function(args,vt){
var t=vt.getContext();
if (['cat', 'less'].indexOf(args[0]) && args[1] === "Certificate"){
t.ev.fire("tryEnterSudo");
return;
} else {
return _("room_wrong_syntax");
}
return _("cannot_cast");
});

1 change: 1 addition & 0 deletions src/js/engine/Gettext.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var POPREFIX_ROOM='room_';
var POPREFIX_ITEM='item_';
var POPREFIX_PEOPLE='people_';
var POSUFFIX_DESC='_text';
var POSUFFIX_EXEC_DESC='_exec';
var PO_NONE='none';
var PO_NONE_DESC=PO_NONE+POSUFFIX_DESC;
var PO_DEFAULT_ROOM=POPREFIX_ROOM+PO_NONE;
Expand Down
2 changes: 1 addition & 1 deletion src/js/engine/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Item.prototype=union(File.prototype, {
if (this.exec_function){
return this.exec_function(this,args,room,vt);
} else {
return cmd_done(vt,[[it,0]],it.cmd_text.less,'exec',args);
return cmd_done(vt,[[it,0]],'','exec',args);
}
},
setPo:function(name,vars){
Expand Down
Loading

0 comments on commit b2e7327

Please sign in to comment.