Thread: Major Additions - Chess
View Single Post
  #129  
Old 08-18-2007, 04:37 PM
aranthorn's Avatar
aranthorn aranthorn is offline
 
Join Date: Jun 2004
Location: Chicago
Posts: 137
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have a couple really nit-picky users complained about white/black, flipped board, etc. Because this mod uses style CSS definitions of alt1 and alt2 for the board (which I think was the right way to go in coding it, btw) some users of mine complained that the Queen's not on her color. She is, but my some of styles are defined with light and dark tones reversed from vB's default. So here's what I did:

I added this bit into every style's "Additional CSS Definitions" area in style manger
Code:
/** START Chess Board **/
		.chess1 {
		   background-color : #FFFFFF;
		}
		
		.chess2 {
		   background-color : #000000;
		}
/** END Chess Board **/
The I changed the plugin "showthread_complete" for the product "chess" to this:
Code:
if($forumid == $vbulletin->options['chess_forumid'])
{
$empty = array('a'=>'','b'=>'','c'=>'','d'=>'','e'=>'','f'=>'','g'=>'','h'=>'');
$board = array(1=>array('a'=>'wR','b'=>'wN','c'=>'wB','d'=>'wQ','e'=>'wK',f=>'wB','g'=>'wN','h'=>'wR'),
	       2=>array('a'=>'wP','b'=>'wP','c'=>'wP','d'=>'wP','e'=>'wP','f'=>'wP','g'=>'wP','h'=>'wP'),
	       3=>$empty,
	       4=>$empty,
	       5=>$empty,
	       6=>$empty,
	       7=>array('a'=>'bP','b'=>'bP','c'=>'bP','d'=>'bP','e'=>'bP','f'=>'bP','g'=>'bP',h=>'bP'),
	       8=>array('a'=>'bR','b'=>'bN','c'=>'bB','d'=>'bQ','e'=>'bK','f'=>'bB','g'=>'bN','h'=>'bR'));

if(preg_match_all("#player\(1,([^)]+)\)#",$data[0][1],$matches,PREG_SET_ORDER))
{
	$player1 = $matches[0][1];
}
else
{
	$player1 = $data[0][0];
}
if(preg_match_all("#player\(2,([^)]+)\)#",$data[0][1],$matches,PREG_SET_ORDER))
{
	$player2 = $matches[0][1];
}

$moveno = 1;
$taken = array();
foreach($data AS $move)
{
	if(!$player2)
	{
		if($move[0] != $player1)
		{
			$player2 = $move[0];
		}
	}
	$postcnt++;
	
	if( (($moveno % 2) && $move[0] == $player1) || (!($moveno % 2) && $move[0] == $player2))
	{  	
		if(preg_match_all("#\(([a-h])([1-8]),([a-h])([1-8])\)#",$move[1],$matches,PREG_SET_ORDER))
		{
			$moveno++;
		}
		foreach($matches AS $match)
		{
			if($board[$match[4]][$match[3]] != '')
			{
				$taken[] = $board[$match[4]][$match[3]];
			}
			$board[$match[4]][$match[3]] = $board[$match[2]][$match[1]];
			$board[$match[2]][$match[1]] = '';
		}
		preg_match_all("#\(([a-h])([1-8]),(w|b)(Q|R|N|B|K|P)\)#",$move[1],$matches,PREG_SET_ORDER);
		foreach($matches AS $match)
		{
			$board[$match[2]][$match[1]] = $match[3].$match[4];
		}
	}

	$movestext[] =  implode($move,": ");

}

$post['signature'] =  "<div id=\"chesschat\" style=\"max-height:200px;overflow:auto;\">" . implode(array_reverse($movestext),"<br />") . "</div>";
if($vbulletin->userinfo['userid'] == 100000000)
{
print_r($vbulletin->options);
die($vbulletin->options['chess_rotation']);
}
if($vbulletin->options['chess_rotation'])
{
	$board = array_reverse($board,true);
}
foreach($board AS $row =>$rowdata)
{
	$output .= "<tr height=\"40px\"><td>$row</td>";
	foreach($rowdata AS $col => $coldata)
	{
		$class = ($class == 'chess1') ? 'chess2':'chess1';
		$imgstr = (($coldata == '') ? ('&nbsp;') : ('<img width="40px" height="40px" src="' . $vbulletin->options['bburl'] . '/images/chess/' . (($coldata[0] == 'b') ? ($vbulletin->options['chess_black']) : ($vbulletin->options['chess_white'])) . "/" . $coldata[1] . ".gif\" />"));
		$output .= "<td id=\"".$col.$row."\"width=\"40px\" onclick=\"move(event,'".$col.$row."')\" class=\"$class\">$imgstr</td>";
	}
	$output .= "</tr>";
	$class = ($class == 'chess1') ? 'chess2':'chess1';
}

foreach($taken AS $piece)
{
	if(substr($piece,0,1) == "w")
	{
		if(!$white)
		{
			$white = "<tr>";
			$whitecnt = 0;
		}
		
		$white .= "<td><img src=\"".$vbulletin->options['bburl']."/images/chess/".$vbulletin->options['chess_white']."/".$piece[1].".gif\" /></td>";
		$whitecnt ++;
		
		if(!($whitecnt % 6))
		{
			$white .= "</tr><tr>";
		}
	}
	else
	{
		if(!$black)
		{
			$black = "<tr>";
			$blackcnt = 0;
		}

		$black .= "<td><img src=\"".$vbulletin->options['bburl']."/images/chess/".$vbulletin->options['chess_black']."/".$piece[1].".gif\" /></td>";
		$blackcnt ++;
		
		if(!($blackcnt % 6))
		{
			$black .= "</tr><tr>";
		}
	}
}

$game_text = $player1 . " vs " . $player2;
$moveplr = (($moveno % 2) ? $player1 : $player2);
$move_text = "Move: $moveno <br /> " . $moveplr . " to move next."; 

eval('$postbits = "' . fetch_template('chess') . '";');
}
All I did was replace the alt1 and alt2 references in the original product plugin with chess1 and chess2 which was defined with white and black backgrounds in the "Additional CSS Definitions" that I added. The part that has the tweaks is in bold / red.

I am going to start looking into making a marble chessboard, wood chessboard, etc.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02216 seconds
  • Memory Usage 1,798KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete