Skip to content

Example: Item list (items.xml)

Chris edited this page Feb 15, 2017 · 3 revisions

DEPRECATED!

This wiki page has been deprecated and refers to version 1.0 of the project. Please refer to the main README for the latest documentation.


Options

The parser implementation (pandaac\Exporter\Parsers\Items in this case) accepts an array of options as its first parameter. By default they are as shown below, but you may pass either of them to change it.

Syntax
new pandaac\Exporter\Parsers\Items([
  'attributes' => true,
])
Defaults
  • attributes false
    • If attributes are enabled, it will fetch available attributes for each item
  • properties false
    • If properties are enabled, it will also fetch available properties for each item attribute. Requires the attributes option to be enabled

Example

use pandaac\Exporter\Exporter;
use pandaac\Exporter\Parsers\Items;

try {

  $items = new Exporter(
    './data/items/items.xml',
    new Items
  );

  $response = $items->export();

} catch (Exception $e) {
  // Log errors...
}

The export() method returns a Illuminate\Support\Collection object, please refer to its documentation. If you would prefer a JSON or an array response however, you may do as follows...

$response = $items->export()->toJson();
$response = $items->export()->toArray();

Example output with all options disabled (JSON)

[
  {
    "id": 106,
    "name": "grass"
  },
  {
    "fromid": 108,
    "toid": 109,
    "name": "flowers"
  },
  {
    "id": 194,
    "name": "dirt"
  },
  {
    "id": 231,
    "name": "sand"
  },
  {
    "id": 280,
    "name": "earth ground"
  },
  {
    "id": 293,
    "name": "grass"
  },
  {
    "id": 294,
    "name": "pitfall"
  },
  {
    "fromid": 351,
    "toid": 353,
    "name": "dirt floor"
  },
  {
    "id": 354,
    "name": "muddy floor"
  },
  {
    "id": 355,
    "name": "muddy floor"
  },
  {
    "fromid": 1423,
    "toid": 1425,
    "name": "campfire"
  },

  ...
]

Example output with all options enabled (JSON)

[
  {
    "id": 106,
    "name": "grass"
  },
  {
    "fromid": 108,
    "toid": 109,
    "name": "flowers"
  },
  {
    "id": 194,
    "name": "dirt"
  },
  {
    "id": 231,
    "name": "sand"
  },
  {
    "id": 280,
    "name": "earth ground"
  },
  {
    "id": 293,
    "name": "grass",
    "attributes": [
      {
        "key": "floorchange",
        "value": "down"
      }
    ]
  },
  {
    "id": 294,
    "name": "pitfall",
    "attributes": [
      {
        "key": "floorchange",
        "value": "down"
      },
      {
        "key": "decayTo",
        "value": 293
      },
      {
        "key": "duration",
        "value": 300
      }
    ]
  },
  {
    "fromid": 351,
    "toid": 353,
    "name": "dirt floor"
  },
  {
    "id": 354,
    "name": "muddy floor"
  },
  {
    "id": 355,
    "name": "muddy floor",
    "attributes": [
      {
        "key": "fluidSource",
        "value": "mud"
      }
    ]
  },
  {
    "fromid": 1423,
    "toid": 1425,
    "name": "campfire",
    "attributes": [
      {
        "key": "field",
        "value": "fire",
        "properties": [
          {
            "key": "damage",
            "value": 20
          },
          {
            "key": "ticks",
            "value": 4000
          },
          {
            "key": "count",
            "value": 2
          },
          {
            "key": "damage",
            "value": 10
          }
        ]
      }
    ]
  },

  ...
]