Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds static maps #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ matrix:
include:
- php: 5.5
env: setup=lowest
- php: 5.5
- php: 5.6
env: setup=stable
- php: 5.6
env: setup=phar
Expand Down
27 changes: 27 additions & 0 deletions src/Common/APIObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


namespace GW2Treasures\GW2Tools\Common;


class APIObject {
public static function fromObject(\stdClass $object) {
$itemStack = new static();

foreach ($object as $property => &$value) {
$itemStack->{$property} = $value;
}

return $itemStack;
}

public static function fromArray(array $array) {
$itemStack = new static();

foreach ($array as $property => &$value) {
$itemStack->{$property} = $value;
}

return $itemStack;
}
}
20 changes: 20 additions & 0 deletions src/Common/Continent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php


namespace GW2Treasures\GW2Tools\Common;


class Continent extends APIObject {
/** @var int $id */
public $id = 0;

public $name = "";

public $continent_dims = [];

public $min_zoom = 0;

public $max_zoom = 0;

public $floors = [];
}
22 changes: 1 addition & 21 deletions src/Common/ItemStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GW2Treasures\GW2Tools\Common;

class ItemStack extends \stdClass {
class ItemStack extends APIObject {
/** @var int $count */
public $count = 1;

Expand All @@ -14,24 +14,4 @@ class ItemStack extends \stdClass {

/** @var int */
public $skin = null;

public static function fromObject(\stdClass $object) {
$itemStack = new ItemStack();

foreach ($object as $property => &$value) {
$itemStack->{$property} = $value;
}

return $itemStack;
}

public static function fromArray(array $array) {
$itemStack = new ItemStack();

foreach ($array as $property => &$value) {
$itemStack->{$property} = $value;
}

return $itemStack;
}
}
18 changes: 18 additions & 0 deletions src/Common/Map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php


namespace GW2Treasures\GW2Tools\Common;


class Map extends APIObject {
/** @var int $id */
public $id = 0;

public $continent_id = 0;

public $default_floor = 0;

public $map_rect = [];

public $continent_rect = [];
}
85 changes: 85 additions & 0 deletions src/Maps/Coordinate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php


namespace GW2Treasures\GW2Tools\Maps;


class Coordinate {
public $x, $y;

/**
* Coordinate constructor.
*
* @param float $x
* @param float $y
*/
public function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}

public static function fromArray(array $array) {
return new Coordinate($array[0], $array[1]);
}

public function multiply($x, $y = null) {
if($y == null) {
$y = $x;
}

return new Coordinate(
$this->x * $x,
$this->y * $y
);
}

public function add($x, $y = null) {
if($y == null) {
$y = $x;
}

return new Coordinate(
$this->x + $x,
$this->y + $y
);
}

public function subtract($x, $y = null) {
if($y == null) {
$y = $x;
}

return new Coordinate(
$this->x - $x,
$this->y - $y
);
}

public function floor() {
return new Coordinate(floor($this->x), floor($this->y));
}

public function round() {
return new Coordinate(round($this->x), round($this->y));
}

public function ceil() {
return new Coordinate(ceil($this->x), ceil($this->y));
}

public function distance(Coordinate $other) {
return sqrt($this->distanceSquared($other));
}

public function distanceSquared(Coordinate $other) {
return pow($this->x - $other->x, 2) + pow($this->y - $other->y, 2);
}

public function min(Coordinate $other) {
return new Coordinate(min($this->x, $other->x), min($this->y, $other->y));
}

public function max(Coordinate $other) {
return new Coordinate(max($this->x, $other->x), max($this->y, $other->y));
}
}
Loading