Tabs.class.php 1.31 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;
Erwan Normand's avatar
Erwan Normand committed
16
		
Erwan Normand's avatar
Rename    
Erwan Normand committed
17
		$this->tabs = array(
Erwan Normand's avatar
Erwan Normand committed
18
19
20
21
22
			array(array(), array(), array(), array(), array()),
			array(array(), array(), array(), array(), array()),
			array(array(), array(), array(), array(), array()),
			array(array(), array(), array(), array(), array()),
			array(array(), array(), array(), array(), array())); // coucou :)
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;

Erwan Normand's avatar
Rename    
Erwan Normand committed
34
        for($i=0; $i<count($tabs); ++$i){
Orbmancer's avatar
Orbmancer committed
35
36
            $tab_x = (int) floor($i / self::$tabwidth);
            $tab_y = (int) floor($i / (self::$tabwidth * self::$tabheight * $this->mapwidth));
Erwan Normand's avatar
Rename    
Erwan Normand committed
37
            $line[] = $tabs[$i];
Orbmancer's avatar
Orbmancer committed
38
39

            if($prev_y != $tab_y){
Erwan Normand's avatar
Rename    
Erwan Normand committed
40
                $this->tabs[$tab_x][$tab_y] = $line;
Orbmancer's avatar
Orbmancer committed
41
42
43
                $line = array();
            }
        }
Erwan Normand's avatar
Erwan Normand committed
44
45
	}
	
Erwan Normand's avatar
Rename    
Erwan Normand committed
46
47
	public function settabs($tabs) {
		$this->tabs = $tabs;
Erwan Normand's avatar
Erwan Normand committed
48
49
	}
	
Erwan Normand's avatar
Rename    
Erwan Normand committed
50
51
	public function gettabs() {
		return $this->tabs;
Erwan Normand's avatar
Erwan Normand committed
52
53
54
	}
	
	public function getTab($x, $y) {
Orbmancer's avatar
Orbmancer committed
55

Erwan Normand's avatar
Erwan Normand committed
56
57
	}
}