Explorar el Código

Monster info page.

Iñigo Valentin hace 7 años
padre
commit
a25189edf1

+ 5 - 1
application/Controller.php

@@ -7,8 +7,8 @@
     require_once($path["page"] . "Home_Page.php");
     require_once($path["page"] . "Monsters_Page.php");
     require_once($path["page"] . "Monster_Page.php");
+    require_once($path["page"] . "Monster_Info_Page.php");
     require_once($path["page"] . "Catalog_Page.php");
-    require_once($path["page"] . "Fusion_Page.php");
     require_once($path["page"] . "Runes_Page.php");
     require_once($path["page"] . "Report_Page.php");
     require_once($path["page"] . "Report_Skillup_Page.php");
@@ -35,6 +35,7 @@
             global $path;
             global $root;
             $page;
+            $handler;
 
             $db = start_db();
 
@@ -63,6 +64,9 @@
                 elseif (strtoupper($pars[0]) == "CATALOG"){
                     $page = new Catalog_Page($db);
                 }
+                elseif (strtoupper($pars[0]) == "MONSTER_INFO"){
+                    $page = new Monster_Info_Page($db, $pars[1]);
+                }
                 elseif (strtoupper($pars[0]) == "RUNES"){
                     $page = new Runes_Page($db);
                 }

+ 23 - 59
application/entity/K_Monster.php

@@ -3,6 +3,7 @@
     require_once($path["entity"] . "Entity.php");
     require_once($path["entity"] . "K_Skill.php");
     require_once($path["entity"] . "K_Leader_Skill.php");
+    require_once($path["entity"] . "K_Source.php");
 
 
     /**
@@ -187,6 +188,11 @@
          */
         public $essences = [];
 
+        /**
+         * {@see K_Source}s the monster can be get from.
+         */
+        public $sources = [];
+
         /**
          * Constructor.
          *
@@ -308,8 +314,24 @@
                 ];
                 array_push($this->essences, $e);
             }
+             $s =
+              "SELECT source " .
+              "FROM k_monster_source " .
+              "WHERE monster = $id; ";
+            $q = $this->db->query($s);
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->sources, new K_Source($this->db, $r["source"]));
+            }
         }
-        
+
+        /**
+         * Gets the pathto the monster image. The image must be in the
+         * img/content/monster/ directory, and its name must be the monster id,
+         * padded with '0' to 4 digites, and the extension must be '.png'.
+         *
+         * @return path to the image, or a path to a fixed unknown image if it
+         *         doesn't exist.
+         */
         public function get_image(){
             global $base_dir;
             global $path;
@@ -321,63 +343,5 @@
             }
         }
 
-        /**
-         * TODO: UNUSED
-         * 
-         * @param $stat Stat name ("ATK", "DEF", "HP", "SPD", "CRR", "CRD", "RES", "ACC").
-         * @return Value of the base stat (floored integer), -1 if wrong stat.
-         */
-        public function get_base_stat($stat){
-            if ($stat == "ATK" || $stat == "DEF" || $stat == "HP" || $stat == "SPD" || $stat == "CRR" || $stat == "CRD" || $stat == "RES" || $stat == "ACC"){
-                $s = 
-                  "SELECT " .
-                  "  min, " .
-                  "  max " .
-                  "FROM k_monster_stat " .
-                  "WHERE " .
-                  "  monster = " . $this->k_monster->id . " AND " .
-                  "  stat = '" . $stat . "' AND " .
-                  "  stars = " . $this->stars . " AND " .
-                  "  awake = " . $this->awakened . ";";
-                $q = $this->db->query($s);
-                if ($q){
-                    $r = $q->fetchArray(SQLITE3_ASSOC);
-                    if ($r){
-                        $min = $r["min"];
-                        $max = $r["max"];
-                        $min_level = 1;
-                        $max_level = 40;
-                        switch ($this->stars){
-                            case 1:
-                                $max_level = 15;
-                                break;
-                            case 2:
-                                $max_level = 20;
-                                break;
-                            case 3:
-                                $max_level = 25;
-                                break;
-                            case 4:
-                                $max_level = 30;
-                                break;
-                            case 5:
-                                $max_level = 35;
-                                break;
-                        }
-                        $base = $min + (($max - $min) * $this->level / $max_level);
-                        return floor($base);
-                    }
-                    else{
-                        return -1;
-                    }
-                }
-                else{
-                    return -1;
-                }
-            }
-            else{
-                return -1;
-            }
-        }
     }
 ?>

+ 83 - 0
application/entity/K_Source.php

