more fixes to loading of creatures

fixed when there are spaces at beginning of the file
fixed when file is unable to parse
This commit is contained in:
slawkens1 2017-06-07 00:16:04 +02:00
parent 57c2547098
commit 649facc5ab
3 changed files with 16 additions and 1 deletions

View File

@ -39,6 +39,16 @@
*/
class OTS_Monster extends DOMDocument
{
private $loaded = false;
public function loadXML($source , $options = 0)
{
$this->loaded = parent::loadXML($source, $options);
}
public function loaded()
{
return $this->loaded;
}
/**
* Returns monster name.
*

View File

@ -117,7 +117,8 @@ class OTS_MonstersList implements Iterator, Countable, ArrayAccess
{
// loads file
$monster = new OTS_Monster();
$monster->load($this->monstersPath . $this->monsters[$name]);
//echo $this->monstersPath . $this->monsters[$name];
$monster->loadXML(trim(file_get_contents($this->monstersPath . $this->monsters[$name])));
return $monster;
}

View File

@ -72,6 +72,10 @@ if(isset($_POST['reload_monsters']) && $canEdit)
//add monsters
foreach($allmonsters as $lol) {
$monster = $allmonsters->current();
if(!$monster->loaded()) {
warning('Error while adding monster: ' . $allmonsters->currentFile());
continue;
}
//load monster mana needed to summon/convince
$mana = $monster->getManaCost();
//load monster experience