Tabs.class.php 1.47 KB
Newer Older
Erwan Normand's avatar
Erwan Normand committed
1
2
<?php

Erwan Normand's avatar
Rename  
Erwan Normand committed
3
class Tabs
Erwan Normand's avatar
Erwan Normand committed
4
{
Erwan Normand's avatar
Erwan Normand committed
5
6
	private static $tabwidth = 40;
	private static $tabheight = 31;
Erwan Normand's avatar
Erwan Normand committed
7
8
	private $mapwidth;
	private $mapheight;
Erwan Normand's avatar
Rename  
Erwan Normand committed
9
10
	private $tabsRaw;
	private $tabs;
Erwan Normand's avatar
Erwan Normand committed
11
12
	
	public function __construct() {
Erwan Normand's avatar
Rename  
Erwan Normand committed
13
		$this->tabsRaw = null;
Erwan Normand's avatar
Erwan Normand committed
14
15
		$this->mapwidth = 5;
		$this->mapheight = 5;
16

Orbmancer's avatar
Orbmancer committed
17
18
19
20
21
		$this->contents = array();

        for($i=1; $i<=5; ++$i)
            for($j=1; $j<=5; ++$j)
                $this->contents[$i][$j] = array();
22

Erwan Normand's avatar
Erwan Normand committed
23
24
25
26
	}
	
	public function importXML($string) {
		$xml = simplexml_load_string($string);
Erwan Normand's avatar
Rename  
Erwan Normand committed
27
		$this->tabsRaw = $xml->Data->tabs->__toString();
Erwan Normand's avatar
Erwan Normand committed
28
		
Erwan Normand's avatar
Rename  
Erwan Normand committed
29
		$tabs = explode(',', $this->tabsRaw);
Orbmancer's avatar
Orbmancer committed
30
31
32
33

        $line = array();
        $prev_y = 1;

Orbmancer's avatar
Orbmancer committed
34
        for($i=0; $i<count($tabs); ++$i){
Orbmancer's avatar
Orbmancer committed
35
36
            $tab_x = $this->getTabX($i);
            $tab_y = $this->getTabY($i);
Orbmancer's avatar
Orbmancer committed
37
            $line[] = $tabs[$i];
Orbmancer's avatar
Orbmancer committed
38
39

            if($prev_y != $tab_y){
Orbmancer's avatar
Orbmancer committed
40
41
42
43
                /*echo '<br/>LINE '.count($this->contents[$tab_x][$tab_y]).'<br/>';
                var_dump($line);
                echo '<br/>';*/
                $this->contents[$tab_x][$tab_y][] = $line;
Orbmancer's avatar
Orbmancer committed
44
45
46
                $line = array();
            }
        }
Erwan Normand's avatar
Erwan Normand committed
47
	}
Orbmancer's avatar
Orbmancer committed
48
49
50
51
52
53
54
55

    private function getTabX($index){
        return (int) floor($index / self::$tabwidth) % 5 +1;
    }

    private function getTabY($index){
        return (int) floor($index / (self::$tabwidth * $this->mapwidth * self::$tabheight)) +1;
    }
Erwan Normand's avatar
Erwan Normand committed
56
	
Erwan Normand's avatar
Rename  
Erwan Normand committed
57
58
	public function settabs($tabs) {
		$this->tabs = $tabs;
Erwan Normand's avatar
Erwan Normand committed
59
60
	}
	
Erwan Normand's avatar
Rename  
Erwan Normand committed
61
62
	public function gettabs() {
		return $this->tabs;
Erwan Normand's avatar
Erwan Normand committed
63
64
65
	}
	
	public function getTab($x, $y) {
Orbmancer's avatar
Orbmancer committed
66

Erwan Normand's avatar
Erwan Normand committed
67
68
	}
}