sbbs/load/defs.js

94 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-10-03 04:08:48 +00:00
/**
* ANSItex definitions
*/
2020-03-26 06:22:46 +00:00
var ACTION_RELOAD =1; /* Reload the current frame */
var ACTION_GOTO =2; /* Goto a specific frame */
var ACTION_BACKUP =3; /* Goto previous frame */
var ACTION_NEXT =4; /* Goto next frame */
var ACTION_TERMINATE =5; /* Terminate the session */
var ACTION_SUBMITRF =6; /* Submit form contents */
var ACTION_STAR =7; /* Star command entry */
2019-10-03 04:08:48 +00:00
2020-03-26 06:22:46 +00:00
var MODE_BL =1; /* Typing * command on baseline */
2019-10-03 04:08:48 +00:00
2020-03-26 06:22:46 +00:00
var FRAME_LENGTH =22; /* Length of a frame */
var FRAME_WIDTH =80; /* Width of a frame */
var FRAME_HEADER =56; /* Size of page owner (length) */
var FRAME_PAGENUM =12; /* Size of page number (length with a-z) */
var FRAME_COST = 9; /* Size of cost (length without unit) */
var FRAME_COSTUNIT ='c'; /* Unit of cost */
2019-10-03 04:08:48 +00:00
2020-03-26 06:22:46 +00:00
var FRAME_TYPE_INFO ='i';
var FRAME_TYPE_TERMINATE ='t';
var FRAME_TYPE_EXTERNAL ='x';
var FRAME_TYPE_RESPONSE ='r';
var FRAME_TYPE_LOGIN ='l';
2020-03-26 06:22:46 +00:00
var ERR_NOT_IMPLEMENTED ='\1RNOT IMPLEMENTED YET?';
var ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
2019-10-03 04:08:48 +00:00
2020-03-26 06:22:46 +00:00
var NO_HISTORY_FRAMES =['98b'];
2019-10-17 13:27:51 +00:00
2019-10-03 04:08:48 +00:00
// Our frame object
2020-03-26 06:22:46 +00:00
function Frame() {
this.version=1;
this.frame=null;
this.index=null;
this.owner=''; // @todo
this.cost=0; // @todo
this.content='';
this.isPublic=false; // @todo
this.isAccessible=false; // @todo
this.type = FRAME_TYPE_INFO;
this.key=[ null,null,null,null,null,null,null,null,null,null ];
this.raw=function() {
return base64_decode(this.content).replace(/(\r\n|\n|\r)/gm,'');
}
this.render=function(withHeader) {
owner = base64_decode(this.owner);
header = '\n\r';
if (this.type != FRAME_TYPE_LOGIN)
header = '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+
'\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
'\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+
(console.screen_columns > 80 ? '\n\r' : '');
return header + base64_decode(this.content);
}
Object.defineProperty(this,'page', {
get: function() {
if (this.frame == null || this.index == null) return null;
return this.frame+this.index;
}
});
}
// Load a frame from disk (.tex file)
Frame.prototype.load = function(filename) {
log(LOG_DEBUG,'Loading frame from: '+filename);
f = new File(system.mods_dir+'ansitex/text/'+filename+'.tex');
if (! f.exists || ! f.open('r')) {
return null;
}
try {
load = JSON.parse(f.read());
for (property in load) {
this[property] = load[property];
}
} catch (error) {
log(LOG_ERROR,'Frame error: '+error);
return null;
}
log(LOG_DEBUG,'Loaded frame: ['+this.frame+']['+this.index+'] ('+this.page+')');
2019-10-17 13:27:51 +00:00
}