Subversion Repository Public Repository

Nextrek

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
var Utilities = {
	getText: function(text){
		var lang = Langs[language];
		var returnText = lang[text];
		return returnText;
	},
	getImage: function(image){
		var agentPics = Agents[userAgent];
		var returnImage = agentPics[image];
		return returnImage;
	},
	getScreenWidth: function(){
		var width = Constants.screenSizes[userAgent].width;
		return width;
	},
	getScreenHeight: function(){
		var height = Constants.screenSizes[userAgent].height;
		return height;
	},
	haveObject: function(){
		for (val in mainData.objects){
			if (mainData.objects[val] && mainData.objects[val].had == true){
				return true;
			}
		}
		return false;
	},
	haveQuests: function(){
		for (val in mainData.quests){
			if (mainData.quests[val] && mainData.quests[val].status == "had" || mainData.quests[val].status == "done"){
				return true;
			}
		}
		return false;
	},
	haveEvents: function(){
		for (val in mainData.events){
			if (mainData.events[val] && mainData.events[val].happened == true){
				return true;
			}
		}
		return false;
	},
	isPrecondValid: function(preCond){
		if (preCond == true){
			return true;
		}
		var precondArray = preCond.split("&");
		var resArray = new Array();
		for (val in precondArray){
			resArray.push(Utilities.checkSinglePrecond(precondArray[val]));
		}
		var result = true;
		for (val in resArray){
			result = result && resArray[val];
		}
		return result;
	},
	checkSinglePrecond: function(singlePrecond){
		if (singlePrecond.indexOf("quest") == 0){
			return Utilities.checkQuestPreCond(singlePrecond.replace("quest(", ""));
		}else if (singlePrecond.indexOf("oggetto") == 0){
			return Utilities.checkOggettoPreCond(singlePrecond.replace("oggetto(", ""));
		}else if (singlePrecond.indexOf("evento") == 0){
			return Utilities.checkEventoPreCond(singlePrecond.replace("evento(", ""));
		}
	},
	checkQuestPreCond: function(precond){
		//alert("checko Quest " + precond);
		var precondQue = precond.split(",")[0];
		var precondWould = precond.split(",")[1] == "done)" ? "done" : precond.split(",")[1] == "had)" ? "had" : "none";
		var result = true;
		if (mainData && mainData.quests && mainData.quests[precondQue]){
			var quest = mainData.quests[precondQue];
			if (quest.status == precondWould){
				result = true;
			}else{
				result = false;
			}
		}
		return result;
	},
	checkOggettoPreCond: function(precond){
		//alert("checko Oggetto " + precond);
		var precondObj = precond.split(",")[0];
		var precondWould = precond.split(",")[1] == "true)" ? true : false;
		var result = true;
		//alert(mainData.objects + "-" + precondObj);
		if (mainData && mainData.objects && mainData.objects[precondObj]){
			var obj = mainData.objects[precondObj];
			//alert(JSON.stringify(obj));
			if (obj.had == precondWould){
				result = true;
			}else{
				result = false;
			}
		}
		//alert(result);
		return result;
	},
	checkEventoPreCond: function(precond){
		//alert("checko Evento " + precond);
		var precondEve = precond.split(",")[0];
		var precondWould = precond.split(",")[1] == "true)" ? true : false;
		var result = true;
		if (mainData && mainData.events && mainData.events[precondEve]){
			var event = mainData.events[precondEve];
			if (event.happened == precondWould){
				result = true;
			}else{
				result = false;
			}
		}
		return result;
	},
	setPostCond: function(postCond){
		if (postCond == true){
			return;
		}
		var postCondArray = postCond.split("&");
		for (val in postCondArray){
			Utilities.setSinglePostCond(postCondArray[val]);
		}
		return;
	},
	setSinglePostCond: function(singlePostCond){
		if (singlePostCond.indexOf("quest") == 0){
			Utilities.setQuestPostCond(singlePostCond.replace("quest(", ""));
		}else if (singlePostCond.indexOf("oggetto") == 0){
			Utilities.setOggettoPostCond(singlePostCond.replace("oggetto(", ""));
		}else if (singlePostCond.indexOf("evento") == 0){
			Utilities.setEventoPostCond(singlePostCond.replace("evento(", ""));
		}
	},
	setQuestPostCond: function(postcond){
		var postcondQue = postcond.split(",")[0];
		var postcondWould = postcond.split(",")[1] == "done)" ? "done" : postcond.split(",")[1] == "had)" ? "had" : "none";
		if (mainData && mainData.quests && mainData.quests[postcondQue]){
			var quest = mainData.quests[postcondQue];
			if (postcondWould == "had" && quest.status != postcondWould){
				Utilities.mostraAlert(quest.hadTitle, quest.hadText, quest, "quest");
			}else if (postcondWould == "done" && quest.status != postcondWould){
				Utilities.mostraAlert(quest.doneTitle, quest.doneText, quest, "quest");
			}
			quest.status = postcondWould;
		}
		return;
	},
	setOggettoPostCond: function(postcond){
		var postcondObj = postcond.split(",")[0];
		var postcondWould = postcond.split(",")[1] == "true)" ? true : false;
		if (mainData && mainData.objects && mainData.objects[postcondObj]){
			var obj = mainData.objects[postcondObj];
			if (postcondWould && obj.had != postcondWould){
				Utilities.mostraAlert(obj.trueTitle, obj.trueText, obj, "object");
			}else if (obj.had != postcondWould){
				Utilities.mostraAlert(obj.falseTitle, obj.falseText, obj, "object");
			}
			obj.had = postcondWould;
		}
		return;
	},
	setEventoPostCond: function(postcond){
		var postcondEve = postcond.split(",")[0];
		var postcondWould = postcond.split(",")[1] == "true)" ? true : false;
		if (mainData && mainData.events && mainData.events[postcondEve]){
			var event = mainData.events[postcondEve];
			if (postcondWould && event.happened != postcondWould){
				Utilities.mostraAlert(event.trueTitle, event.trueText, event, "event");
			}else if (event.happened != postcondWould){
				Utilities.mostraAlert(event.falseTitle, event.falseText, event, "event");
			}
			event.happened = postcondWould;
		}
		return;
	},
	mostraAlert: function(title, text, obj, type){
		var container = document.getElementById("alertBox");
		var alertWidth = parseInt(Utilities.getScreenWidth()*mainData.alert.widthPerc);
		var alertHeight = parseInt(Utilities.getScreenHeight()*mainData.alert.heightPerc);
		var alertLeftPos = parseInt((Utilities.getScreenWidth() - alertWidth)/2);
		var alertTopPos = parseInt((Utilities.getScreenHeight() - alertHeight)/2);
		container.style.width = ""+ alertWidth + "px";
		container.style.height = ""+ alertHeight + "px";
		container.style.top = alertTopPos + "px";
		container.style.left = alertLeftPos + "px";
		container.style.backgroundColor = mainData.alert["alert-background-color"];
		container.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(mainData.alert["alert-background-img"]) + ')';
		container.style.display = "block";
		
		var blocker = document.getElementById("alertBlocker");
		blocker.style.width = ""+ Utilities.getScreenWidth() + "px";
		blocker.style.height = ""+ Utilities.getScreenHeight() + "px";
		blocker.style.top = "0px";
		blocker.style.left = "0px";
		blocker.style.display = "block";
		
		var leftBorderContainer = document.getElementById("alertWBorderLeft");
		leftBorderContainer.style.top = alertTopPos + "px";
		leftBorderContainer.style.left = alertLeftPos + "px";
		leftBorderContainer.style.width = ""+ mainData.alert["wBorder-width"] + "px";
		leftBorderContainer.style.height = ""+ alertHeight + "px";
		leftBorderContainer.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(mainData.alert["wBorderLeft-img"]) + ')';
		leftBorderContainer.style.display = "block";
		
		var rightBorderContainer = document.getElementById("alertWBorderRight");
		rightBorderContainer.style.top = alertTopPos + "px";
		rightBorderContainer.style.left = (alertLeftPos + alertWidth - mainData.alert["wBorder-width"]) + "px";
		rightBorderContainer.style.width = ""+ mainData.alert["wBorder-width"] + "px";
		rightBorderContainer.style.height = ""+ alertHeight + "px";
		rightBorderContainer.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(mainData.alert["wBorderRight-img"]) + ')';
		rightBorderContainer.style.display = "block";
		
		var topBorderContainer = document.getElementById("alertHBorderTop");
		topBorderContainer.style.top = alertTopPos + "px";
		topBorderContainer.style.left = alertLeftPos + "px";
		topBorderContainer.style.width = ""+ alertWidth + "px";
		topBorderContainer.style.height = ""+ mainData.alert["hBorder-height"] + "px";
		topBorderContainer.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(mainData.alert["hBorderTop-img"]) + ')';
		topBorderContainer.style.display = "block";
		
		var bottomBorderContainer = document.getElementById("alertHBorderBottom");
		bottomBorderContainer.style.top = (alertTopPos +alertHeight - mainData.alert["hBorder-height"]) +"px";
		bottomBorderContainer.style.left = alertLeftPos + "px";
		bottomBorderContainer.style.width = ""+ alertWidth + "px";
		bottomBorderContainer.style.height = ""+ mainData.alert["hBorder-height"] + "px";
		bottomBorderContainer.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(mainData.alert["hBorderBottom-img"]) + ')';
		bottomBorderContainer.style.display = "block";
		
		var alertTitle = document.getElementById("alertTitle");
		alertTitle.innerHTML = title;
		alertTitle.style.top = (alertTopPos + mainData.alert["hBorder-height"] + 10 )+ "px";
		alertTitle.style.left = (alertLeftPos + mainData.alert["wBorder-width"] + 10 )+ "px";
		alertTitle.style.width = ""+ (alertWidth - 2* mainData.alert["wBorder-width"] - 20 )+ "px";
		alertTitle.style.height = ""+ 30 + "px";
		alertTitle.style.display = "block";
		
		var alertText = document.getElementById("alertText");
		alertText.innerHTML = text;
		alertText.style.top = (alertTopPos + mainData.alert["hBorder-height"] + 40 )+ "px";
		alertText.style.left = (alertLeftPos + mainData.alert["wBorder-width"] + 10 )+ "px";
		alertText.style.width = ""+ (alertWidth - 2* mainData.alert["wBorder-width"] - 20 )+ "px";
		alertText.style.height = "auto";
		alertText.style.display = "block";
		
		var alertImg = document.getElementById("alertImg");
		alertImg.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(obj["img"]) + ')';
		alertImg.style.top = (alertTopPos + alertHeight - mainData.defaults[type + "-height"] - 50 - mainData.alert["alert-OKButton-height"])+ "px";
		alertImg.style.left = (alertLeftPos + mainData.alert["wBorder-width"] + 10 )+ "px";
		alertImg.style.width = ""+ (mainData.defaults[type+"-width"])+ "px";
		alertImg.style.height = ""+ (mainData.defaults[type + "-height"])+ "px";
		alertImg.style.display = "block";						
								
		var alertImgText = document.getElementById("alertImgText");
		alertImgText.innerHTML = Utilities.getText(obj["description"]);
		alertImgText.style.top = (alertTopPos + alertHeight - mainData.defaults[type + "-height"] - 50 - mainData.alert["alert-OKButton-height"])+ "px";
		alertImgText.style.left = (alertLeftPos + mainData.alert["wBorder-width"] + 20 + mainData.defaults[type+"-width"])+ "px";
		alertImgText.style.width = ""+ (alertWidth - 30 - (2 * mainData.alert["wBorder-width"]) - mainData.defaults[type+"-width"])+ "px";
		alertImgText.style.height = "auto";
		alertImgText.style.display = "block";						
		
		var alertOKButton = document.getElementById("alertOKButton");
		alertOKButton.style.backgroundImage = 'url(' + "./images/"+
								Utilities.getImage(mainData.alert["alert-OKButton-img"]) + ')';
		alertOKButton.style.top = (alertTopPos + alertHeight - 20 - mainData.alert["alert-OKButton-height"])+ "px";
		alertOKButton.style.left = (alertLeftPos + parseInt((alertWidth - mainData.alert["alert-OKButton-width"])/2))+ "px";
		alertOKButton.style.width = ""+ mainData.alert["alert-OKButton-width"]+ "px";
		alertOKButton.style.height = ""+ mainData.alert["alert-OKButton-height"]+ "px";
		alertOKButton.style.display = "block";												
		
	},
	nascondiAlert: function(){
		document.getElementById("alertBlocker").style.display = "none";
		document.getElementById("alertBox").style.display = "none";
		document.getElementById("alertWBorderLeft").style.display = "none";
		document.getElementById("alertWBorderRight").style.display = "none";
		document.getElementById("alertHBorderTop").style.display = "none";
		document.getElementById("alertHBorderBottom").style.display = "none";
		document.getElementById("alertTitle").style.display = "none";
		document.getElementById("alertText").style.display = "none";
		document.getElementById("alertImg").style.display = "none";
		document.getElementById("alertImgText").style.display = "none";
		document.getElementById("alertOKButton").style.display = "none";
	}
};

Commits for Nextrek/minstrek/GameEditorBKP - Copia/GameEditor/bin/Release/MinsTrek/appFiles/Utilities.js

Diff revisions: vs.
Revision Author Commited Message
78 JMBauan picture JMBauan Fri 21 Feb, 2014 12:04:23 +0000