001package com.fs.starfarer.api.impl.campaign.intel.bar;
002
003import java.util.ArrayList;
004import java.util.Iterator;
005import java.util.List;
006
007import com.fs.starfarer.api.EveryFrameScript;
008import com.fs.starfarer.api.Global;
009import com.fs.starfarer.api.impl.campaign.intel.bar.events.BarEventManager;
010
011public class PortsideBarData implements EveryFrameScript {
012        
013        public static final String KEY = "$core_PortsideBarData";
014        
015//      public static final float CHECK_DAYS = 10f;
016//      public static final float CHECK_PROB = 0.5f;
017        
018        
019        public static PortsideBarData getInstance() {
020                Object test = Global.getSector().getMemoryWithoutUpdate().get(KEY);
021                return (PortsideBarData) test; 
022        }
023        
024        protected List<PortsideBarEvent> active = new ArrayList<PortsideBarEvent>();
025        
026        public PortsideBarData() {
027                Global.getSector().getMemoryWithoutUpdate().set(KEY, this);
028        }
029
030        
031        public void addEvent(PortsideBarEvent event) {
032                active.add(event);
033        }
034        
035        public void removeEvent(PortsideBarEvent event) {
036                active.remove(event);
037                // may or may not be there, but try to remove in any case
038                BarEventManager.getInstance().getActive().remove(event);
039        }
040        
041        public List<PortsideBarEvent> getEvents() {
042//              boolean exists = false;
043//              for (PortsideBarEvent curr : active) {
044//                      if (curr instanceof HubMissionBarEventWrapper) {
045//                              exists = true;
046//                              break;
047//                      }
048//              }
049//              if (!exists) {
050//                      active.add(new HubMissionBarEventWrapper("cheapCom"));
051//              }
052                return active;
053        }
054
055        public void advance(float amount) {
056                
057                Iterator<PortsideBarEvent> iter = active.iterator();
058                while (iter.hasNext()) {
059                        PortsideBarEvent curr = iter.next();
060                        if (curr.shouldRemoveEvent()) {
061                                iter.remove();
062                        } else {
063                                curr.advance(amount);
064                                if (curr.shouldRemoveEvent()) {
065                                        iter.remove();
066                                }
067                        }
068                }
069                
070        }
071
072        public boolean isDone() {
073                return false;
074        }
075
076        public boolean runWhilePaused() {
077                return false;
078        }
079
080        
081        
082}
083
084