|
1
|
|
|
/* |
|
2
|
|
|
* This file is part of ArakneUtils. |
|
3
|
|
|
* |
|
4
|
|
|
* ArakneUtils 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
|
|
|
* ArakneUtils 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 ArakneUtils. If not, see <https://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright (c) 2017-2020 Vincent Quatrevieux |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
package fr.arakne.utils.maps; |
|
21
|
|
|
|
|
22
|
|
|
import fr.arakne.utils.maps.serializer.CellData; |
|
23
|
|
|
import org.checkerframework.checker.index.qual.NonNegative; |
|
24
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull; |
|
25
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
|
26
|
|
|
import org.checkerframework.dataflow.qual.Pure; |
|
27
|
|
|
|
|
28
|
|
|
import java.util.Objects; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Base implementation of MapCell by adapting a {@link CellData} |
|
32
|
|
|
* |
|
33
|
|
|
* @param <M> The DofusMap class |
|
34
|
|
|
* @param <C> Should be the cell class it-self |
|
35
|
|
|
*/ |
|
36
|
|
|
public abstract class AbstractCellDataAdapter<M extends @NonNull DofusMap, C extends @NonNull MapCell> implements MapCell<C> { |
|
37
|
|
|
protected final CellData data; |
|
38
|
|
|
private final M map; |
|
39
|
|
|
private final @NonNegative int id; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param map The container map |
|
43
|
|
|
* @param data The cell data |
|
44
|
|
|
* @param id The cell id |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public AbstractCellDataAdapter(M map, CellData data, @NonNegative int id) { |
|
47
|
1 |
|
this.map = map; |
|
48
|
1 |
|
this.data = data; |
|
49
|
1 |
|
this.id = id; |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
@Pure |
|
53
|
|
|
@Override |
|
54
|
|
|
public final @NonNegative int id() { |
|
55
|
1 |
|
return id; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
@Pure |
|
59
|
|
|
@Override |
|
60
|
|
|
public final boolean walkable() { |
|
61
|
1 |
|
return data.active() && data.movement().walkable(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
@Pure |
|
65
|
|
|
@Override |
|
66
|
|
|
public final M map() { |
|
67
|
1 |
|
return map; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
@Override |
|
71
|
|
|
public boolean equals(@Nullable Object o) { |
|
72
|
1 |
|
if (this == o) { |
|
73
|
1 |
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
if (o == null || getClass() != o.getClass()) { |
|
77
|
1 |
|
return false; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
final AbstractCellDataAdapter<?, ?> that = (AbstractCellDataAdapter<?, ?>) o; |
|
81
|
|
|
|
|
82
|
1 |
|
return id == that.id && map == that.map; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
@Override |
|
86
|
|
|
public int hashCode() { |
|
87
|
1 |
|
return Objects.hash(map, id); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|