Starsector API
Loading...
Searching...
No Matches
ConstructionQueue.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ.impl;
2
3import java.util.ArrayList;
4import java.util.List;
5
6
7public class ConstructionQueue {
8
9 public static class ConstructionQueueItem {
10 public String id;
11 public int cost;
12 public ConstructionQueueItem(String id, int cost) {
13 this.id = id;
14 this.cost = cost;
15 }
16 }
17
18 protected List<ConstructionQueueItem> items = new ArrayList<ConstructionQueueItem>();
19
20 protected Object readResolve() {
21 if (items == null) {
22 items = new ArrayList<ConstructionQueueItem>();
23 }
24 return this;
25 }
26
27 public List<ConstructionQueueItem> getItems() {
28 return items;
29 }
30 public void setItems(List<ConstructionQueueItem> items) {
31 this.items = items;
32 }
33
34 public void addToEnd(String id, int cost) {
35 ConstructionQueueItem item = new ConstructionQueueItem(id, cost);
36 items.add(item);
37 }
38
39 public void moveUp(String id) {
40 ConstructionQueueItem item = getItem(id);
41 if (item == null) return;
42 int index = items.indexOf(item);
43 index--;
44 if (index < 0) index = 0;
45 items.remove(item);
46 items.add(index, item);
47 }
48
49 public void moveDown(String id) {
50 ConstructionQueueItem item = getItem(id);
51 if (item == null) return;
52 int index = items.indexOf(item);
53 index++;
54 items.remove(item);
55 if (index > items.size()) index = items.size();
56 items.add(index, item);
57 }
58
59 public void moveToFront(String id) {
60 ConstructionQueueItem item = getItem(id);
61 if (item == null) return;
62 items.remove(item);
63 items.add(0, item);
64 }
65
66 public void moveToBack(String id) {
67 ConstructionQueueItem item = getItem(id);
68 if (item == null) return;
69 items.remove(item);
70 items.add(item);
71 }
72
73 public void removeItem(String id) {
74 items.remove(getItem(id));
75 }
76
77 public ConstructionQueueItem getItem(String id) {
78 for (ConstructionQueueItem item : items) {
79 if (item.id.equals(id)) return item;
80 }
81 return null;
82 }
83
84 public boolean hasItem(String id) {
85 return getItem(id) != null;
86 }
87}
88
89
90
91
92