This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Improved rendering via Item and Buff objects

  • Loading branch information...
mattrubin committed Oct 15, 2011
1 parent 7ac5695 commit f6a50723ced9ce5a58dc135c79f3f170f19ab72a
Showing with 65 additions and 62 deletions.
  1. +7 −0 common/classes/Buff.php
  2. +47 −0 common/classes/Item.php
  3. +0 −46 common/classes/metabolic.php
  4. +11 −16 item.php
View
@@ -4,6 +4,13 @@
class Buff extends DataObject
{
protected static $TABLE = 'buffs';
+
+ public function render_li(){
+ echo '<li class="buff">';
+ echo '<span class="value">+<a href="buff.php">'.$this->name.'</a></span>';
+ echo '</li>';
+ echo "\n";
+ }
}
?>
View
@@ -1,8 +1,13 @@
<?php
require_once("DataObject.php");
+define('MOOD', 'Mood');
+define('ENERGY', 'Energy');
+define('XP', 'Experience');
+
class Item extends DataObject
{
+
protected static $TABLE = 'items';
private $buff_object = NULL;
@@ -31,6 +36,48 @@ public static function renderList($items){
}*/
}
+ public function render_info(){
+ $this->render_title();
+ $this->render_metabolics();
+ $this->render_details();
+ }
+
+ public function render_title(){
+ echo "<h1 class=\"item-title\">";
+ echo "\t<img src=\"$this->thumb_url\" width=\"40\" height=\"40\"/>\n";
+ echo "\t$this->name\n";
+ echo "</h1>";
+ }
+
+ public function render_metabolics(){
+ echo '<ul class="metabolics">';
+ $this->render_metabolic(MOOD, $this->consume_mood);
+ $this->render_metabolic(ENERGY, $this->consume_energy);
+ $this->render_metabolic(XP, $this->consume_xp);
+ if($buff = $this->getBuff())
+ $buff->render_li();
+ echo "</ul>\n";
+ }
+
+ public static function render_metabolic($metabolic, $value){
+ $value = intVal($value);
+ if($value == 0) return;
+ echo '<li '.(($value==0)?'style="opacity:.3;"':'').'>';
+ echo '<img class="metabolic-image" src="images/'.strtolower($metabolic).'.png" alt="'.$metabolic.'"/>';
+ echo '<span class="value '.(($value >= 0)?'positive':'negative').'">'.$value.'</span>';
+ echo '</li>';
+ echo "\n";
+ }
+
+
+ public function render_details(){
+ echo "<ul class=\"item-details\">\n<li class=\"item-price\">\n";
+ printf("\tWorth about <strong>%d currants</strong>\n", $this->street_price);
+ echo "</li><li class=\"item-stack\">\n";
+ printf("\tFits up to <strong>%d</strong> in a backpack slot\n", $this->stack_height);
+ echo "</li>\n</ul>\n";
+ }
+
public function getBuff(){
if(!$this->consume_buff) return NULL;
@@ -1,46 +0,0 @@
-<?php
-
-define('MOOD', 'Mood');
-define('ENERGY', 'Energy');
-define('XP', 'Experience');
-
-
-function render_metabolic($metabolic, $value){
- $value = intVal($value);
- if($value == 0) return;
- echo '<li '.(($value==0)?'style="opacity:.3;"':'').'>';
- echo '<img class="metabolic-image" src="images/'.strtolower($metabolic).'.png" alt="'.$metabolic.'"/>';
- //if($value >= 0)
- echo '<span class="value '.(($value >= 0)?'positive':'negative').'">'.$value.'</span>';
- //else
- // echo '<span class="negative value">'.$value.'</span>';
- echo '</li>';
- echo "\n";
-}
-function render_buff($name){
- echo '<li class="buff">';
- echo '<span class="value">+<a href="buff.php">'.$name.'</a></span>';
- echo '</li>';
- echo "\n";
-}
-
-
-function render_metabolics($mood, $energy, $xp, $buff=null){
- echo '<ul class="metabolics">';
- render_metabolic(MOOD, $mood);
- render_metabolic(ENERGY, $energy);
- render_metabolic(XP, $xp);
- if($buff) render_buff($buff);
- echo "</ul>\n";
-}
-
-function render_cost($mood, $energy, $xp, $currants=0){
- echo '<ul class="cost">';
- render_metabolic(MOOD, $mood);
- render_metabolic(ENERGY, $energy);
- render_metabolic(XP, $xp);
- echo "</ul>\n";
-}
-
-
-?>
View
@@ -116,22 +116,10 @@ function checkVal(val, idStr){
<a href="index.php">Index</a> |
<a href="item.php?id=<?php echo $item->id; ?>&go=next" >Next &gt;</a>
- <h1 class="item-title">
- <img src="<?php echo $item->thumb_url ?>" width="40" height="40"/>
- <?php echo $item->name; ?>
- </h1>
- <?php
- include_once("common/classes/metabolic.php");
- render_metabolics($item->consume_mood, $item->consume_energy, $item->consume_xp, isset($buff)?$buff->name:null);
+ <?php
+ // Render basic info about the item
+ $item->render_info();
?>
- <ul class="item-details">
- <li class="item-price">
- Worth about <strong><?php echo intVal($item->street_price); ?> currants</strong>
- </li>
- <li class="item-stack">
- Fits up to <strong><?php echo intVal($item->stack_height); ?></strong> in a backpack slot
- </li>
- </ul>
@@ -140,7 +128,14 @@ function checkVal(val, idStr){
<br/><br/><br/><br/>
<h2><?php echo ($recipe['harvest'])?'Harvest':'Recipe'; ?></h2>
<?php
- include_once("common/classes/metabolic.php");
+ function render_cost($mood, $energy, $xp, $currants=0){
+ echo '<ul class="cost">';
+ Item::render_metabolic(MOOD, $mood);
+ Item::render_metabolic(ENERGY, $energy);
+ Item::render_metabolic(XP, $xp);
+ echo "</ul>\n";
+ }
+
render_cost($recipe['cost_mood'], $recipe['cost_energy'], $recipe['cost_xp'], $recipe['cost_currants']);
?>
<form method="post" id="form">

0 comments on commit f6a5072

Please sign in to comment.