From 8120873e7ddac228c72f7333d6ca7246319ca2da Mon Sep 17 00:00:00 2001
From: Fibinger Ádám <adam.fibinger@wup.hu>
Date: Thu, 10 Oct 2019 19:57:11 +0200
Subject: [PATCH] Overlay generator form skeleton

---
 EOG/Models/Stripe.php |  241 +++++++++++++++++++++++++++--------------------
 1 files changed, 139 insertions(+), 102 deletions(-)

diff --git a/EOG/Models/Stripe.php b/EOG/Models/Stripe.php
index dce29c0..0f91067 100644
--- a/EOG/Models/Stripe.php
+++ b/EOG/Models/Stripe.php
@@ -4,123 +4,160 @@
 
 class Stripe
 {
-    const TEAM_BLUE = 'blue';
-    const TEAM_ORANGE = 'orange';
+	const TEAM_BLUE = 'blue';
+	const TEAM_ORANGE = 'orange';
 
-    private $allowedColors = [self::TEAM_BLUE, self::TEAM_ORANGE];
-    private $allowedStripeClasses = ['team', 'simple'];
-    private $allowedOperators = [
-        'alibi', 'amaru', 'ash', 'bandit', 'blackbeard', 'blitz', 'buck', 'capitao', 'castle',
-        'caveira', 'clash', 'doc', 'dokkaebi', 'echo', 'ela', 'finka', 'frost', 'fuze',
-        'glaz', 'goyo', 'gridlock', 'hibana', 'iq', 'jackal', 'jager', 'kaid', 'kapkan',
-        'lesion', 'lion', 'maestro', 'maverick', 'mira', 'montagne', 'mozzie', 'mute', 'nokk',
-        'nomad', 'pulse', 'rook', 'sledge', 'smoke', 'tachanka', 'thatcher', 'thermite', 'twitch',
-        'valkyrie', 'vigil', 'warden', 'ying', 'zofia'];
-    protected $state = [
-        'stripe' => [
-            'class' => 'team',
-        ],
-        'cup' => [
-            'number' => '#75',
-            'name' => '5on5 Open Cup',
-        ],
-        'team' => [
-            'orange' =>
-                [
-                    'name' => 'Narancs Csapat',
-                    'ban' => [
-                        'mira',
-                        'jackal'
-                    ]
-                ],
-            'blue' => [
-                'name' => 'Kék csapat',
-                'ban' => [
-                    'rook',
-                    'blitz'
-                ]
-            ]
-        ]
-    ];
+	private $allowedColors = [self::TEAM_BLUE, self::TEAM_ORANGE];
+	private $allowedStripeClasses = ['team', 'simple', 'team-ban'];
+	private $allowedOperators = [
+		'alibi', 'amaru', 'ash', 'bandit', 'blackbeard', 'blitz', 'buck', 'capitao', 'castle',
+		'caveira', 'clash', 'doc', 'dokkaebi', 'echo', 'ela', 'finka', 'frost', 'fuze',
+		'glaz', 'goyo', 'gridlock', 'hibana', 'iq', 'jackal', 'jager', 'kaid', 'kapkan',
+		'lesion', 'lion', 'maestro', 'maverick', 'mira', 'montagne', 'mozzie', 'mute', 'nokk',
+		'nomad', 'pulse', 'rook', 'sledge', 'smoke', 'tachanka', 'thatcher', 'thermite', 'twitch',
+		'valkyrie', 'vigil', 'warden', 'ying', 'zofia'];
+	protected $state = [
+		'stripe' => [
+			'class' => 'team',
+		],
+		'cup'    => [
+			'number' => '#75',
+			'name'   => '5on5 Open Cup',
+		],
+		'team'   => [
+			'orange' =>
+				[
+					'name' => 'Narancs Csapat',
+					'ban'  => [
+						'mira',
+						'jackal'
+					]
+				],
+			'blue'   => [
+				'name' => 'Kék csapat',
+				'ban'  => [
+					'rook',
+					'blitz'
+				]
+			]
+		]
+	];
 
-    public function setClass(string $class): self
-    {
-        if (!in_array($class, $this->allowedStripeClasses)) {
-            throw new \InvalidArgumentException("Given class " . $class . " not allowed. Allowed classes: " . implode(', ', $this->allowedStripeClasses));
-        }
+	public function setClass(string $class): self
+	{
+		if (!in_array($class, $this->allowedStripeClasses))
+		{
+			throw new \InvalidArgumentException("Given class " . $class . " not allowed. Allowed classes: " . implode(', ', $this->allowedStripeClasses));
+		}
 
-        if ($class === 'simple') {
-            $this->setSimpleStripe();
-        }
+		if ($class === 'simple')
+		{
+			$this->setSimpleStripe();
+		}
 
-        $this->state['stripe']['class'] = $class;
+		$this->state['stripe']['class'] = $class;
 
-        return $this;
-    }
+		return $this;
+	}
 
-    private function setSimpleStripe()
-    {
-        unset($this->state['team']);
-    }
+	private function setSimpleStripe()
+	{
+		unset($this->state['team']);
+	}
 
-    public function setCup(string $number, string $name)
-    {
-        $this->state['cup']['number'] = $number;
-        $this->state['cup']['name'] = $name;
-    }
+	public function setCup(string $number, string $name)
+	{
+		$this->state['cup']['number'] = $number;
+		$this->state['cup']['name'] = $name;
+	}
 
-    /**
-     * @param string $color Csapat szín validáció
-     *
-     * Dob egy Exception-t ha nem orange / blue
-     */
-    private function testColor(string $color)
-    {
-        if (!in_array($color, $this->allowedColors)) {
-            throw new \InvalidArgumentException("Given colour " . $team_color . " not allowed. Allowed colours: " . implode(', ', $this->allowedColors));
-        }
-    }
+	/**
+	 * @param string $color Csapat szín validáció
+	 *
+	 * Dob egy Exception-t ha nem orange / blue
+	 */
+	private function testColor(string $color)
+	{
+		if (!in_array($color, $this->allowedColors))
+		{
+			throw new \InvalidArgumentException("Given colour " . $team_color . " not allowed. Allowed colours: " . implode(', ', $this->allowedColors));
+		}
+	}
 
-    public function setTeamName(string $team_color = self::TEAM_BLUE, $name)
-    {
-        $this->testColor($team_color);
-        $this->state['team'][$team_color]['name'] = $name;
-    }
+	public function setTeamName(string $team_color = self::TEAM_BLUE, $name)
+	{
+		$this->testColor($team_color);
+		$this->state['team'][$team_color]['name'] = $name;
+	}
 
-    public function addTeamBan(string $team_color = self::TEAM_BLUE, $operator)
-    {
-        $this->testColor($team_color);
-        if (!in_array($operator, $this->allowedOperators)) {
-            //FIXME: védő és támadó operátorok külön
-            throw new \InvalidArgumentException("Given operator not allowed:  " . $operator . " Allowed operators: " . implode(', ', $this->allowedOperators));
-        }
-    }
+	public function addTeamBan(string $team_color = self::TEAM_BLUE, $operator)
+	{
+		$this->testColor($team_color);
+		if (!in_array($operator, $this->allowedOperators))
+		{
+			//FIXME: védő és támadó operátorok külön
+			throw new \InvalidArgumentException("Given operator not allowed:  " . $operator . " Allowed operators: " . implode(', ', $this->allowedOperators));
+		}
+	}
 
-    public function __get($name)
-    {
-        if ($this->__isset($name)) {
-            return $this->state[$name];
-        }
+	public function __get($name)
+	{
+		if ($this->__isset($name))
+		{
+			return $this->state[$name];
+		}
 
-        return null;
-    }
+		return null;
+	}
 
-    public function __isset($name)
-    {
-        return isset($this->state[$name]);
-    }
+	public function __isset($name)
+	{
+		return isset($this->state[$name]);
+	}
 
-    public function loadJson(string $json)
-    {
-        $state = json_decode($json);
+	public function loadJson(string $json)
+	{
+		$state = json_decode($json);
 
-        if (!empty($state['stripe']["class"])) {
-            $this->setClass($state['stripe']["class"]);
-        }
+		unset($this->state);
+		$this->state = [];
 
-        if (!empty($state['cup']['name']) && !empty($state['cup']['number'])) {
-            $this->setCup($state['cup']['number'], $state['cup']['name']);
-        }
+		if (!empty($state['stripe']["class"]))
+		{
+			$this->setClass($state['stripe']["class"]);
+		}
 
-    }
+		if (!empty($state['cup']['name']) && !empty($state['cup']['number']))
+		{
+			$this->setCup($state['cup']['number'], $state['cup']['name']);
+		}
+
+		if (!empty($state['team']))
+		{
+			foreach ([self::TEAM_BLUE, self::TEAM_ORANGE] as $color)
+			{
+				if (!empty($state['team'][$color]['name']))
+				{
+					$this->setTeamName($color, $state['team'][$color]['name']);
+				}
+
+				if (!empty($state['team'][$color]['ban']) && is_array($state['team'][$color]['ban']))
+				{
+					foreach ($state['team'][$color]['ban'] as $operator)
+					{
+						$this->addTeamBan($color, $operator);
+					}
+				}
+			}
+		}
+	}
+
+	public function getJson()
+	{
+		return json_encode($this->state);
+	}
+
+	public function getOperators() {
+		return $this->allowedOperators;
+	}
 }
\ No newline at end of file

--
Gitblit v1.8.0