summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java
blob: 7120a91b171ae84f5533e30b8601bcda36ebf4ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fourisland.fourpuzzle.gamestate.mapview.event;

import com.fourisland.fourpuzzle.gamestate.mapview.Map;
import java.util.Vector;

/**
 *
 * @author hatkirby
 */
public class EventList extends Vector<LayerEvent> {
    
    public EventList(Map parentMap)
    {
        setParentMap(parentMap);
    }
    
    public EventList copy(Map parentMap)
    {
        EventList temp = new EventList(parentMap);
        
        for (LayerEvent ev : this)
        {
            temp.add(ev.copy());
        }
        
        return temp;
    }
    
    @Override
    public boolean add(LayerEvent o)
    {
        if (o.getLabel().equals("Unlabelled"))
        {
            o.setLabel("Event" + (this.size()+1));
        } else {
            if (    (o.getLabel().equals("Hero")) ||
                    (o.getLabel().equals("Unlabelled")) ||
                    (o.getLabel().equals("")))
            {
                return false;
            }
            
            for (LayerEvent ev : this)
            {
                if (ev.getLabel().equals(o.getLabel()))
                {
                    return false;
                }
            }
        }
        
        if (parentMap != null)
        {
            o.setParentMap(parentMap);
        }
        
        return super.add(o);
    }
    
    private Map parentMap = null;
    public Map getParentMap()
    {
        return parentMap;
    }
    public void setParentMap(Map parentMap)
    {
        this.parentMap = parentMap;
        
        for (LayerEvent ev : this)
        {
            ev.setParentMap(parentMap);
        }
    }

}