Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class map{
- private $sql;
- private $uniqueId;
- private $easyName;
- private $cellData;
- private $cellAttributes;
- public function saveMap(){
- $check = "SELECT entry_id FROM maps WHERE map_id = {$this->uniqueId}";
- $exe = $this->sql->query($check);
- $save = array();
- if($exe->num_rows > 1){
- foreach($this->cellData AS $z => $cell){
- foreach ($cell AS $xy => $style) {
- $save[] = "UPDATE maps SET style = '{$style}' WHERE map_id = {$this->uniqueId} AND xy = '{$xy}';" . "\n";
- }
- }
- $save[] = "UPDATE map_names SET name = '{$this->easyName}' WHERE map_id = {$this->uniqueId}";
- }else{
- foreach($this->cellData AS $z => $cell){
- foreach ($cell AS $xy => $style) {
- $save[] = "INSERT INTO maps (map_id, style, xy) VALUES ({$this->uniqueId},'{$style}','{$xy}');" . "\n";
- }
- }
- $save[] = "INSERT INTO map_names (name, map_id) VALUES ('{$this->easyName}',{$this->uniqueId})";
- }
- foreach ($this->cellAttributes as $cellid => $data) {
- $check = "SELECT entry_id FROM map_cell_data WHERE cellxy = '{$cellid}' AND map_id = {$this->uniqueId}";
- $exe = $this->sql->query($check);
- if($exe->num_rows > 1){
- $save[] = "UPDATE map_cell_data SET data = '{$data}' WHERE map_id = {$this->uniqueId} AND cellxy = '{$cellid}';" . "\n";
- }else{
- $save[] = "INSERT INTO map_cell_data (map_id, data, cellxy) VALUES ({$this->uniqueId},'{$data}','{$cellid}');" . "\n";
- }
- }
- foreach($save as $z => $q){
- $exe = $this->sql->query($q);
- if($this->sql->error){
- echo $this->sql->error;
- echo $q;
- }
- }
- }
- public function loadMap($p = false){
- $getData = "SELECT maps.map_id AS mid, maps.style AS style, maps.xy AS xy, map_cell_data.cellxy AS cxy, map_cell_data.data AS data FROM maps LEFT JOIN map_cell_data ON map_cell_data.map_id = maps.map_id WHERE maps.map_id = {$this->uniqueId}";
- $exe = $this->sql->query($getData);
- if($this->sql->error){
- echo $this->sql->error;
- }
- $cellData = array();
- $cellAttr = array();
- while($r = $exe->fetch_array()){
- $cellData[$r['xy']] = $r['style'];
- $cellAttr[$r['cxy']] = $r['data'];
- if(!isset($mid)){
- $mid = $r['mid'];
- }
- }
- $cols = 25;
- $rows = 20;
- $grid = "";
- if($p == true){
- $grid .= '<div id="playArea">';
- $grid .= '<div id="moving"><div id="toonSprite"></div></div>';
- }
- $grid .= "<div id='gridWrap' data-mapid='{$mid}'>";
- for($r=0;$r<$rows;$r++){
- $r2 = $r *32;
- for($c=0;$c<$cols;$c++){
- $c2 = $c*32;
- $cellClass = "";
- $dataxyz = " data-xyz='0,0,0'";
- if(isset($cellAttr[$c2."|".$r2])){
- if($cellAttr[$c2."|".$r2] == "nomove"){
- $cellClass = " nomove";
- }elseif($cellAttr[$c2."|".$r2] != ""){
- $cellClass = " warpto";
- $dataxyz = " data-xyz='{$cellAttr[$c2."|".$r2]}'";
- }
- }
- $grid .= "<div id='{$c2}-{$r2}cell' class='cell{$cellClass}'{$dataxyz} data-x='{$c2}' data-y='{$r2}'><div style='background: " . $cellData[$c."|".$r."layer1"] . "' class='layer1' id='{$c}|{$r}layer1'></div><div style='background: " . $cellData[$c."|".$r."layer2"] . "' class='layer2' id='{$c}|{$r}layer2'></div><div style='background: " . $cellData[$c."|".$r."mask1"] . "' class='mask1' id='{$c}|{$r}mask1'></div><div data-x='{$c}' data-y='{$r}' style='background: " . $cellData[$c."|".$r."mask2"] . "' class='mask2' id='{$c}|{$r}mask2'></div></div>";
- }
- $grid .= "<div class='c'></div>";
- }
- $grid .= "</div>";
- if($p == true){
- $grid .= '</div>';
- }
- return $grid;
- }
- public function preLoadMap(){
- $getData = "SELECT maps.style AS style, maps.xy AS xy, map_cell_data.cellxy AS cxy, map_cell_data.data AS data FROM maps LEFT JOIN map_cell_data ON map_cell_data.map_id = maps.map_id WHERE maps.map_id = {$this->uniqueId}";
- $exe = $this->sql->query($getData);
- if($this->sql->error){
- echo $this->sql->error;
- }
- $cellData = array();
- $cellAttr = array();
- while($r = $exe->fetch_array()){
- $cellData[$r['xy']] = $r['style'];
- $cellAttr[$r['cxy']] = $r['data'];
- }
- $cols = 25;
- $rows = 20;
- $grid = "<div id='preLoad{$this->uniqueId}'>";
- for($r=0;$r<$rows;$r++){
- $r2 = $r *32;
- for($c=0;$c<$cols;$c++){
- $c2 = $c*32;
- $cellClass = "";
- $dataxyz = " data-xyz='0,0,0'";
- if(isset($cellAttr[$c2."|".$r2])){
- if($cellAttr[$c2."|".$r2] == "nomove"){
- $cellClass = " nomove";
- }elseif($cellAttr[$c2."|".$r2] != ""){
- $cellClass = " warpto";
- $dataxyz = " data-xyz='{$cellAttr[$c2."|".$r2]}'";
- }
- }
- $grid .= "<div id='{$c2}-{$r2}cell' class='cell{$cellClass}'{$dataxyz} data-x='{$c2}' data-y='{$r2}'><div style='background: " . $cellData[$c."|".$r."layer1"] . "' class='layer1' id='{$c}|{$r}layer1'></div><div style='background: " . $cellData[$c."|".$r."layer2"] . "' class='layer2' id='{$c}|{$r}layer2'></div><div style='background: " . $cellData[$c."|".$r."mask1"] . "' class='mask1' id='{$c}|{$r}mask1'></div><div data-x='{$c}' data-y='{$r}' style='background: " . $cellData[$c."|".$r."mask2"] . "' class='mask2' id='{$c}|{$r}mask2'></div></div>";
- }
- $grid .= "<div class='c'></div>";
- }
- $grid .= "</div>";
- return $grid;
- }
- function __construct($data){
- $this->sql = new mysqli(sqlhost,sqluser,sqlpass,sqldb);
- if(isset($data['uniqueid'])){
- $this->uniqueId = $this->sql->escape_string($data['uniqueid']);
- }
- if(isset($data['easyName'])){
- $this->easyName = $this->sql->escape_string($data['easyName']);
- $this->easyName = str_replace(" ","_",$this->easyName);
- }
- if(isset($data['layer1'])){
- $this->cellData['layer1'] = $data['layer1'];
- $this->cellData['layer2'] = $data['layer2'];
- $this->cellData['mask1'] = $data['mask1'];
- $this->cellData['mask2'] = $data['mask2'];
- $this->cellAttributes = $data['cells'];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement