Update itemlistparser (#336)

* Improve itemlistparser. Remove ugly cache file

* Convert item id to int, remove items variable
This commit is contained in:
Alvaro Carvajal 2019-01-10 22:56:05 +01:00 committed by Stefan A. Brannfjell
parent 590dc37d28
commit f79a48fc06
3 changed files with 29 additions and 6425 deletions

View File

@ -1,14 +1,34 @@
<?php <?php
/* Returns a PHP array $id => 'name' /* Returns a PHP array $id => 'name'
$items = getItemList(); $items = getItemList();
echo $items[2160]; // Returns 'Crystal Coin' echo $items[2160]; // Returns 'Crystal Coin'
*/ */
function getItemList() { function getItemList() {
$item_list = explode(PHP_EOL, file_get_contents('item_list.txt')); return parseItems();
$ia = array();
for ($i = 0; $i < count($item_list) - 1; $i++) {
$it = explode('@', $item_list[$i]);
$ia[(int)$it[0]] = ucfirst($it[1]);
} }
return $ia;
function getItemById($id) {
$items = parseItems();
if(isset($items[$id])) {
return $items[$id];
}
return false;
}
function parseItems() {
global $config;
$items = simplexml_load_file($config['server_path'].'/data/items/items.xml');
$out = array();
// Create our parsed item list
foreach ($items->children() as $item) {
if ($item['id'] && $item['name'] != NULL) {
$out[(int)$item['id']] = (string)$item['name'];
}
}
return $out;
} }

View File

@ -1,18 +0,0 @@
<?php
$items = simplexml_load_file($config['server_path'].'/data/items/items.xml');
// Create our parsed item list
$item_list = fopen('item_list.txt', 'w');
foreach ($items->children() as $item) {
if ($item['id'] && $item['name'] != NULL) {
fwrite($item_list, $item['id'].'@'.$item['name'].PHP_EOL);
}
}
fclose($item_list);

File diff suppressed because it is too large Load Diff