diff --git a/README b/README index 748755a..521a398 100644 --- a/README +++ b/README @@ -2,32 +2,22 @@ Ship.js is a simple javascript library, to easily add ship fits to pages, where It depends on a php page to decode the ship dna into a useable form, which can be called from anywhere. A copy runs on my personal server, and I'm not planning on taking it down any time soon. - - Installing this into wordpress: - This was the initial reason for writing this code. In your theme header: Ensure the following exists. - - - - If any don't, make sure to add them. (the ship.js one almost certainly won't.) - Then, to use it:
- - -The ship in the insert ship call refers to the div before it. you can have multiple ships, by naming them differently. The long string is the ship DNA, as from http://wiki.eveonline.com/en/wiki/Ship_DNA +The ship in the insert ship call refers to the div before it. you can have multiple ships, by naming them differently. The long string is the ship DNA, as from http://wiki.eveonline.com/en/wiki/Ship_DNA \ No newline at end of file diff --git a/db.inc.php.example b/db.inc.php.example index e07347f..723dc88 100644 --- a/db.inc.php.example +++ b/db.inc.php.example @@ -1 +1,8 @@ - + diff --git a/dnagen.php b/dnagen.php index f41f1cb..6f8d645 100644 --- a/dnagen.php +++ b/dnagen.php @@ -1,26 +1,26 @@ - -DNA generator - - -

Ship DNA generator

-
-

Ship fitting goes here, in eft fitting form

-
- -

-Back to main menu - - +
+ + +
+ Back to main menu + + \ No newline at end of file diff --git a/eftconverter.php b/eftconverter.php index f2360a6..446a98d 100644 --- a/eftconverter.php +++ b/eftconverter.php @@ -1,173 +1,155 @@ - - -Ship DNA Generator - - - - - - -40 or (substr($shipdetails[0],0,1) != "[") ) -{ -echo "Too big or bad format"; -exit; -} - - -$shipname=trim($shipdetails[0],"["); - -$mods=array(); -$mods[$shipname]=1; -$inner=array_shift($fittingarray); -foreach ($fittingarray as $line) -{ - if (preg_match('/^(.*) x(\d+)$/',trim($line),$matches)) - { - if(array_key_exists($matches[1],$mods)) - { - $mods[$matches[1]]+=$matches[2]; - } - else - { - $mods[$matches[1]]=$matches[2]; - } +40 or (substr($shipdetails[0],0,1) != "[") ) { + echo "Too big or bad format"; + exit; + } + + $shipname=trim($shipdetails[0],"["); + + $mods=array(); + $mods[$shipname]=1; + $inner=array_shift($fittingarray); + foreach ($fittingarray as $line) { + if (preg_match('/^(.*) x(\d+)$/',trim($line),$matches)) { + if(array_key_exists($matches[1],$mods)) { + $mods[$matches[1]]+=$matches[2]; + } + else + { + $mods[$matches[1]]=$matches[2]; + } } - else if (!preg_match('/\[/',$line)) - { - $line=trim($line); - $moduledetail=explode(",",$line,2); - if(array_key_exists($moduledetail[0],$mods)) - { - $mods[$moduledetail[0]]++; + else if (!preg_match('/\[/',$line)) { + $line=trim($line); + $moduledetail=explode(",",$line,2); + if(array_key_exists($moduledetail[0],$mods)) { + $mods[$moduledetail[0]]++; + } + else + { + $mods[$moduledetail[0]]=1; + } + if (array_key_exists(1,$moduledetail)) { + if(array_key_exists(trim($moduledetail[1]),$mods)) { + $mods[trim($moduledetail[1])]++; } else { - $mods[$moduledetail[0]]=1; - } - if (array_key_exists(1,$moduledetail)) - { - if(array_key_exists(trim($moduledetail[1]),$mods)) - { - $mods[trim($moduledetail[1])]++; - } - else - { - $mods[trim($moduledetail[1])]=1; - } + $mods[trim($moduledetail[1])]=1; } + } } -} - + } -$sql="select invTypes.typeid,typename,COALESCE(effectid,categoryID) effectid from invTypes left join dgmTypeEffects on (dgmTypeEffects.typeid=invTypes.typeid and effectid in (11,12,13,2663,3772)), invGroups where invTypes.typename=? and invTypes.groupid=invGroups.groupid"; -$stmt = $dbh->prepare($sql); + $sql="select invTypes.typeid,typename,COALESCE(effectid,categoryID) effectid from invTypes left join dgmTypeEffects on (dgmTypeEffects.typeid=invTypes.typeid and effectid in (11,12,13,2663,3772)), invGroups where invTypes.typename=? and invTypes.groupid=invGroups.groupid"; + $stmt = $dbh->prepare($sql); -$high=array(); -$med=array(); -$low=array(); -$subsystem=array(); -$ammo=array(); -$rig=array(); -$drones=array(); + $high=array(); + $med=array(); + $low=array(); + $subsystem=array(); + $ammo=array(); + $rig=array(); + $drones=array(); - -foreach ($mods as $module=>$number) -{ + foreach ($mods as $module=>$number) { $stmt->execute(array($module)); - if ($row = $stmt->fetchObject()) - { - switch($row->effectid) - { - case 6: - $shipid=$row->typeid; - break; + if ($row = $stmt->fetchObject()) { + switch($row->effectid) { + case 6: + $shipid=$row->typeid; + break; case 8: - $ammo[$row->typeid]=(int)$number; - break; + $ammo[$row->typeid]=(int)$number; + break; case 11: - $low[$row->typeid]=(int)$number; - break; + $low[$row->typeid]=(int)$number; + break; case 12: - $high[$row->typeid]=(int)$number; - break; + $high[$row->typeid]=(int)$number; + break; case 13: - $med[$row->typeid]=(int)$number; - break; + $med[$row->typeid]=(int)$number; + break; case 18: - $drones[$row->typeid]=(int)$number; - break; + $drones[$row->typeid]=(int)$number; + break; case 2663: - $rig[$row->typeid]=(int)$number; - break; + $rig[$row->typeid]=(int)$number; + break; case 3772: - $subsystem[$row->typeid]=(int)$number; - break; - } + $subsystem[$row->typeid]=(int)$number; + break; + } } + } + + $dna=$shipid.":"; + + foreach ($subsystem as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":").":"; + + foreach ($high as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":").":"; + + foreach ($med as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":").":"; -} - -$dna=$shipid.":"; - - -foreach ($subsystem as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":").":"; - -foreach ($high as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":").":"; -foreach ($med as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":").":"; -foreach ($low as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":").":"; -foreach ($rig as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":").":"; -foreach ($drones as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":").":"; -foreach ($ammo as $module=>$number) -{ -$dna.=$module.";".$number.":"; -} -$dna=trim($dna,":")."::"; + foreach ($low as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":").":"; + + foreach ($rig as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":").":"; + + foreach ($drones as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":").":"; + + foreach ($ammo as $module=>$number) { + $dna.=$module.";".$number.":"; + } + + $dna=trim($dna,":")."::"; ?> -

fitting

- -
- - -
-Back to the generator - - + + + + Ship DNA Generator + + + +

fitting

+ +
+ + +
+ Back to the generator + + \ No newline at end of file diff --git a/parsedna.php b/parsedna.php index 07fb201..99e7038 100644 --- a/parsedna.php +++ b/parsedna.php @@ -1,101 +1,88 @@ -prepare($sql); -#$sql='select invTypes.typeid,typename,COALESCE(effectid,1) effectid from invTypes left join dgmTypeEffects on (dgmTypeEffects.typeid=invTypes.typeid and effectid in (11,12,13,2663,3772)) where invTypes.typeid=?'; -$sql='select invTypes.typeid,typename,COALESCE(effectid,categoryID) effectid from invTypes left join dgmTypeEffects on (dgmTypeEffects.typeid=invTypes.typeid and effectid in (11,12,13,2663,3772)), invGroups where invTypes.typeid=? and invTypes.groupid=invGroups.groupid'; -$stmt = $dbh->prepare($sql); - -$typenames=array(); -$typeslot=array(); -foreach ($innertypelist as $value) -{ + $typenames=array(); + $typeslot=array(); + foreach ($innertypelist as $value) { $stmt->execute(array($value)); - - if ($row = $stmt->fetchObject()) - { - $typenames[$row->typeid]=htmlentities($row->typename, ENT_QUOTES); - $typeslot[$row->typeid]=$row->effectid; + if ($row = $stmt->fetchObject()) { + $typenames[$row->typeid]=htmlentities($row->typename, ENT_QUOTES); + $typeslot[$row->typeid]=$row->effectid; } -} + } -$shiptype=''; -$shipid=''; -foreach ( $array as $value) -{ + $shiptype=''; + $shipid=''; + foreach ($array as $value) { $types=explode(";",$value); - $types[0]=filter_var($types[0],FILTER_SANITIZE_NUMBER_INT); + $types[0]=filter_var($types[0],FILTER_SANITIZE_NUMBER_INT); $types[1]=filter_var($types[1],FILTER_SANITIZE_NUMBER_INT); - if ($types[0]) - { - switch($typeslot[$types[0]]) - { + if ($types[0]) { + switch($typeslot[$types[0]]) { case 6: - $shipid=$types[0]; - $shiptype= $typenames[$shipid]; - break; + $shipid=$types[0]; + $shiptype= $typenames[$shipid]; + break; case 11: - $low[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); - break; + $low[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); + break; case 12: - $high[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); - break; + $high[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); + break; case 13: - $med[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); - break; + $med[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); + break; case 2663: - $rig[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); - break; + $rig[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); + break; case 3772: - $subsystem[]=array($typenames[$types[0]].":".$types[0]=>1); - break; - case 18: - $drones[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); - break; - case 8: - $charge[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); - break; - - } + $subsystem[]=array($typenames[$types[0]].":".$types[0]=>1); + break; + case 18: + $drones[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); + break; + case 8: + $charge[]=array($typenames[$types[0]].":".$types[0]=>(int)$types[1]); + break; + } } -} -$json=array(); -$json["ship"]=array("shipname"=>$shiptype,"shipid"=>$shipid,"dna"=>$dna); -$json["high"]=$high; -$json["medium"]=$med; -$json["low"]=$low; -$json["rig"]=$rig; -$json["subsystem"]=$subsystem; -$json["drones"]=$drones; -$json["charge"]=$charge; + } -echo json_encode($json); + $json=array(); + $json["ship"]=array("shipname"=>$shiptype,"shipid"=>$shipid,"dna"=>$dna); + $json["high"]=$high; + $json["medium"]=$med; + $json["low"]=$low; + $json["rig"]=$rig; + $json["subsystem"]=$subsystem; + $json["drones"]=$drones; + $json["charge"]=$charge; + echo json_encode($json); ?> diff --git a/ship.js b/ship.js index 695349a..ca7f749 100644 --- a/ship.js +++ b/ship.js @@ -1,139 +1,137 @@ -function insertship(div,dna) -{ - -highslot=["left: 75px; top: 90px", "left: 105px; top: 65px", "left: 140px; top: 47px", "left: 178px; top: 37px", "left: 212px; top: 37px", "left: 253px; top: 43px", "left: 287px; top: 63px", "left: 315px; top: 90px"]; -medslot=["left: 45px; top: 142px", "left: 37px; top: 180px", "left: 38px; top: 220px", "left: 49px; top: 257px", "left: 69px; top: 290px", "left: 100px; top:315px", "left: 128px; top: 332px", "left: 165px; top: 347px"]; -lowslot=["left: 228px; top: 355px", "left: 267px; top: 343px", "left: 300px; top: 320px", "left: 328px; top: 292px", "left: 345px; top: 260px", "left: 355px; top: 223px", "left: 353px; top: 185px", "left: 350px; top: 145px"]; -rigslot=["left: 120px; top: 228px", "left: 150px; top: 263px", "left: 192px; top: 276px"]; -subsystem=["left: 122px; top: 163px","left: 153px; top: 130px","left: 195px; top: 115px","left: 241px; top: 129px","left: 270px; top: 165px"]; - - - - var Url = "https://www.fuzzwork.co.uk/ships/parsedna.php?dna="+dna; - -jQuery.get(Url,function(json){ - - shipdisplay="
"; - shipdisplay=shipdisplay+"
"; - - - slot=1; - for (var i = 0; i < json["high"].length; i++) - { - - for (var key in json["high"][i]) - { - for (var num=0; num
"; - slot++; - } - } - } - - - slot=1; - for (var i = 0; i < json["medium"].length; i++) - { - - for (var key in json["medium"][i]) - { - for (var num=0; num"; - slot++; - } - } - } - - - - slot=1; - for (var i = 0; i < json["low"].length; i++) - { - - for (var key in json["low"][i]) - { - for (var num=0; num"; - slot++; - } - } - } - - - - - - - - slot=1; - for (var i = 0; i < json["rig"].length; i++) - { - - for (var key in json["rig"][i]) - { - for (var num=0; num"; - slot++; - } - } - } - - slot=1; - for (var i = 0; i < json["subsystem"].length; i++) - { - - for (var key in json["subsystem"][i]) - { - for (var num=0; num"; - slot++; - } - } - } - slot=1; - topspace=37; - left=400; - for (var i = 0; i < json["drones"].length; i++) - { - - for (var key in json["drones"][i]) - { - parts=key.split(':'); - shipdisplay+="
"; - topspace=topspace+35; - slot++; - } - } - slot=1 - topspace=topspace+35 - for (var i = 0; i < json["charge"].length; i++) - { - - for (var key in json["charge"][i]) - { - parts=key.split(':'); - shipdisplay+="
"; - topspace=topspace+35; - slot++; - } - } -shipdisplay+=""; - - document.getElementById(div).innerHTML=shipdisplay; - -}); - -} - - - +'use strict' + +function insertShip(div, dna) { + + var highSlot = ["left: 75px; top: 90px", "left: 105px; top: 65px", "left: 140px; top: 47px", "left: 178px; top: 37px", "left: 212px; top: 37px", "left: 253px; top: 43px", "left: 287px; top: 63px", "left: 315px; top: 90px"], + medSlot = ["left: 45px; top: 142px", "left: 37px; top: 180px", "left: 38px; top: 220px", "left: 49px; top: 257px", "left: 69px; top: 290px", "left: 100px; top:315px", "left: 128px; top: 332px", "left: 165px; top: 347px"], + lowSlot = ["left: 228px; top: 355px", "left: 267px; top: 343px", "left: 300px; top: 320px", "left: 328px; top: 292px", "left: 345px; top: 260px", "left: 355px; top: 223px", "left: 353px; top: 185px", "left: 350px; top: 145px"], + rigSlot = ["left: 120px; top: 228px", "left: 150px; top: 263px", "left: 192px; top: 276px"], + subSystem = ["left: 122px; top: 163px", "left: 153px; top: 130px", "left: 195px; top: 115px", "left: 241px; top: 129px", "left: 270px; top: 165px"], + url = "https://www.fuzzwork.co.uk/ships/parsedna.php?dna=" + dna, + xmlHttp = new XMLHttpRequest(), + shipDisplay = "", + slot = 1, + i = 0, + key, num = 0, + json, parts, topSpace, left, shipDisplay; + + xmlHttp.open("GET", url, true); + + xmlHttp.onload = function(e) { + if (xmlHttp.readyState === 4) { + if (xmlHttp.status === 200) { + json = JSON.parse(xmlHttp.responseText); + + shipDisplay = "
"; + + shipDisplay += "
"; + + if (json.hasOwnProperty("high")) { + for (i = 0; i < json.high.length; i++) { + for (key in json.high[i]) { + for (num = 0; num < json.high[i][key]; num++) { + parts = key.split(':'); + shipDisplay += "
"; + slot++; + }; + }; + }; + }; + + slot = 1; + if (json.hasOwnProperty("medium")) { + for (var i = 0; i < json.medium.length; i++) { + for (var key in json.medium[i]) { + for (var num = 0; num < json.medium[i][key]; num++) { + parts = key.split(':'); + shipDisplay += "
"; + slot++; + }; + }; + }; + }; + + slot = 1; + if (json.hasOwnProperty("low")) { + for (var i = 0; i < json.low.length; i++) { + for (var key in json.low[i]) { + for (var num = 0; num < json.low[i][key]; num++) { + parts = key.split(':'); + shipDisplay += "
"; + slot++; + }; + }; + }; + }; + + slot = 1; + if (json.hasOwnProperty("rig")) { + for (var i = 0; i < json.rig.length; i++) { + for (var key in json.rig[i]) { + for (var num = 0; num < json.rig[i][key]; num++) { + parts = key.split(':'); + shipDisplay += "
"; + slot++; + }; + }; + }; + }; + + slot = 1; + if (json.hasOwnProperty("subsystem")) { + for (var i = 0; i < json.subsystem.length; i++) { + for (var key in json.subsystem[i]) { + for (var num = 0; num < json.subsystem[i][key]; num++) { + parts = key.split(':'); + shipDisplay += "
"; + slot++; + }; + }; + }; + }; + + slot = 1; + topSpace = 37; + left = 400; + + if (json.hasOwnProperty("drones")) { + for (var i = 0; i < json.drones.length; i++) { + for (var key in json.drones[i]) { + parts = key.split(':'); + shipDisplay += "
"; + topSpace = topSpace + 35; + slot++; + }; + }; + }; + + slot = 1; + topSpace = topSpace + 35; + + if (json.hasOwnProperty("charge")) { + for (var i = 0; i < json.charge.length; i++) { + for (var key in json.charge[i]) { + parts = key.split(':'); + shipDisplay += "
"; + topSpace = topSpace + 35; + slot++; + }; + }; + }; + + shipDisplay += "
"; + document.getElementById(div).innerHTML = shipDisplay; + } else { + shipDisplay = '
There was an error when requesting the ships fitting.
'; + document.getElementById(div).innerHTML = shipDisplay; + }; + }; + }; + + xmlHttp.onerror = function(e) { + console.error(xhr.statusText); + }; + + xmlHttp.send(); + return false; +}; \ No newline at end of file diff --git a/test.html b/test.html index 6f425f1..b02414d 100644 --- a/test.html +++ b/test.html @@ -1,14 +1,16 @@ -Ship test - - - - -
-
- - + + Ship test + + + + + +
+
+ +