@@ -0,0 +1,83 @@
+<?php
+
+    require_once($path["entity"] . "Entity.php");
+
+
+    /**
+     * Monster source.
+     *
+     * Represents an object from the table 'k_source'.
+     */
+    class K_Source extends Entity{
+
+        /**
+         * Monster identifier.
+         */
+        public $id;
+
+        /**
+         * Source name.
+         */
+        public $name;
+
+        /**
+         * Source description.
+         */
+        public $description;
+
+        /**
+         * Indicates if the source is farmable.
+         */
+        public $farmable_source;
+
+        /**
+         * Constructor.
+         *
+         * Searches the database and retrieves the information about the
+         * monster, populating it and it's items.
+         *
+         * @param SQLite3 $db Connection to the database.
+         * @param int $id Monster identifier.
+         */
+        public function __construct($db, $id){
+            global $path;
+            parent::__construct($db);
+            $s =
+              "SELECT " .
+              "  id, " .
+              "  name, " .
+              "  description, " .
+              "  farmable_source " .
+              "FROM k_source " .
+              "WHERE id = $id; ";
+            $q = $this->db->query($s);
+            $r = $q->fetchArray(SQLITE3_ASSOC);
+            if ($r){
+                $this->id = $r["id"];
+                $this->name = $r["name"];
+                $this->description = $r["description"];
+                $this->farmable_source = $r["farmable_source"];
+            }
+        }
+
+        /**
+         * Gets the pathto the monster image. The image must be in the
+         * img/content/monster/ directory, and its name must be the monster id,
+         * padded with '0' to 4 digites, and the extension must be '.png'.
+         *
+         * @return path to the image, or a path to a fixed unknown image if it
+         *         doesn't exist.
+         */
+        public function get_image(){
+            global $base_dir;
+            global $path;
+            if (file_exists($base_dir . "img/content/source/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
+                return $path["img"]["content"] . "source/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
+            }
+            else{
+                return $path["img"]["layout"] . "unknown.png";
+            }
+        }
+
+    }
+?>

+ 74 - 0
application/page/Monster_Info_Page.php

@@ -0,0 +1,74 @@
+ <?php
+
+    require_once($path["page"] . "Page.php");
+    require_once($path["entity"] . "K_Monster.php");
+
+
+    /**
+     * Monster details page.
+     */
+    class Monster_Info_Page extends Page{
+
+        /**
+         * Selected @{see Monster}0
+         * [0]: Unawakened monster (null if default purple).
+         * [1]: Awakened monster (null if silver).
+         * [2]: Second awakened monster (null if unavailaable).
+         */
+        public $monster = [];
+
+        /**
+         * Constructor.
+         *
+         * Retrieves the data and initializes the variables.
+         *
+         * @param SQLite3 $db Connection to the database.
+         * @param string $id Monster id. Can be any of the awakening stages
+         */
+        public function __construct($db, $id){
+            global $path;
+            global $root;
+            parent::__construct($db);
+            $this->view = $path["view"] . "monster_info.php";
+            $title = "";
+            $monster = new K_Monster($db, $id);
+            if ($monster->can_awaken == 0){
+                // Silver star monster.
+                $this->monster[0] = $monster;
+                $this->monster[1] = null;
+                $this->monster[2] = null;
+                $title = $this->monster[0]->element . " " . $this->monster[0]->name;
+            }
+            elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && $monster->awakens_from == ""){
+                // Default purple (Rainbowmon or King Angelmon)
+                $this->monster[0] = null;
+                $this->monster[1] = $monster;
+                $this->monster[2] = null;
+                $title = $this->monster[1]->name;
+            }
+            elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && $monster->awakens_from =! ""){
+                // Normal monster, already awakened, no 2a.
+                $this->monster[0] = new K_Monster($db, $monster->awakens_from);
+                $this->monster[1] = $monster;
+                $this->monster[2] = null;
+                $title = $this->monster[1]->name . " - " .$this->monster[0]->element . " " . $this->monster[0]->name;
+            }
+            elseif ($monster->can_awaken == 1 && $monster->awakens_to != "" && $monster->awakens_from == ""){
+                // Normal monster, not awakened, may have 2a.
+                $this->monster[0] = $monster;
+                $this->monster[1] = new K_Monster($db, $this->monster[0]->awakens_to);
+                if ($this->monster[1]->awakens_to == ""){
+                    $this->monster[2] = null;
+                }
+                else{
+                    $this->monster[2] = new K_Monster($db, $this->monster[1]->awakens_to);
+                }
+                $title = $this->monster[1]->name . " - " .$this->monster[0]->element . " " . $this->monster[0]->name;
+            }
+
+            $this->title = $title ." - SWDB";
+            $this->description = $title . " info - SWDB";
+            $this->canonical = $root . "monster_info/" . $id;
+        }
+    }
+?>

