1
|
|
|
/* |
|
|
|
|
2
|
|
|
* This file is part of Swf Map Loader. |
3
|
|
|
* |
4
|
|
|
* Swf Map Loader is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* Swf Map Loader is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with Swf Map Loader. If not, see <https://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* Copyright (c) 2020-2020 Vincent Quatrevieux |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
package fr.arakne.swfmaploader.map; |
21
|
|
|
|
22
|
|
|
import fr.arakne.swfmaploader.swf.SwfMapStructure; |
23
|
|
|
import fr.arakne.utils.maps.DofusMap; |
24
|
|
|
import fr.arakne.utils.maps.MapCell; |
25
|
|
|
import fr.arakne.utils.maps.serializer.CellData; |
26
|
|
|
import fr.arakne.utils.value.Dimensions; |
27
|
|
|
|
28
|
|
|
import java.util.ArrayList; |
29
|
|
|
import java.util.List; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Simple implementation of a DofusMap using {@link SwfMapStructure} |
33
|
|
|
* Extends this class to create more specific implementations |
34
|
|
|
* |
35
|
|
|
* @param <C> The cell type |
36
|
|
|
*/ |
37
|
|
|
public class SimpleMap<C extends MapCell> implements DofusMap<C> { |
38
|
|
|
final private Dimensions dimensions; |
39
|
|
|
|
40
|
|
|
final protected List<C> cells; |
41
|
|
|
final protected SwfMapStructure structure; |
42
|
|
|
|
43
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
44
|
1 |
|
public SimpleMap(SwfMapStructure structure, CellData[] cells, MapFactory<C, ? extends SimpleMap<C>> mapFactory) { |
45
|
1 |
|
this.structure = structure; |
46
|
1 |
|
this.dimensions = new Dimensions(structure.width(), structure.height()); |
47
|
1 |
|
this.cells = makeCells(cells, (MapFactory<C, SimpleMap<C>>) mapFactory); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
@Override |
51
|
|
|
final public int size() { |
52
|
1 |
|
return cells.size(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
@Override |
56
|
|
|
final public C get(int id) { |
57
|
1 |
|
return cells.get(id); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
@Override |
61
|
|
|
final public Dimensions dimensions() { |
62
|
1 |
|
return dimensions; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private List<C> makeCells(CellData[] data, MapFactory<C, SimpleMap<C>> factory) { |
66
|
1 |
|
List<C> cells = new ArrayList<>(data.length); |
|
|
|
|
67
|
|
|
|
68
|
1 |
|
for (int id = 0; id < data.length; ++id) { |
69
|
1 |
|
cells.add(factory.createCell(this, id, data[id])); |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
return cells; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|