Added:
trunk/twxbbs/scripts/game-A/wormholes.js
- copied, changed from r77,
/trunk/twxbbs/scripts/game-A/stop-attacks.js
Modified:
trunk/twxbbs/scripts/game-A/stop-attacks.js
trunk/twxbbs/src/main/resources/org/twdata/twxbbs/proxy/script/global.js
Log:
Playing with a wormhole script, adding better ansi support
Modified: trunk/twxbbs/scripts/game-A/stop-attacks.js
==============================================================================
--- trunk/twxbbs/scripts/game-A/stop-attacks.js (original)
+++ trunk/twxbbs/scripts/game-A/stop-attacks.js Sat Sep 6 07:17:51 2008
@@ -9,7 +9,7 @@
match = prompt.match(attackPtn);
if (match != null) {
println("Try to attack "+match[1]+" with "+match[4]+"
using "+match[3]+" fighters");
- player.send("*\u001b[31m\u001b[1mLet's just be
friends\u001b[22m*");
+ player.send("*#[bold;fgRed]Let's just be friends#[normal]*");
game.setCapturingTextLineTrigger("no", "No", function(txt){});
game.send("n");
Copied: trunk/twxbbs/scripts/game-A/wormholes.js (from r77,
/trunk/twxbbs/scripts/game-A/stop-attacks.js)
==============================================================================
--- /trunk/twxbbs/scripts/game-A/stop-attacks.js (original)
+++ trunk/twxbbs/scripts/game-A/wormholes.js Sat Sep 6 07:17:51 2008
@@ -1,44 +1,19 @@
-var attackPtn = / (.*)'s (.*) \(([0-9]+)-([0-9]+)\).*/;
-
-function maybeAttack(prompt) {
- game.setTextTrigger("maybeAttack", "[N]?", attack);
+function sectorStart(txt) {
+ game.setTextTrigger("warps", "Warps to Sector");
+ pause();
+ game.killTextTrigger("warps");
+ game.setCapturingTextTrigger("insertText", ":", insertWarp);
pause();
- game.killTextTrigger("maybeAttack");
}
-function attack(prompt) {
- match = prompt.match(attackPtn);
- if (match != null) {
- println("Try to attack "+match[1]+" with "+match[4]+"
using "+match[3]+" fighters");
- player.send("*\u001b[31m\u001b[1mLet's just be
friends\u001b[22m*");
- game.setCapturingTextLineTrigger("no", "No", function(txt){});
- game.send("n");
-
- // Gets the game database and updates the attackAttempts stats
- var db = session.get("db");
- var stats = db.getTable("stats");
- var attackAttemptsList = stats.get("attackAttempts");
- attackAttemptsList = (attackAttemptsList == null ? new Array() :
attackAttemptsList);
- attackAttemptsList.push({
- "targetTrader" : match[1],
- "targetShip" : match[2],
- "targetFigs" : match[4],
- "attackerFigs" : match[3]
- });
- stats.put("attackAttempts", attackAttemptsList);
- // debugging
- println("Attack attempts:");
- for (x in attackAttemptsList) {
- println("\tAttacked: "+attackAttemptsList[x].targetTrader);
- }
+function insertWarp(txt) {
- pause();
- } else {
- println("Can't match :"+prompt+":");
- }
+ game.killTextTrigger("insertText");
+ player.send(txt+"
#[bold;blinkSlow;fgRed;bgWhite]<<Wormhole>>#[normal]");
pause();
+
}
-game.setTextTrigger("attack", "Attack", maybeAttack);
+game.setTextLineTrigger("sectorStart", "#[bold;fgGreen]Sector
#[fgYellow]: #[fgCyan]666", sectorStart);
pause();
Modified:
trunk/twxbbs/src/main/resources/org/twdata/twxbbs/proxy/script/global.js
==============================================================================
---
trunk/twxbbs/src/main/resources/org/twdata/twxbbs/proxy/script/global.js
(original)
+++
trunk/twxbbs/src/main/resources/org/twdata/twxbbs/proxy/script/global.js
Sat Sep 6 07:17:51 2008
@@ -1,8 +1,45 @@
var triggerCallbacks = {};
function Api(lexer) {
-
+ var replaceAnsiTokens = function(txt) {
+ var finalTxt = [];
+ var token = null;
+ var hashHit = false;
+ for (var x = 0; x < txt.length; x++) {
+ var c = txt.charAt(x);
+ if (token == null) {
+ if (c == '#') {
+ hashHit = true;
+ finalTxt.push("\u001b")
+ } else {
+ if (hashHit && c == '[') {
+ token = [];
+ }
+ finalTxt.push(c);
+ hashHit = false;
+ }
+ } else {
+ if (c == ';' || c == ']') {
+ var param = token.join("");
+ if (isNaN(parseInt(param))) {
+ param = ansiCode[param];
+ }
+ finalTxt.push(param);
+ finalTxt.push((c == ']' ? 'm' : c));
+ if (c == ';') {
+ token = [];
+ } else {
+ token = null;
+ }
+ } else {
+ token.push(c);
+ }
+ }
+ }
+ //println("turned "+txt+" into "+finalTxt.join(""));
+ return finalTxt.join("");
+ };
this.send = function(txt) {
- lexer.send(txt);
+ lexer.send(replaceAnsiTokens(txt));
};
this.getCurrentLine = function() {
lexer.getCurrentLine();
@@ -11,21 +48,22 @@
lexer.killTextTrigger(id);
}
this.setTextTrigger = function(id, text, callback) {
- lexer.setTextTrigger(id, text);
+ lexer.setTextTrigger(id, replaceAnsiTokens(text));
triggerCallbacks[id] = callback;
}
this.setTextLineTrigger = function(id, text, callback) {
- lexer.setTextLineTrigger(id, text);
+ lexer.setTextLineTrigger(id, replaceAnsiTokens(text));
triggerCallbacks[id] = callback;
}
this.setCapturingTextTrigger = function(id, text, callback) {
- lexer.setCapturingTextTrigger(id, text);
+ lexer.setCapturingTextTrigger(id, replaceAnsiTokens(text));
triggerCallbacks[id] = callback;
}
this.setCapturingTextLineTrigger = function(id, text, callback) {
- lexer.setCapturingTextLineTrigger(id, text);
+ lexer.setCapturingTextLineTrigger(id, replaceAnsiTokens(text));
triggerCallbacks[id] = callback;
}
+
}
var game = new Api(gameApi);
@@ -34,10 +72,47 @@
function pause() {
var id = gameApi.pause();
if (id != null) {
- triggerCallbacks[id](stripAnsi(gameApi.getMatchedLine()));
+ if (triggerCallbacks[id])
+ triggerCallbacks[id](stripAnsi(gameApi.getMatchedLine()));
}
}
function stripAnsi(txt) {
return new String(gameApi.stripAnsi(txt));
}
+
+var ansiCode = new function() {
+ this.normal = "0";
+ this.bold = "1";
+ this.faint = "2";
+ this.italic = "3";
+ this.underlineSingle = "4";
+ this.blinkSlow = "5";
+ this.blinkRapid = "6";
+ this.inverse = "7";
+ this.strike = "9";
+ this.underlineDouble = "21";
+ this.boldOff = "22";
+ this.italicsOff = "23";
+ this.underlineOff = "24";
+ this.inverseOff = "27";
+ this.strikeOff = "29";
+ this.fgBlack = "30";
+ this.fgRed = "31";
+ this.fgGreen = "32";
+ this.fgYellow = "33";
+ this.fgBlue = "34";
+ this.fgPurple = "35";
+ this.fgCyan = "36";
+ this.fgWhite = "37";
+ this.fgDefault = "39";
+ this.bgBlack = "40";
+ this.bgRed = "41";
+ this.bgGreen = "42";
+ this.bgYellow = "43";
+ this.bgBlue = "44";
+ this.bgPurple = "45";
+ this.bgCyan = "46";
+ this.bgWhite = "47";
+ this.bgDefault = "49";
+};
\ No newline at end of file