+ 267 - 0
application/view/monster_info.php

@@ -0,0 +1,267 @@
+<!DOCTYPE html>
+<html lang='en'>
+    <head>
+        <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
+        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
+        <title><?=$page->title?></title>
+        <link rel='shortcut icon' href='<?=$page->favicon?>'/>
+        <!-- CSS files -->
+        <link rel='stylesheet' type='text/css' href='<?=$path["css"]?>ui.css'/>
+        <link rel='stylesheet' type='text/css' href='<?=$path["css"]?>monster_info.css'/>
+        <!-- Script files -->
+        <script src="<?=$path["js"]?>ui.js"></script>
+        <!-- Meta tags -->
+        <link rel='canonical' href='<?=$page->canonical?>'/>
+        <link rel='author' href='<?=$page->author?>'/>
+        <link rel='publisher' href='<?=$page->author?>'/>
+        <meta name='description' content='<?=$page->description?>'/>
+        <meta property='og:title' content='<?=$page->title?>'/>
+        <meta property='og:url' content='<?=$page->canonical?>'/>
+        <meta property='og:description' content='<?=$page->description?>'/>
+        <meta property='og:image' content='<?=$page->icon?>'/>
+        <meta property='og:site_name' content='<?=$page->name?>'/>
+        <meta property='og:type' content='website'/>
+        <meta property='og:locale' content='en'/>
+        <meta name='twitter:card' content='summary'/>
+        <meta name='twitter:title' content='<?=$page->title?>'/>
+        <meta name='twitter:description' content='<?=$page->description?>'/>
+        <meta name='twitter:image' content='<?=$page->icon?>'/>
+        <meta name='twitter:url' content='<?=$page->canonical?>'/>
+        <meta name='robots' content='index follow'/>
+    </head>
+    <body>
+<?php
+        include __DIR__ . "/inc/header.php";
+?>
+        <section id='monster'>
+<?php
+            for ($i = 0; $i < 3; $i ++){
+                if ($page->monster[$i] != null){
+                    if ($i == 0 && monster[1] == null){
+                        // Silver monster.
+                        $star_src = $path["img"]["layout"] . "icon/star_silver.png";
+                        $mon_title = $page->monster[$i]->element . " " . $page->monster[$i]->name;
+                    }
+                    elseif ($i == 0 && monster[1] != null){
+                        // Gold monster.
+                        $star_src = $path["img"]["layout"] . "icon/star.png";
+                        $mon_title = $page->monster[$i]->element . " " . $page->monster[$i]->name;
+                    }
+                    elseif ($i == 1){
+                        // Awakened monster.
+                        $star_src = $path["img"]["layout"] . "icon/star_aw.png";
+                        $mon_title = $page->monster[$i]->name;
+                    }
+                    elseif ($i == 2){
+                        // Second awakened.
+                        $star_src = $path["img"]["layout"] . "icon/star_aw2.png";
+                         $mon_title = $page->monster[$i]->name;
+                    }
+?>
+                    <article class='stage'>
+                        <div class='profile'>
+                            <img class='monster_image' title='<?=$mon_title?>' class='border_<?=$page->monster[$i]->element?>' src='<?=$page->monster[$i]->get_image()?>'/>
+                            <div class='details'>
+                                <h4><?=$mon_title?></h4>
+                                <span class='stars'>
+<?php
+                                    for ($j = 0; $j < $page->monster[$i]->base_stars; $j ++){
+?>
+                                        <img class='star' src='<?=$star_src?>'/>
+<?php
+                                    }
+?>
+                                </span>
+                                <span class='archetype'>
+                                    <?=$page->monster[$i]->archetype?>
+                                </span>
+                            </div> <!-- #details -->
+                        </div>
+                        <table class='stats'>
+                            <tr>
+                                <th>
+                                    ATK
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->base_attack?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    DEF
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->base_defense?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    HP
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->base_hp?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    SPD
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->speed?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    CRR
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->crit_rate?>%
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    CRD
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->crit_damage?>%
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    ACC
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->accuracy?>%
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>
+                                    RES
+                                </th>
+                                <td>
+                                    <?=$page->monster[$i]->resistance?>%
+                                </td>
+                            </tr>
+                        </table>
+                        <div class='extra'>
+<?php
+                            if (count($page->monster[$i]->sources) > 0){
+?>
+                                <div class='sources'>
+                                    <span>
+                                        Obtainable from:
+                                    </span>
+<?php
+                                    foreach ($page->monster[$i]->sources as $source){
+?>
+                                        <img title='<?=$source->name?>' class='source' src='<?=$source->get_image()?>' />
+<?php
+                                    }
+?>
+                                </div>
+<?php
+                            }
+                            if (count($page->monster[$i]->essences) > 0){
+?>
+                                <div class='essences'>
+                                    <span>
+                                        Awake with:
+                                    </span>
+<?php
+                                    foreach ($page->monster[$i]->essences as $essence){
+?>
+                                       <div class='essence border_<?=$essence["element"]?>'>
+                                            <img alt='<?=$essence["grade"]?> <?=$essence["element"]?> essence' title='<?=$essence["amount"]?>x <?=$essence["grade"]?> <?=$essence["element"]?> essence' class='essence' src='<?=$path["img"]["layout"]?>essence/<?=$essence["element"]?>_<?=$essence["grade"]?>.png'/>
+                                            <span>
+                                                <?=$essence["amount"]?>
+                                            </span>
+                                        </div>
+<?php
+                                    }
+?>
+                                </div>
+<?php
+                            }
+?>
+                        </div> <!-- .extra -->
+                        <div class='skills'>
+<?php
+                            if ($page->monster[$i]->leader_skill){
+?>
+                                <div class='skill'>
+                                    <img class='skill_img' src='<?=$page->monster[$i]->leader_skill->get_image()?>'/>
+                                    <span class='skill_level'>
+                                        &nbsp;
+                                    </span>
+                                    <span class='skill_name'>
+                                        Leader skill
+                                    </span>
+                                    <span class='skill_description'>
+                                        <?=$page->monster[$i]->leader_skill->create_description()?>
+                                    </span>
+                                </div>
+<?php
+                            }
+                            foreach ($page->monster[$i]->skill as $skill){
+?>
+                                <div class='skill'>
+                                    <img class='skill_img' src='<?=$skill->get_image()?>'/>
+                                    <span class='skill_name'>
+                                        <?=$skill->name?>
+                                    </span>
+                                    <span class='skill_description'>
+                                        <?=$skill->description?>
+                                    </span>
+<?php
+                                    if (count($skill->effect) > 0){
+?>
+                                        <span class='skill_effects'>
+<?php
+                                            foreach ($skill->effect as $effect){
+?>
+                                                <img class='effect_img' title='<?=$effect->name?>' src='<?=$effect->get_image()?>'/>
+<?php
+                                            }
+?>
+                                        </span>
+<?php
+                                    }
+                                    if ($skill->max_level > 1){
+?>
+                                        <table class='skill_up'>
+<?php
+                                            foreach ($skill->level as $level){
+                                                if ($level->level > 1){
+?>
+                                                    <tr>
+                                                        <td class='level'>
+                                                            Lv. <?=$level->level?>
+                                                        </td>
+                                                        <td class='description'>
+                                                            <?=$level->description?>
+                                                        </td>
+                                                    </tr>
+<?php
+                                                }
+                                            }
+?>
+                                        </table>
+<?php
+                                    }
+?>
+                                </div>
+<?php
+                            }
+?>
+                        </div> <!-- #skills -->
+                    </article>
+<?php
+                } // if ($page->monster[$i] != null)
+            } // for (int $i = 0; $i < 3; $i ++)
+?>
+        </section>
+<?php
+        include __DIR__ . "/inc/footer.php";
+?>
+    </body>
+</html>

