SelfRegisterable
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 0
cts 0
cp 0
c 1
b 0
f 0
wmc 0

1 Method

Rating   Name   Duplication   Size   Complexity  
register(ExplorationActionRegistry) 0 1 ?
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu 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
 * Araknemu 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 Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.exploration.interaction.action;
21
22
import fr.quatrevieux.araknemu.game.exploration.ExplorationPlayer;
23
24
import java.util.EnumMap;
25
26
/**
27
 * Registry for all exploration game actions
28
 */
29
public final class ExplorationActionRegistry implements ActionFactory {
30 1
    private final EnumMap<ActionType, ActionFactory> factories = new EnumMap<>(ActionType.class);
31
32 1
    public ExplorationActionRegistry(SelfRegisterable... actions) {
33 1
        for (SelfRegisterable action : actions) {
34 1
            action.register(this);
35
        }
36 1
    }
37
38
    @Override
39
    public Action create(ExplorationPlayer player, ActionType action, String[] arguments) {
40 1
        if (!factories.containsKey(action)) {
41 1
            throw new IllegalArgumentException("No factory found for game action : " + action);
42
        }
43
44 1
        return factories.get(action).create(player, action, arguments);
45
    }
46
47
    /**
48
     * Register a new exploration action into the registry
49
     *
50
     * @param type The action type
51
     * @param factory The factory
52
     */
53
    public void register(ActionType type, ActionFactory factory) {
54 1
        factories.put(type, factory);
55 1
    }
56
57
    public interface SelfRegisterable {
58
        /**
59
         * Auto-register the action factory into the action registry
60
         */
61
        public void register(ExplorationActionRegistry factory);
62
    }
63
}
64