Skip to content

Commit

Permalink
Game thread links on index.php
Browse files Browse the repository at this point in the history
Accept a URL as part of the new game creation process, determine
whether it is a PA forum thread, and store the thread number if
it is.  In the game index, provide links to game threads for those
games for which a thread number is available.
  • Loading branch information
wallyaltman committed Jun 29, 2011
1 parent c773b3f commit 13b15ad
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 74 deletions.
52 changes: 37 additions & 15 deletions chaos.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ body {
}

hgroup {
margin:0 0 10px 45px;
margin:0 0 10px 45px;
}
h1 {
color:#BB1111;
text-shadow: #200000 0px 0px 3px;
padding:4px;
}
hgroup > h1 {
margin:-5px 0 3px 0;
margin:-5px 0 3px 0;
}
hgroup > h2 {
color:#BB1111;
text-shadow: #200000 0px 0px 3px;
font-size:1.6em;
display:block;
margin-left:15px;
width:auto;
font-size:1.6em;
display:block;
margin-left:15px;
width:auto;
}
/* Server time */
/* Server time */
time {
position:relative;
top:-20px;
Expand Down Expand Up @@ -133,13 +133,17 @@ input:checked + label[for="hornedrat"]{
text-shadow: #282828 1px 1px 0;
}
/** Game number, official vs. other game **/
form > fieldset:nth-of-type(2){
form > fieldset:nth-of-type(1){
height:43px;
}
/* Game number input */
#gamenumber {
width:80px;
}
/* Game thread entry */
input[type="url"] {
width:350px;
}
/*** My Games / Recent Games***/
/** Game links **/
section a {
Expand Down Expand Up @@ -176,26 +180,44 @@ section a.more:active {
color:#000000;
text-shadow: #B300FF 1px 1px 0, #B300FF 1px -1px 0, #B300FF -1px -1px 0, #B300FF -1px 1px 0;
}
/** Game thread links**/
section a.thread {
text-decoration:none;
font-weight:bold;
margin-left:4px;
}
section a.thread:link {
color:#001d69;
text-shadow: #000011 1px 1px 0;
}
section a.thread:visited {
color:#295CE3;
text-shadow: #000030 1px 1px 0;
}
section a.thread:active {
color:#000000;
text-shadow: #0000E0 1px 1px 0, #0000E0 1px -1px 0, #0000E0 -1px -1px 0, #0000E0 -1px 1px 0;
}
/*** Other ***/
.hideme {
display:none;
}
/**** gameboard.php ****/
/*** Navigation ***/
nav {
position:relative;
top:-75px;
position:relative;
top:-75px;
}
nav > ul {
float:right;
padding:0;
float:right;
padding:0;
}
nav li {
display:inline-block;
padding-right:8px;
display:inline-block;
padding-right:8px;
}
nav a {
font-weight:bold;
font-weight:bold;
}
nav a:link, nav a:visited {
color:#9922CC;
Expand Down
4 changes: 4 additions & 0 deletions gameboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,8 @@ function drawBoard(blank, local){
var oldWorldXML = state.getElementsByTagName("oldworld")[0];
//Check for the game type (for Chaos cards)
board.expansion = state.documentElement.getAttribute("expansion");
//Check for a game thread number (forums.penny-arcade.com/showthread.php?thread=...)
board.threadNum = state.documentElement.getAttribute("thread");
//Get the board setup
var info = getGameSetup(board.expansion);
board.info = info;
Expand Down Expand Up @@ -2633,6 +2635,8 @@ function saveBoardXML(saveType){
boardState.setAttribute("state", gameState || board.state);
//Set the game expansion
boardState.setAttribute("expansion", board.expansion);
//Set the game thread number
boardState.setAttribute("thread", board.threadNum);
//Old World cards
var oldWorld = xmlDoc.createElement("oldworld");
oldWorld.setAttribute("set", board.owcset);
Expand Down
3 changes: 3 additions & 0 deletions gamelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
if ($xmlgame->moveToAttribute('expansion')){
$gamestarts[$gnum]['expansion'] = $xmlgame->value;
}
if ($xmlgame->moveToAttribute('thread')){
$gamestarts[$gnum]['thread'] = $xmlgame->value;
}
$gamestarts[$gnum]['modified'] = $modtimes[$gnum];
}
$xmlgame->close();
Expand Down
5 changes: 4 additions & 1 deletion gamelist_q.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
if ($xmlgame->moveToAttribute('expansion')){
$gamestarts[$gnum]['expansion'] = $xmlgame->value;
}
if ($xmlgame->moveToAttribute('thread')){
$gamestarts[$gnum]['thread'] = $xmlgame->value;
}
$gamestarts[$gnum]['modified'] = $modtimes[$gnum];
}
$xmlgame->close();
Expand All @@ -77,4 +80,4 @@
$ownerfile = 'owned_games.json';
$owneroutput = json_encode($gamestarts);
file_put_contents($dir.$ownerfile, $owneroutput, LOCK_EX);
?>
?>
103 changes: 84 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
function Index(){

/*** Private ***/

var $textGameNumber = $("#gamenumber");

var $textPlayerNames = $('[name^="player_"]');

var $radioOfficialGame = $("#officialgame");
var $radioOtherGame = $("#othergame");

var $checkIcon = $("#check");

var $errorIcon = $("#error");


var $urlGameThread = $("#pathread");
var $hiddenGameThread = $("#threadnum");

var $checkIconGame = $("#checkgame");
var $errorIconGame = $("#errorgame");

var $checkIconThread = $("#checkthread");
var $errorIconThread = $("#errorthread");

/**
* Disable the "player name" text input field for
* a ruinous power.
Expand All @@ -44,12 +49,11 @@ function Index(){
$(this).change(disableTextInput);
};


/**
* Determine whether the game number falls within
* the allowable range, and is still available.
*/

var checkGameNumber = function(){
var dfd = new $.Deferred();
var official = $radioOfficialGame.prop("checked");
Expand All @@ -65,7 +69,7 @@ function Index(){
});
return dfd.promise();
};

/**
* Update the icons to reflect the validity of
* the game number.
Expand All @@ -74,16 +78,71 @@ function Index(){
var updateGameNumberIcons = function(){
$.when(checkGameNumber()).then(function(okay){
if (okay){
$errorIcon.hide();
$checkIcon.show();
$errorIconGame.hide();
$checkIconGame.show();
}
else {
$checkIcon.hide();
$errorIcon.show();
$checkIconGame.hide();
$errorIconGame.show();
}
});
};


/**
* Check whether a forum thread can be identified
* from a given URL or thread number.
*/

var validateGameURL = function(){
var dfd = new $.Deferred();
var url = $urlGameThread.attr("value");
//Capture groups: /------------------------------1------------------------------\ /--4--\
var pattern = /^((?:http:\/\/)?forums.penny-arcade.com\/show(thread|post)\.php\?)?(?:(t|p)=)?(\d{6,9})/i;
//Capture groups: \----2----/ \---3--/
//Match the regular expression
var matches = url.match(pattern);
//Check for a valid forum thread
if (matches) {
if (matches[3] === "p") {
//If given a URL with post number, grab the thread, find
//the thread number, and return it
$.get("readthread.php", { p: matches[4] }, function(threadNum) {
$hiddenGameThread.prop("value", threadNum);
dfd.resolve(threadNum);
}, "json");
} else if (!isNaN(matches[4])) {
//If given a URL with thread number, or just a number, simply
//try to GET the page, and return the number on success
$.get("readthread.php", { t: matches[4] }, function(threadNum) {
$hiddenGameThread.prop("value", threadNum);
dfd.resolve(threadNum);
}, "json");
} else {
return false;
}
} else {
return false;
}
return dfd.promise();
}

/**
* Update the icon to indicate whether a forum thread
* could be identified from the URL field.
*/

var updateGameURLIcon = function(){
$.when(validateGameURL()).then(function(threadNum){
if (!isNaN(threadNum) && threadNum > 0) {
$errorIconThread.hide();
$checkIconThread.show();
}
else {
$checkIconThread.hide();
$errorIconThread.show();
}
});
}
/**
* Set handlers on checkboxes to enable/disable name
* entry fields and set/clear placeholder text.
Expand All @@ -100,13 +159,19 @@ function Index(){
});

/**
* Set handlers on the input field and
* the radio buttons.
* Set handlers on the number input field
* and the radio buttons.
*/

$textGameNumber.change(updateGameNumberIcons);
$radioOfficialGame.change(updateGameNumberIcons);
$radioOtherGame.change(updateGameNumberIcons);

/**
* Set handlers on the URL input field.
*/

$urlGameThread.change(updateGameURLIcon);
}

$(document).ready(function(){
Expand Down
Loading

0 comments on commit 13b15ad

Please sign in to comment.