-
Notifications
You must be signed in to change notification settings - Fork 0
/
STAppDisplay.pde
387 lines (289 loc) · 8.79 KB
/
STAppDisplay.pde
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
import de.exitgames.api.loadbalancing.LoadBalancingClient;
import de.exitgames.api.loadbalancing.LoadBalancingPeer;
import java.security.Provider;
import java.security.Security;
import java.util.Enumeration;
import java.util.Collections;
import java.util.Iterator;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Calendar;
import java.util.Arrays;
import java.util.concurrent.locks.*;
import java.util.concurrent.CopyOnWriteArrayList;
/* for slack */
import net.gpedro.integrations.slack.*;
import com.google.gson.JsonElement;
import processing.video.*;
String SLACK_TAG="";
boolean DRAW_DEBUG=false;
boolean OFFLINE=false;
final int MGAME=3;
boolean DO_EASTER_EGG=false;
final boolean DRAW_FRAME=false;
final boolean WRITE_LOG=true;
PrintWriter log_output;
final float ORIGIN_DISPLAY_WIDTH=4080;
final float ORIGIN_DISPLAY_HEIGHT=376;
final String PARAM_FILE_PATH="stapp_display_params.json";
GlobalParameter Global_Param;
// final int Left_Screen_X=1024;
// final int Right_Screen_X=3056;
PhotonClient photon_client;
Thread photon_thread;
int igame_scene=-1;
GameScene[] agame_scene;
boolean show_game_over=false;
PFont font,name_font,timer_font;
PApplet gapplet;
PImage img_qrcode_android,img_qrcode_ios;
PShader shd_rmv_bg;
PVector scale_to_screen;
SlackApi slack_hook;
public void init(){
if(!DRAW_FRAME){
// to make a frame not displayable, you can
// use frame.removeNotify()
frame.removeNotify();
frame.setUndecorated(true);
// addNotify, here i am not sure if you have
// to add notify again.
frame.addNotify();
}
super.init();
}
void setup(){
Global_Param=new GlobalParameter(PARAM_FILE_PATH);
Global_Param.readParameters();
scale_to_screen=new PVector(Global_Param.Display_Size.x/ORIGIN_DISPLAY_WIDTH,Global_Param.Display_Size.y/ORIGIN_DISPLAY_HEIGHT);
SLACK_TAG=Global_Param.Slack_Tag;
SERVER_NAME=Global_Param.Server_Name;
frame.setLocation(0,0);
size((int)Global_Param.Window_Size.x,(int)Global_Param.Window_Size.y,P3D);
noCursor();
frameRate(60);
gapplet=this;
/* Init Slack */
slack_hook=new SlackApi("https://hooks.slack.com/services/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");
if(WRITE_LOG){
String log_name="log/STDisplayLog_"+year()+nf(month(),2)+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+".txt";
println("Create Log: "+log_name);
log_output=createWriter(log_name);
printlnA("STDisplay Start!",true);
}
/* for Photon SDK*/
Security.addProvider(new BouncyCastleProvider());
try{
Field field = Class.forName("javax.crypto.JceSecurity").
getDeclaredField("isRestricted");
field.setAccessible(true);
field.set(null, java.lang.Boolean.FALSE);
}catch(Exception ex){
ex.printStackTrace();
}
// img_qrcode_title=loadImage("APP_TITLE.png");
img_qrcode_android=loadImage("qr_android.png");
img_qrcode_ios=loadImage("qr_ios.png");
agame_scene=new GameScene[MGAME];
agame_scene[0]=new AGameScene();
agame_scene[1]=new BGameScene();
agame_scene[2]=new CGameScene();
// for(GameScene game_scene:agame_scene) game_scene.Init();
// println(agame_scene[6]);
font=loadFont("GameOver_Font.vlw");
textFont(font, 20);
name_font=loadFont("Combined-Bold-22.vlw");
timer_font=loadFont("Timer_Font.vlw");
shd_rmv_bg=loadShader("Rmv_Black.glsl");
background(0);
}
void draw(){
background(0);
scale_to_screen.x=Global_Param.Display_Size.x/ORIGIN_DISPLAY_WIDTH;
scale_to_screen.y=Global_Param.Display_Size.y/ORIGIN_DISPLAY_HEIGHT;
String str_log="";
boolean all_loaded=true;
for(int i=0;i<MGAME;++i){
if(agame_scene[i]!=null && !agame_scene[i].finish_load) all_loaded=false;
}
if(!all_loaded){
str_log+="LOADING";
for(int i=0;i<(frameCount/10)%5;++i) str_log+=".";
str_log+="\n";
}else{
if(!OFFLINE && photon_client==null){
photon_client=new PhotonClient();
photon_thread=new Thread(photon_client);
photon_thread.start();
}
if(igame_scene<0){
str_log+="NO GAME";
for(int i=0;i<(frameCount/10)%5;++i) str_log+=".";
str_log+="\n";
}else{
pushMatrix();
translate(Global_Param.Display_Loc.x,Global_Param.Display_Loc.y);
//scale(scale_to_screen.x,scale_to_screen.y);
agame_scene[igame_scene].SUpdate();
agame_scene[igame_scene].Draw();
agame_scene[igame_scene].DrawOnGraph(this.g);
popMatrix();
}
}
// frame.setTitle(String.valueOf(frameRate));
if(DRAW_DEBUG){
if(OFFLINE) str_log+="OFFLINE\n";
else str_log+="ONLINE\n";
str_log+="Display Loc: "+Global_Param.Display_Loc.x+" , "+Global_Param.Display_Loc.y;
str_log+="\nDisplay Size: "+Global_Param.Display_Size.x+" , "+Global_Param.Display_Size.y;
str_log+="\nDisplay Scale: "+scale_to_screen.x+" , "+scale_to_screen.y;
fill(255,0,0);
text(str_log,20,height-100);
text(frameRate,1024,height-100);
}
// if(mousePressed) saveFrame("STApp_cap_#####.png");
}
void setGame(int game_index){
// game_index-=101;
printlnA("Set Game : "+game_index,true);
if(game_index<0 || game_index>MGAME-1) return;
if(game_index>-1)
if(agame_scene[game_index]!=null){
agame_scene[game_index].Init();
igame_scene=game_index;
}
}
void printlnA(String str_print){
printlnA(str_print,false);
}
void printlnA(String str_print,boolean send_slack){
println(str_print);
log_output.println(getTimeStamp()+str_print);
if(send_slack) slack_hook.call(new SlackMessage(SLACK_TAG+str_print));
}
String getTimeStamp(){
return nf(hour(),2)+nf(minute(),2)+nf(second(),2)+" ";
}
void keyPressed(){
switch(key){
case 'a':
setGame((igame_scene+1)%MGAME);
break;
case 'g':
show_game_over=!show_game_over;
break;
case 'h':
// if(igame_scene==0) ((AGameScene)agame_scene[igame_scene]).addNewHouse("test_id"+frameCount,(int)random(2));
break;
case 'd':
//DRAW_DOOR=!DRAW_DOOR;
DRAW_DEBUG=!DRAW_DEBUG;
break;
case 'o':
OFFLINE=!OFFLINE;
background(0);
if(!OFFLINE){
photon_client=new PhotonClient();
new Thread(photon_client).start();
}else{
photon_client.disconnect();
photon_thread=null;
}
break;
case 'c':
if(igame_scene==2) ((CGameScene)agame_scene[2]).toggleClockMode();
break;
case 's':
if(igame_scene==1) ((BGameScene)agame_scene[1]).StartGame();
if(igame_scene==0) ((AGameScene)agame_scene[0]).triggerBuilding();
break;
case 't':
if(igame_scene==0) ((AGameScene)agame_scene[0]).triggerTurb();
break;
case ENTER:
if(!OFFLINE) photon_client.sendSwitchGameEvent((igame_scene+1)%3);
break;
case 'n':
if(igame_scene==0) ((AGameScene)agame_scene[0]).triggerCat();
break;
case 'e':
DO_EASTER_EGG=!DO_EASTER_EGG;
break;
case 'Z':
if(DRAW_DEBUG) Global_Param.Display_Size.x+=1;
break;
case 'X':
if(DRAW_DEBUG) Global_Param.Display_Size.x-=1;
break;
case 'Q':
if(DRAW_DEBUG) Global_Param.Display_Size.y+=1;
break;
case 'W':
if(DRAW_DEBUG) Global_Param.Display_Size.y-=1;
break;
case 'S':
if(DRAW_DEBUG) Global_Param.saveParameters();
break;
case 'R':
if(DRAW_DEBUG) Global_Param.readParameters();
break;
}
if(key==CODED){
switch(keyCode){
case UP:
if(DRAW_DEBUG) Global_Param.Display_Loc.y-=1;
break;
case DOWN:
if(DRAW_DEBUG) Global_Param.Display_Loc.y+=1;
break;
case LEFT:
if(DRAW_DEBUG) Global_Param.Display_Loc.x-=1;
break;
case RIGHT:
if(DRAW_DEBUG) Global_Param.Display_Loc.x+=1;
break;
}
}
}
String drawIlandText(String build_name,int left_right){
if(build_name==null) return null;
// println("Draw Iland Text "+build_name);
PGraphics pg_text=createGraphics(120,52,P3D);
pg_text.beginDraw();
pg_text.translate(pg_text.width/2,pg_text.height/2);
pg_text.textFont(name_font,22);
pg_text.textAlign(CENTER,CENTER);
float twid=pg_text.textWidth(build_name);
float tscale=(twid<120)?1:120/twid;
pg_text.scale(tscale,2.2);
pg_text.background(0,0);
pg_text.fill(255);
pg_text.text(build_name,0,0);
for(int i=0;i<2;++i) pg_text.filter(DILATE);
// if(left_right==1) pg_text.fill(65,103,177);
// else pg_text.fill(239,74,82);
pg_text.fill(0);
pg_text.text(build_name,0,0);
// pg_text.shader(shd_rmv_bg);
// pg_text.loadPixels();
// for(int i=0;i<pg_text.width;++i)
// for(int j=0;j<pg_text.height;++j){
// color tcolor=pg_text.get(i,j);
// if(red(tcolor)<65 || green(tcolor)<103 || blue(tcolor)<177) pg_text.set(i,j,color(0,0));
// else pg_text.set(i,j,color(tcolor,255));
// }
// pg_text.updatePixels();
pg_text.endDraw();
String file_name="tag_name_"+nf(frameCount,5)+"_"+nf((int)random(1000),4)+".png";
pg_text.save(file_name);
// saveStrings("tag_str_"+nf(frameCount,5),new String[]{build_name});
return file_name;
}
void exit(){
println("PROGRAM EXIT!");
if(WRITE_LOG){
log_output.flush(); // Writes the remaining data to the file
log_output.close(); // Finishes the file
}
super.exit();
}