forked from nkrisztian89/interstellar-armada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
1060 lines (1060 loc) Β· 47.5 KB
/
Gruntfile.js
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2016-2018, 2020-2024 KrisztiΓ‘n Nagy
* @file Grunt configuration file for the Interstellar Armada game
* @author KrisztiΓ‘n Nagy [[email protected]]
* @licence GNU GPLv3 <http://www.gnu.org/licenses/>
*/
/**
* @param grunt
*/
module.exports = function (grunt) {
"use strict";
var
settings = grunt.file.readJSON("src/config/settings.json"),
getConstName = function (string) {
var result = "", i;
for (i = 0; i < string.length; i++) {
if (string[i].match(/[A-Z]/)) {
result += "_";
}
result += ((string[i] === " ") || (string[i] === "-")) ? "_" : string[i].toUpperCase();
}
return result;
},
scssMappings = {
"css/general.css": 'src/scss/general.scss',
"css/about.css": 'src/scss/screens/about.scss',
"css/battle.css": 'src/scss/screens/battle.scss',
"css/controls.css": 'src/scss/screens/controls.scss',
"css/database.css": 'src/scss/screens/database.scss',
"css/debriefing.css": 'src/scss/screens/debriefing.scss',
"css/gameplay-settings.css": 'src/scss/screens/gameplay-settings.scss',
"css/general-settings.css": 'src/scss/screens/general-settings.scss',
"css/graphics.css": 'src/scss/screens/graphics.scss',
"css/ingame-menu.css": 'src/scss/screens/ingame-menu.scss',
"css/missions.css": 'src/scss/screens/missions.scss',
"css/multi-games.css": 'src/scss/screens/multi-games.scss',
"css/multi-lobby.css": 'src/scss/screens/multi-lobby.scss',
"css/multi-score.css": 'src/scss/screens/multi-score.scss',
"css/checkgroup.css": 'src/scss/components/checkgroup.scss',
"css/dialog.css": 'src/scss/components/dialog.scss',
"css/infobox.css": 'src/scss/components/infobox.scss',
"css/listcomponent.css": 'src/scss/components/listcomponent.scss',
"css/loadingbox.css": 'src/scss/components/loadingbox.scss',
"css/menucomponent.css": 'src/scss/components/menucomponent.scss',
"css/selector.css": 'src/scss/components/selector.scss',
"css/slider.css": 'src/scss/components/slider.scss',
"css/editor.css": 'src/scss/editor.scss'
},
// the getters for the properties with these names simply return the "private" property of the object,
// which is useful for development (as functions crash if there is a typo in the name instead of just
// silently returning undefined, and they provide another hooking point for debug code), but for
// optimization purposes, it is better to refer to the property directly in the release builds, so
// here we build an array of replacements which replace the getters with direct property access and
// remove their definitions from the code
// these getters are to be replaced both in the game and the editor sources
gettersToReplaceCommon = [
["positionMatrix"],
["orientationMatrix"],
["scalingMatrix"],
["velocityMatrix"],
["renderableObject"],
["subnodes"],
["instancing"],
["rootNode"],
["camera"],
["duration"],
["visualModel"],
["physicalModel"],
["childrenAlwaysInside", ""],
["ignoreTransform", "should"],
["color"],
["lightColor"],
["layers"],
["growthRate"],
["dimensions"],
["directionSpread"],
["velocity"],
["velocitySpread"],
["initialNumber"],
["spawnNumber"],
["spawnTime"],
["delay"],
["particleEmitterDescriptors"],
["mass"],
["muzzleFlash"],
["lightIntensity"],
["trailDescriptor"],
["explosionClass"],
["shieldExplosionClass"],
["shortName"],
["antiShip", "is"],
["lockingAngle"],
["modelScale"],
["capacity"],
["length"],
["homingMode"],
["angularAcceleration"],
["mainBurnAngleThreshold"],
["launchVelocity"],
["ignitionTime"],
["salvoCooldown"],
["proximityRange"],
["kineticFactor"],
["thrusterSlots"],
["barrels"],
["attachmentPoint"],
["rotationStyle"],
["fixed", "is"],
["basePoint"],
["rotators"],
["thrusterBurnParticle"],
["prepareVelocity"],
["prepareDuration"],
["jumpOutDuration"],
["jumpOutAcceleration"],
["jumpOutScaling"],
["jumpOutExplosionClass"],
["jumpInDuration"],
["jumpInDeceleration"],
["jumpInVelocity"],
["jumpInScaling"],
["jumpInExplosionClass"],
["rechargeColor"],
["rechargeAnimationDuration"],
["isFighterType", ""],
["name"],
["particle"],
["position"],
["period"],
["intensity"],
["spacecraftType"],
["hitpoints"],
["armor"],
["factionColor"],
["turnStyle"],
["attackVectorAngles"],
["attackThresholdAngle"],
["bodies"],
["weaponSlots"],
["missileLaunchers"],
["defaultLoadout"],
["views"],
["showTimeRatioDuringExplosion"],
["damageIndicators"],
["lightSources"],
["blinkerDescriptors"],
["missileClass", "get", "class"],
["salvoLeft"],
["state"],
["squads"],
["trigger"],
["pilotedSpacecraft", "get", "pilotedCraft"],
["squad"],
["indexInSquad"],
["weapons"],
["physicalPositionMatrix", "get", "physicalModel._positionMatrix"],
["physicalOrientationMatrix", "get", "physicalModel._orientationMatrix"],
["physicalScalingMatrix", "get", "physicalModel._scalingMatrix"],
["physicalVelocityMatrix", "get", "physicalModel._velocityMatrix"],
["missileClasses"],
["targetingSpacecrafts", "get", "targetedBy"],
["propulsion"],
["scale"],
["scaleMode"],
["visibleSize"],
["velocityVector"],
["boxLayout"],
["element"],
["emitting", "is"],
["isFighterType", ""],
["isAimingView", ""],
["inSalvoMode", "is", "salvo"],
["locked", "is"],
["alive", "is"],
["away", "is"],
["readyToUse", "is"],
["playing", "is"],
["measuredFromCenter", "is"],
["mousePosition"],
["isRenderedWithoutDepthMask", ""],
["isRenderedWithDepthMask", ""],
["dissipationDuration"],
["wireframe", "is"],
["test", "is"],
["custom", "is"],
["dragFactor"],
["angularDrag"],
["vibrationEnabled", "is"],
["hitDistance"],
["points"],
["playerHitpointsFactor"],
["friendlyHitpointsFactor"],
["enemyReactionTimeFactor"],
["playerSelfDamage"],
["playerFriendlyFireDamage"],
["hitboxOffset"],
["lastStrafeTarget"],
["lastLiftTarget"],
["lastYawTarget"],
["lastPitchTarget"],
["lastRollTarget"],
["initialCount"],
["team"],
["key"],
["minLOD"],
["aspect"],
["minFOV"],
["maxFOV"],
["node"],
["pannerNode"],
["origoPositionMatrix"],
["soundSource"],
["params"],
["piloted", "is"],
["viewDistance"],
["nearDistance", "get", "near"],
["blendMode"],
["vertexShaderSource"],
["fragmentShaderSource"],
["numAttributeVectors"],
["numVertexUniformVectors"],
["numVaryingVectors"],
["numTextureUnits"],
["numFragmentUniformVectors"],
["weaponDescriptors"],
["missileDescriptors"],
["propulsionDescriptor"],
["sensorsDescriptor"],
["jumpEngineDescriptor"],
["shieldDescriptor"],
['transformMatrix'],
['barrelMarkers'],
['first'],
['uniformData']
],
// these getters are to be replaced only in the game (and not the editor) sources
gettersToReplaceGame = [
["scene"]
],
getGetterReplacement = function (replacement) {
// create the replacements for each simple getter
var
functionName = ((replacement.length > 1) ? replacement[1] : "get") + ((replacement[1] === "") ? replacement[0] : replacement[0][0].toUpperCase() + replacement[0].substring(1)),
fieldName = "_" + ((replacement.length > 2) ? replacement[2] : replacement[0]);
return [{
// replace calls to this getter with a simple reference to the property
match: "." + functionName + '()',
replacement: "." + fieldName
}, {
// remove the getter definition from the prototype
match: new RegExp("\\s\\w+\\.prototype\\." + functionName + " = function \\(\\) {\\s+return this." + fieldName + ";\\s+};", "g"),
replacement: ""
}, {
// remove the getter definition from the prototype if it was added by reference
match: new RegExp("\\s\\w+\\.prototype\\." + functionName + " = \\w+;", "g"),
replacement: ""
}];
},
getterReplacementsCommon = gettersToReplaceCommon.map(getGetterReplacement),
getterReplacementsGame = gettersToReplaceGame.map(getGetterReplacement),
setterReplacements = [
["lightSource"],
["strafeTarget"],
["liftTarget"],
["yawTarget"],
["pitchTarget"],
["rollTarget"],
["team"],
["controlledCamera"],
["name"],
["dragFactor"],
["node"],
["instancedShader"],
["smallestSizeWhenDrawn"],
["clearColor"],
["ambientColor"],
["revealState"],
["piloted"],
["objectIntensity"]
].map(
function (replacement) {
// create the replacements for each simple setter
var
functionName = ((replacement.length > 1) ? replacement[1] : "set") + ((replacement[1] === "") ? replacement[0] : replacement[0][0].toUpperCase() + replacement[0].substring(1)),
fieldName = "_" + ((replacement.length > 2) ? replacement[2] : replacement[0]);
return [{
// replace calls to this setter with a simple assignment of the property
match: new RegExp("\\." + functionName + "\\(((?:[^()]+|\\((?:[^()]+|\\([^()]*\\))*\\))*)\\)", "g"),
replacement: "." + fieldName + "=" + "$1"
}, {
// remove the setter definition from the prototype
match: new RegExp("\\s\\w+\\.prototype\\." + functionName + " = function \\(\\w+\\) {\\s+this." + fieldName + " = \\w+;\\s+};", "g"),
replacement: ""
}, {
// remove the setter definition from the prototype if it was added by reference
match: new RegExp("\\s\\w+\\.prototype\\." + functionName + " = \\w+;", "g"),
replacement: ""
}];
}),
methodRemovals = [
"showHitbox",
"hideHitbox",
"toggleHitboxVisibility",
"getHitboxTextures",
"_addHitboxModel",
"getHitbox",
"addCuboid",
"log",
"logNodes",
["increaseCount", false, "Scene"],
"setupShadowMapDebugging",
"getMainDebugStats",
"getShadowMapDebugStats",
["isShadowMapDebuggingEnabled", true],
["getShadowMapDebuggingSettings", true],
"getNumLines",
"getNumTriangles",
// -------------------------------------------------------------
// stereoscopy
"setAnaglyphRendering",
"setSideBySideRendering",
["isAnaglyphRenderingEnabled", true],
["getAnaglyphRenderingSettings", true],
["isSideBySideRenderingEnabled", true],
["getSideBySideRenderingSettings", true]
].map(
function (replacement) {
var functionName = Array.isArray(replacement) ? replacement[0] : replacement, exported = Array.isArray(replacement) && replacement[1], className = Array.isArray(replacement) && replacement[2],
result = [{
// remove the method definition from the prototype (up to 2 levels of curly braces nesting in function body)
match: new RegExp("\\s" + (className || "\\w+") + "\\.prototype\\." + functionName + " = function \\((\\w+,*\\s*)*\\) {(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*};", "g"),
replacement: ""
}];
if (exported) {
result.push({
// remove the method export
match: new RegExp(functionName + ": _context\\." + functionName + "\\.bind\\(_context\\),*", "g"),
replacement: ""
});
}
return result;
}),
exportedFunctionRemovals = [
["isDebugVersion", null, true],
["resetDebugStats", "egomModel"],
["getDebugStats", "egomModel"],
["getDebugInfo"],
["cuboidModel", null, true],
["gridModel", null, true],
["positionMarkerModel", null, true],
["toString3", "vec", false, true],
["toString4", "vec", false, true],
["clearMatrixCount", "mat", false, true],
["getMatrixCount", "mat", false, true],
["toString3", "mat", false, true],
["toString4", "mat", false, true],
["toHTMLString4", "mat", false, true]
].map(
function (replacement) {
var
functionName = replacement[0],
moduleName = (replacement.length > 1) ? replacement[1] : null,
direct = (replacement.length > 2) ? replacement[2] : false,
expression = (replacement.length > 3) ? replacement[3] : false,
result = expression ? [{
// remove the function definition and export (up to 2 levels of curly braces nesting in function body)
match: new RegExp(moduleName + "\\." + functionName + " = function \\((\\w+,*\\s*)*\\) {(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*};", "g"),
replacement: ""
}] : direct ? [{
// remove the function definition and export (up to 2 levels of curly braces nesting in function body)
match: new RegExp(functionName + ": function \\((\\w+,*\\s*)*\\) {(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*},*", "g"),
replacement: ""
}] :
[{
// remove the function definition (up to 2 levels of curly braces nesting in function body)
match: new RegExp("function " + functionName + "\\((\\w+,*\\s*)*\\) {(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*}", "g"),
replacement: ""
}, {
// remove the function export
match: new RegExp(functionName + ": " + functionName + ",*", "g"),
replacement: ""
}];
if (moduleName) {
result.push({
// remove the function calls (matching alphanumeric params)
match: new RegExp(moduleName + "\\." + functionName + "\\((\\w+,*\\s*)*\\);", "g"),
replacement: ""
});
}
return result;
}),
objectRemovals = [
"_DEBUG_STATS"
].map(
function (objectName) {
return {
// remove the object definition (up to 2 levels of curly braces nesting)
match: new RegExp(objectName + " = {(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*}(,|;)*", "g"),
replacement: ""
};
}),
fieldRemovals = [
"_nodeCount",
"_nodeCountByType",
"_mainDebugStats",
"_shadowMapDebugStats",
"_shadowMapDebugging",
"_shadowMapDebugLightIndex",
"_shadowMapDebugRangeIndex",
"_shadowMapDebugShader",
// -------------------------------------------------------------
// stereoscopy
"_stereoscopicMode",
"_redShader",
"_cyanShader",
"_stereoscopicFrameBuffer",
"_leftShader",
"_rightShader",
"_sideBySideOriginalAspect",
"_leftEye",
"_rightEye"
].map(
function (fieldName) {
return {
// remove field setter
match: new RegExp("this\\." + fieldName + " = [^;]+;", "g"),
replacement: ""
};
}),
settingsToReplace = [
["missileAutoChangeCooldown", "battle"],
["cameraPilotingSwitchTransitionDuration", "battle"],
["cameraPilotingSwitchTransitionStyle", "battle"],
["strafeSpeedFactor", "battle"],
["turnAccelerationDurationInSeconds", "battle", "TURN_ACCELERATION_DURATION_S"],
["backgroundObjectDistance", "battle"],
["defaultMuzzleFlashDuration", "battle"],
["targetViewName", "battle"],
["targetChangeTransitionDuration", "battle"],
["targetChangeTransitionStyle", "battle"],
["targetOrderDuration", "battle"],
["selfFire", "battle"],
["maxCombatForwardSpeedFactor", "battle"],
["maxCombatReverseSpeedFactor", "battle"],
["maxCruiseForwardSpeedFactor", "battle"],
["maxCruiseReverseSpeedFactor", "battle"],
["showHitboxesForHitchecks", "battle"],
["fireSoundStackingTimeThreshold", "battle"],
["fireSoundStackingVolumeFactor", "battle"],
["hitSoundStackingTimeThreshold", "battle"],
["hitSoundStackingVolumeFactor", "battle"],
["weaponFireSoundStackMinimumDistance", "battle"],
["demoFighterAI", "battle", "DEMO_FIGHTER_AI_TYPE"],
["demoShipAI", "battle", "DEMO_SHIP_AI_TYPE"],
["scoreFractionForKill", "battle"],
["scoreBonusForHullIntegrity", "battle"],
["scoreBonusForHullIntegrityTeam", "battle"],
["missileHitRatioFactor", "battle"],
["scoreBonusForTeamSurvival", "battle"],
["particlePoolPrefillFactor", "battle"],
["projectilePoolPrefillFactor", "battle"],
["missilePoolPrefillFactor", "battle"],
["trailSegmentPoolPrefillFactor", "battle"],
["explosionPoolPrefillFactor", "battle"],
["viewDistance", "battle"],
["moveToOrigoDistance", "battle"],
["demoViewSwitchInterval", "battle"],
["demoDoubleViewSwitchChance", "battle"],
["jumpPrepareViewName", "battle"],
["jumpOutViewName", "battle"],
["musicVolumeInMenus", "battle"],
["sfxVolumeInMenus", "battle"],
["simulationStepsPerSecond", "battle"],
["battleRenderFPS", "battle", "RENDER_FPS"],
["quitDelayAfterJumpOut", "battle"],
["gameStateDisplayDelay", "battle"],
["multiMatchQuitDelay", "battle"],
["endThemeCrossfadeDuration", "battle"],
["cameraDefaultTransitionDuration", "battle"],
["cameraDefaultTransitionStyle", "battle"],
["ambientMusic", "battle"],
["victoryMusic", "battle"],
["defeatMusic", "battle"],
["debriefingVictoryMusic", "battle"],
["debriefingDefeatMusic", "battle"],
["combatThemeDurationAfterFire", "battle"],
["debriefingThemeFadeInDuration", "battle"],
["useRequestAnimFrame", "general"],
["defaultRandomSeed", "general"],
["luminosityFactorsArrayName", "general", "UNIFORM_LUMINOSITY_FACTORS_ARRAY_NAME"],
["useVerticalCameraValues", "general"],
["menuMusic", "general"],
["musicFadeInDuration", "general"],
["themeCrossfadeDuration", "general"],
["musicFadeOutDuration", "general"],
["slowConnectionThreshold", "multi"],
["connectionLostThreshold", "multi"],
["disconnectThreshold", "multi"],
["defaultFOV", "camera", "DEFAULT_FOV"],
["defaultSpan", "camera"],
["defaultBaseOrientation", "camera"],
["defaultPointToFallback", "camera"]
],
getValueString = function (value) {
if (typeof value === "string") {
return '"' + value + '"';
}
if (Array.isArray(value)) {
return "\\[" + value.map(getValueString).join(", ") + "\\]";
}
if (typeof value === "object") {
var result = "{\\s*", property;
for (property in value) {
if (value.hasOwnProperty(property)) {
result += '"' + property + '": ' + getValueString(value[property]) + ",?\\s*";
}
}
result += "}";
return result;
}
return value.toString();
},
settingConfigReplacements = settingsToReplace.map(
function (replacement) {
var value = settings.logic[replacement[1]][replacement[0]],
setting = '"' + replacement[0] + '": ' + getValueString(value);
return {
// either remove a comma from before or after the setting (if there is any)
match: new RegExp(",\\s*" + setting + "|" + setting + ",*", "g"),
replacement: ""
};
}),
settingReplacements = settingsToReplace.map(
function (replacement) {
var constName = (replacement.length < 3) ? getConstName(replacement[0]) : replacement[2],
value = settings.logic[replacement[1]][replacement[0]];
return [{
// replacing usages of this setting
match: new RegExp("(config|this).getSetting\\((config.|)" + replacement[1].toUpperCase() + "_SETTINGS." + constName + "\\)", "g"),
replacement: (typeof value === "string") ? '"' + value + '"' : value
}, {
// removing the definition of this setting from configuration.js
match: new RegExp("\\s" + constName + ": {\\s*name: \"" + replacement[0] + "\"(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*}[,\\s]", "g"),
replacement: ""
}];
}),
databaseSettingsToReplace = [
["showLoadingBoxFirstTime"],
["showLoadingBoxOnItemChange"],
["backgroundColor"],
["itemViewDistance"],
["itemViewFOV", "ITEM_VIEW_FOV"],
["itemViewSpan"],
["showWireframeModel"],
["wireframeShaderName"],
["wireframeColor"],
["showSolidModel"],
["solidShaderName"],
["lightSources"],
["startSizeFactor"],
["minimumSizeFactor", "MIN_SIZE_FACTOR"],
["maximumSizeFactor", "MAX_SIZE_FACTOR"],
["modelAutoRotation"],
["modelMouseRotation"],
["rotationFPS", "ROTATION_FPS"],
["rotationRevealStartAngle"],
["rotationStartAngle"],
["rotationViewAngle"],
["rotationDuration"],
["rotationMouseSensitivity"],
["modelRevealAnimation"],
["revealColor"],
["revealFPS", "REVEAL_FPS"],
["revealDuration"],
["revealSolidDelayDuration"],
["revealTransitionLengthFactor"],
["databaseRenderFPS", "RENDER_FPS"]
],
databaseSettingConfigReplacements = databaseSettingsToReplace.map(
function (replacement) {
var value = settings.logic.database[replacement[0]],
setting = '"' + replacement[0] + '": ' + getValueString(value);
return {
// either remove a comma from before or after the setting (if there is any)
match: new RegExp(",\\s*" + setting + "|" + setting + ",*", "g"),
replacement: ""
};
}),
databaseSettingReplacements = databaseSettingsToReplace.map(
function (replacement) {
var constName = (replacement.length < 2) ? getConstName(replacement[0]) : replacement[1],
value = settings.logic.database[replacement[0]];
return [{
// replacing usages of this setting
match: new RegExp("_getSetting\\(SETTINGS." + constName + "\\)", "g"),
replacement: (typeof value === "string") ? '"' + value + '"' : value
}, {
// removing the definition of this setting from configuration.js
match: new RegExp("\\s" + constName + ": {\\s*name: \"" + replacement[0] + "\"(?:[^}{]+|{(?:[^}{]+|{[^}{]*})*})*}[,\\s]", "g"),
replacement: ""
}];
});
// flatten the replacements arrays
getterReplacementsCommon.reduce(function (acc, val) {
return acc.concat(val);
}, []);
getterReplacementsGame.reduce(function (acc, val) {
return acc.concat(val);
}, []);
setterReplacements.reduce(function (acc, val) {
return acc.concat(val);
}, []);
methodRemovals.reduce(function (acc, val) {
return acc.concat(val);
}, []);
exportedFunctionRemovals.reduce(function (acc, val) {
return acc.concat(val);
}, []);
settingReplacements.reduce(function (acc, val) {
return acc.concat(val);
}, []);
databaseSettingReplacements.reduce(function (acc, val) {
return acc.concat(val);
}, []);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
_requirejs: {
game: {
options: {
baseUrl: "js",
name: "main",
optimize: "uglify2",
uglify2: {
mangle: {
keep_fnames: false // turn on to keep minification but make error messages using constructor.name readable
}
},
out: "js/main.js",
preserveLicenseComments: false
}
},
editor: {
options: {
baseUrl: "js",
name: "editor-main",
optimize: "uglify2",
uglify2: {
mangle: {
keep_fnames: true
}
},
out: "js/editor-main.js",
preserveLicenseComments: false
}
}
},
_clean: {
full: ["config/", "css/", "data/", "js/", "dist/"],
editor: ["js/editor", "js/editor*"],
dist: ["js/*", "!js/main.js"],
distWithEditor: ["js/*", "!js/main.js", "!js/editor-main.js"],
snap: ["dist/"]
},
_copy: {
devData: {
files: [
{expand: true, cwd: 'src/config/', src: ['**'], dest: 'config/'},
{expand: true, cwd: 'src/data/', src: ['**'], dest: 'data/'}
]
},
distData: {
files: [
{expand: true, cwd: 'src/config/', src: ['**'], dest: 'config/'},
{expand: true, cwd: 'src/data/', src: ['**', '!test/**', '!missions/tests/**', 'missions/tests/test.json'], dest: 'data/'}
]
},
js: {
files: [
{expand: true, cwd: 'src/js/', src: ['**'], dest: 'js/'}
]
}
},
_sync: {
dev: {
files: [
{expand: true, cwd: 'src/config/', src: ['**'], dest: 'config/'},
{expand: true, cwd: 'src/data/', src: ['**'], dest: 'data/'},
{expand: true, cwd: 'src/js/', src: ['**'], dest: 'js/'}
]
}
},
_eslint: {
options: {
overrideConfigFile: ".eslintrc.js"
},
target: ["src/js/"]
},
_sass: {
dev: {
options: {
style: "expanded"
},
files: scssMappings
},
dist: {
options: {
noSourceMap: true,
style: "compressed"
},
files: scssMappings
}
},
_minify: {
config: {
files: 'config/**/*.json'
},
data: {
files: 'data/**/*.json'
}
},
_replace: {
distConfig: {
// removes setting values that have been baked into the game source
options: {
patterns: settingConfigReplacements.concat(databaseSettingConfigReplacements),
usePrefix: false
},
files: [
{expand: true, cwd: 'config/', src: ['settings.json'], dest: 'config/'}
]
},
distData: {
// removes test mission entries from missions.json
options: {
patterns: [
{
match: /,\s*{\s*"source":\s*"[^"]*",\s*"test":\s*true\s*}/g,
replacement: ''
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'data/', src: ['missions.json'], dest: 'data/'}
]
},
// these replacements should be applied to both the game and the editor
preOptimizeCommon: {
options: {
patterns: [
{
match: '_matrixCount++;',
replacement: '//_matrixCount++;'
}, {
match: 'application.log_DEBUG',
replacement: '//application.log_DEBUG'
}, {
match: '_DEBUG_STATS.',
replacement: '//_DEBUG_STATS.'
}, {
match: '|| application.crash()',
replacement: ''
}, {
match: 'application.crash();',
replacement: ''
}, {
match: 'application.isDebugVersion()',
replacement: 'false'
}, {
match: 'missionDescriptor.isTest()',
replacement: 'false'
}, {
match: 'if (this._shadowMapDebugging) {',
replacement: 'if (false) {'
}, {
match: 'graphics.isShadowMapDebuggingEnabled()',
replacement: 'false'
// -------------------------------------------------
// stereoscopy
}, {
match: 'graphics.isAnaglyphRenderingEnabled()',
replacement: 'false'
}, {
match: 'graphics.isSideBySideRenderingEnabled()',
replacement: 'false'
}, {
match: 'if (this._stereoscopicMode !== Scene.StereoscopicMode.NONE) {',
replacement: 'if (false) {'
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'js/', src: ['**'], dest: 'js/'}
]
},
// these replacements should only be applied to the game, and not the editor (removes hitbox visuals for example)
preOptimizeGame: {
options: {
patterns: [
{
match: 'if (preview) {',
replacement: 'if (false) {'
}, {
match: 'if (!preview) {',
replacement: 'if (true) {'
}, {
match: 'preview ? ',
replacement: 'false ? '
}, {
match: '_hitZoneColor =',
replacement: '//'
}, {
match: '_hitZoneColor,',
replacement: '//'
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'js/', src: ['**', '!editor', '!editor*'], dest: 'js/'}
]
},
// replacing some widely and frequently used one-line getter calls with the direct access of their respective properties to
// avoid the overhead of calling the getter functions
// these replacements should be applied to both the game and the editor
optimizeCommon: {
options: {
patterns: getterReplacementsCommon.concat(setterReplacements.concat(settingReplacements.concat(databaseSettingReplacements.concat([
{
match: '_scene.getLODContext()',
replacement: '_scene._lodContext'
}, {
match: '.getDefaultGroupLuminosityFactors()',
replacement: '._defaultLuminosityFactors'
}, {
match: 'setFileCacheBypassEnabled(true)',
replacement: 'setFileCacheBypassEnabled(false)'
}, {
match: 'if (_showHitboxesForHitchecks) {',
replacement: 'if (false) {'
}, {
match: '!silentDiscard',
replacement: 'false'
}, {
match: 'if (this._leftEye) {',
replacement: 'if (false) {'
}, {
match: 'if (this._rightEye) {',
replacement: 'if (false) {'
}
])))),
usePrefix: false
},
files: [
{expand: true, cwd: 'js/', src: ['**'], dest: 'js/'}
]
},
// these replacements should only be applied to the game, and not the editor (removes hitbox visuals for example)
optimizeGame: {
options: {
patterns: getterReplacementsGame.concat(methodRemovals.concat(exportedFunctionRemovals.concat(objectRemovals.concat(fieldRemovals.concat([
{
match: 'addSupplements.hitboxes',
replacement: 'false'
}, {
match: 'this._hitbox = null',
replacement: '//'
}, {
match: 'if (this._hitbox) {',
replacement: 'if (false) {'
}, {
match: 'if (hitbox) {',
replacement: 'if (false) {'
}
]))))),
usePrefix: false
},
files: [
{expand: true, cwd: 'js/', src: ['**', '!editor', '!editor*'], dest: 'js/'}
]
},
// these replacements should be applied to both the game and the editor
postOptimize: {
options: {
// shorten some commonly used long property/method names to make the build file smaller
patterns: [
{
match: '_positionMatrixInCameraSpaceValid',
replacement: 'pMCV'
}, {
match: '_positionMatrixInCameraSpace',
replacement: 'pMC'
}, {
match: '_positionMatrix',
replacement: 'pM'
}, {
match: '_orientationMatrix',
replacement: 'oM'
}, {
match: '_scalingMatrix',
replacement: 'sM'
}, {
match: '_cascadeScalingMatrix',
replacement: 'csM'
}, {
match: '_modelMatrixInverseValid',
replacement: 'mMIV'
}, {
match: '_modelMatrixInverse',
replacement: 'mMI'
}, {
match: '_modelMatrix',
replacement: 'mM'
}, {
match: '_visualModel',
replacement: 'vMo'
}, {
match: '_physicalModel',
replacement: 'pMo'
}, {
match: '_spacecraft',
replacement: '_sc'
}, {
match: '_weapon',
replacement: '_w'
}, {
match: '_projectile',
replacement: '_p'
}, {
match: '_missileLauncher',
replacement: '_mL'
}, {
match: '_missile',
replacement: '_m'
}, {
match: '_targetingComputer',
replacement: '_tC'
}, {
match: '_target',
replacement: '_t'
}, {
match: '_maneuveringComputer',
replacement: '_mC'
}, {
match: 'BATTLE_SETTINGS',
replacement: 'BS'
}, {
match: 'getHUDSetting',
replacement: 'gHS'
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'js/', src: ['**'], dest: 'js/'}
]
},
setSnap: {
options: {
patterns: [
{
match: /"platform":"\w+"/g,
replacement: '"platform":"snap"'
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'config/', src: ['config.json'], dest: 'config/'}
]
},
setAppimage: {
options: {
patterns: [
{
match: /"platform":"\w+"/g,
replacement: '"platform":"appimage"'
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'config/', src: ['config.json'], dest: 'config/'}
]
},
resetPlatform: {
options: {
patterns: [
{
match: /"platform":"\w+"/g,
replacement: '"platform":"web"'
}
],
usePrefix: false
},
files: [
{expand: true, cwd: 'config/', src: ['config.json'], dest: 'config/'}
]