From 73fe1bf0a7bd78ca0c8261478a3dbfa2d67193ad Mon Sep 17 00:00:00 2001 From: Eric Fredricksen Date: Tue, 6 Jul 2010 00:04:37 -0700 Subject: [PATCH] First pass at charsheet --- config.js | 14 ++++++++++++++ main.html | 32 ++++++++++++++++++++++++++++++++ main.js | 48 +----------------------------------------------- roster.js | 12 +----------- 4 files changed, 48 insertions(+), 58 deletions(-) diff --git a/config.js b/config.js index 2f738a7..91d53ea 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,20 @@ // TODO These code bits don't really belong here, but this is the only shared bit of js +function template(id, data) { + var tmpl = $("#" + id).html(); + var brag = tmpl.replace(/\$([_A-Za-z.]+)/g, function (str, p1) { + var dict = data; + $.each(p1.split("."), function (i,v) { + if (!dict) return true; + dict = dict[v]; + return null; + }); + return dict || ''; + }); + return brag; +} + // From http://baagoe.com/en/RandomMusings/javascript/ // Johannes Baagøe , 2010 function Mash() { diff --git a/main.html b/main.html index ab94d32..c5b15fc 100644 --- a/main.html +++ b/main.html @@ -171,4 +171,36 @@
Cheats: + + + + diff --git a/main.js b/main.js index c44cb3b..13f4a9a 100644 --- a/main.js +++ b/main.js @@ -815,53 +815,7 @@ function ExportCharSheet() { } function CharSheet() { - var f = ''; - function Wr(a) { f = f + a; } - function WrLn(a) { if (a != undefined) Wr(a); Wr("\r\n"); } - - Wr(Get(Traits,'Name')); - if (GetHostName()) - Wr(' [' + GetHostName() + ']'); - WrLn; - WrLn(Get(Traits,'Race') + ' ' + Get(Traits,'Class')); - WrLn(Format('Level %d (exp. %d/%d)', [GetI(Traits,'Level'), ExpBar.Position, ExpBar.Max])); - //WrLn('Level ' + Get(Traits,'Level') + ' (' + ExpBar.Hint + ')'); - WrLn; - if (Plots.length() > 0) - WrLn('Plot stage: ' + Plots.last().text() + ' (' + PlotBar.Hint + ')'); - if (Quests.length() > 0) - WrLn('Quest: ' + Quests.last().text() + ' (' + QuestBar.Hint + ')'); - WrLn(); - WrLn( 'Stats:'); - WrLn( Format(' STR%7d', [GetI(Stats,'STR')])); - WrLn( Format(' CON%7d', [GetI(Stats,'CON')])); - WrLn( Format(' DEX%7d', [GetI(Stats,'DEX')])); - WrLn( Format(' INT%7d', [GetI(Stats,'INT')])); - WrLn( Format(' WIS%7d HP Max%7d', [GetI(Stats,'WIS'), GetI(Stats,'HP Max')])); - WrLn( Format(' CHA%7d MP Max%7d', [GetI(Stats,'CHA'), GetI(Stats,'MP Max')])); - WrLn(); - WrLn( 'Equipment:'); - for (var i = 1; i <= Equips.length()-1; ++i) { - if (Get(Equips,i)) - WrLn( ' ' + LeftStr(Equips[i].Caption + ' ', 12) + Get(Equips,i)); - } - WrLn(); - WrLn( 'Spell Book:'); - for (var s = 0; s < Spells.length(); ++s) - WrLn(' ' + Spells.label(s) + ' ' + Get(Spells,s)); - WrLn(); - WrLn( 'Inventory (' + EncumBar.Hint + '):'); - WrLn( ' ' + Indefinite('gold piece', GetI(Inventory, 'Gold'))); - for (var ii = 2; ii <= Items.length()-1; ++ii) { - if (Pos(' of ', Inventory[ii].Caption) > 0) - WrLn( ' ' + Definite(Inventory[ii].Caption, GetI(Inventory,ii))); - else - WrLn( ' ' + Indefinite(Items[ii].Caption, GetI(Inventory,ii))); - } - WrLn(); - WrLn( '-- ' + DateTimeToStr(Now)); - WrLn( '-- Progress Quest 6.2 - http://progressquest.com/'); - return f; + return template("sheet", game); } diff --git a/roster.js b/roster.js index 6f3bb0a..d59b4e0 100644 --- a/roster.js +++ b/roster.js @@ -54,17 +54,7 @@ $(document).ready(function () { }); function brag(sheet) { - var tmpl = $("#badge").html(); - var brag = tmpl.replace(/\$([A-Za-z.]+)/g, function (str, p1) { - var dict = sheet; - $.each(p1.split("."), function (i,v) { - if (!dict) return true; - dict = dict[v]; - return null; - }); - return dict || ''; - }); - brag = $(brag); + var brag = $(template("badge", sheet)); if (sheet.motto) brag.find(".bs").text('"' + sheet.motto + '"'); return brag;