+ 203 - 0
public/css/monster_info.css

@@ -0,0 +1,203 @@
+section#monster{
+    display: block;
+    width: 98%;
+    margin: auto;
+    text-align: center;
+}
+@media screen and (max-width : 990px){
+    section#monster{
+        width: 100%;
+    }
+}
+
+section#monster article.stage{
+    margin: 0.5em;
+    position: relative;
+    border-radius: 1em;
+    background: #351e0b;
+    border: 0.2em solid #f2c920;
+    padding: 0.3em;
+}
+
+section#monster article.stage div.profile{
+    display: inline-block;
+    vertical-align: top;
+}
+
+section#monster article.stage div.profile img.monster_image{
+    max-width: 12em;
+    max-height: 12em;
+    border-style: solid;
+    border-width: 0.3em;
+    border-radius: 15%;
+    display: inline-block;
+    vertical-align: top;
+    margin: 0 0.5em 1em 0.5em;
+}
+section#monster article.stage div.profile div.details{
+    display: inline-block;
+    vertical-align: top;
+    text-align: center;
+}
+section#monster article.stage div.profile div.details span.stars{
+    display: block;
+}
+section#monster article.stage div.profile div.details span.stars img.star{
+    width: 1em;
+    height: 1em;
+    filter: drop-shadow(0 0 0.05em #ffffff);
+    margin: -0.1em;
+}
+section#monster article.stage div.profile div.details span.archetype{
+    color: #ffffff;
+    display: block;
+    text-shadow: 0 0 0.2em #000000, 0 0 0.2em #000000;
+    font-size: 80%;
+}
+section#monster article.stage div.profile h4{
+    color: #ffffff;
+    font-weight: bold;
+    text-shadow: 0 0 0.2em #000000, 0 0 0.2em #000000, 0 0 0.4em #000000;
+    margin: 0.1em;
+    display: block;
+}
+
+section#monster article.stage table.stats{
+    font-size: 65%;
+    border: 0.1em solid black;
+    color: #ffffff;
+    margin: 0.4em;
+    border-collapse: collapse;
+    border-radius: 0.4em;
+    display: inline-block;
+    vertical-align: top;
+    max-width: 10em;
+}
+
+section#monster article.stage table.stats td,th{
+    padding: 0.01em 0.5em;
+    border: 0.1em solid #000000;
+}
+
+section#monster article.stage table.stats th{
+    font-weight: bold;
+    background-color: #00000066;
+}
+
+section#monster article.stage table.stats td{
+    font-weight: bold;
+    background-color: #ffffff33;
+}
+
+section#monster article.stage div.extra{
+    display: inline-block;
+}
+
+section#monster article.stage div.extra div.sources span{
+    display: block;
+    font-size: 70%;
+    margin: 0.5em 0 0 0;
+    color: #ffffff;
+}
+
+section#monster article.stage div.extra div.sources img.source{
+    width: 2em;
+    height: 2em;
+    border: 0.1em solid #f2c920;
+    border-radius: 0.3em;
+}
+
+section#monster article.stage div.extra div.essences span{
+    display: block;
+    font-size: 70%;
+    margin: 0.5em 0 0 0;
+    color: #ffffff;
+}
+
+section#monster article.stage div.extra div.essences div.essence{
+    position: relative;
+    display: inline-block;
+    vertical-align: top;
+    border-style: solid;
+    border-width: 0.1em;
+    border-radius: 15%;
+    width: 1.3em;
+    height: 1.3em;
+    margin-bottom: 0.1em;
+}
+section#monster article.stage div.extra div.essences div.essence img{
+    position: absolute;
+    top: 0;
+    left: 0;
+    width: 1.5em;
+    height: 1.5em;
+}
+section#monster article.stage div.extra div.essences div.essence span{
+    position: absolute;
+    font-size: 80%;
+    top: 0.15em;
+    left: 0.8em;
+    color: #ffffff;
+    text-shadow: 0 0 0.1em #000000, 0 0 0.1em #000000, 0 0 0.2em #000000, 0 0 0.2em #000000;
+}
+
+section#monster article.stage div.skills{
+    text-align: center;
+}
+
+section#monster article.stage div.skills div.skill{
+    display: inline-block;
+    vertical-align: top;
+    margin: 0.5em;
+    color: #ffffff;
+    text-align: center;
+    max-width: 20%;
+}
+
+section#monster article.stage div.skills div.skill img.skill_img{
+    width: 4em;
+    height: 4em;
+    border: 0.2em solid #f2c920;
+    border-radius: 0.4em;
+}
+
+section#monster article.stage div.skills div.skill span.skill_name{
+    text-shadow: 0 0 0.2em #000000, 0 0 0.2em #000000, 0 0 0.4em #000000;
+    display: block;
+    font-weight: bold;
+    font-size: 90%;
+}
+
+section#monster article.stage div.skills div.skill span.skill_description{
+    font-size: 70%;
+    font-style: italic;
+}
+
+section#monster article.stage div.skills div.skill span.skill_effects{
+    display: block;
+    text-align: center;
+    margin-top: 1em;
+}
+
+section#monster article.stage div.skills div.skill span.skill_effects img.effect_img{
+    width: 1.5em;
+    height: 1.5em;
+    border: 0.1em solid #000000;
+    border-radius: 0.5em;
+}
+
+section#monster article.stage div.skills div.skill table.skill_up{
+    font-size: 70%;
+    margin-top: 1em;
+}
+
+section#monster article.stage div.skills div.skill table.skill_up td{
+    color: #ffffff;
+    padding: 0.03em 0.3em;
+}
+
+section#monster article.stage div.skills div.skill table.skill_up td.level{
+    font-style: italic;
+    padding-right: 0.8em;
+    min-width: 3em; 
+}