001package com.fs.starfarer.api.loading;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import com.fs.starfarer.api.ModSpecAPI;
007
008public class Description implements WithSourceMod {
009
010        public static enum Type {
011                SHIP,
012                WEAPON,
013                SHIP_SYSTEM,
014                RESOURCE,
015                ACTION_TOOLTIP,
016                PLANET,
017                ASTEROID,
018                FACTION,
019                TERRAIN,
020                GALLERY,
021                CUSTOM,
022        }
023        
024        private Type type;
025        private String id;
026        
027        private String text1 ="No description... yet", text2 ="No description... yet", text3 ="No description... yet";
028        private String text4 = null;
029        private String text5 = null;
030
031        public Description(String id, Type type) {
032                this.type = type;
033                this.id = id;
034        }
035        
036        public String getUID() {
037                return id + "_" + type.name();
038        }
039        
040        public String getText5() {
041                return text5;
042        }
043
044        public void setText5(String text5) {
045                this.text5 = text5;
046        }
047
048        public String getText4() {
049                return text4;
050        }
051
052        public void setText4(String text4) {
053                this.text4 = text4;
054        }
055        public boolean hasText4() {
056                return text4 != null && !text4.isEmpty();
057        }
058        public boolean hasText5() {
059                return text5 != null && !text5.isEmpty();
060        }
061
062        public String getText1() {
063                return text1;
064        }
065        
066        public String getText1FirstPara() {
067                if (text1 != null) {
068                        int index = text1.indexOf('\n');
069                        if (index != -1) {
070                                return text1.substring(0, index);
071                        }
072                }
073                return text1;
074        }
075        
076        public List<String> getText1Paras() {
077                return getParas(text1);
078        }
079        public List<String> getText2Paras() {
080                return getParas(text2);
081        }
082        public List<String> getText3Paras() {
083                return getParas(text3);
084        }
085        public List<String> getText4Paras() {
086                return getParas(text4);
087        }
088        public List<String> getText5Paras() {
089                return getParas(text5);
090        }
091        
092        public List<String> getParas(String text) {
093                List<String> result = new ArrayList<String>();
094                if (text == null) return result;
095                
096                String [] temp = text.split("\\n");
097                for (String p : temp) {
098                        p = p.trim();
099                        if (p.isEmpty()) continue;
100                        result.add(p);
101                }
102                return result;
103        }
104
105        
106        public void setText1(String text1) {
107                if (text1 == null || text1.equals("")) text1 = "No description... yet";
108                this.text1 = text1.trim();
109        }
110
111        public String getText2() {
112                return text2;
113        }
114
115        public void setText2(String text2) {
116                if (text2 == null || text2.equals("")) text2 = "No description... yet";
117                this.text2 = text2.trim();
118        }
119
120        public String getText3() {
121                return text3;
122        }
123
124        public void setText3(String text3) {
125                if (text3 == null || text3.equals("")) text3 = "No description... yet";
126                this.text3 = text3.trim();
127        }
128        
129        public boolean hasText2() {
130                String str = getText2();
131                if (str == null || str.isEmpty() || str.equals("No description... yet")) return false;
132                return true;
133        }
134        public boolean hasText1() {
135                String str = getText1();
136                if (str == null || str.isEmpty() || str.equals("No description... yet")) return false;
137                return true;
138        }
139        public boolean hasText3() {
140                String str = getText3();
141                if (str == null || str.isEmpty() || str.equals("No description... yet")) return false;
142                return true;
143        }
144        
145        private ModSpecAPI sourceMod = null;
146        public ModSpecAPI getSourceMod() {
147                return sourceMod;
148        }
149        public void setSourceMod(ModSpecAPI sourceMod) {
150                this.sourceMod = sourceMod;
151        }
152}