/*
 * Copyright 2018 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.destinationsol.testingUtilities;

import org.destinationsol.entitysystem.EntitySystemManager;
import org.destinationsol.modules.ModuleManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.headless.HeadlessApplication;
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
import com.badlogic.gdx.graphics.GL20;
import org.destinationsol.SolApplication;
import org.destinationsol.game.DebugOptions;
import org.destinationsol.game.SolGame;
import org.terasology.gestalt.entitysystem.component.management.ComponentManager;

public final class InitializationUtilities {

    public static SolGame game;
    private static boolean initialized;

    private InitializationUtilities() { } // empty private constructor for utility class

    public static void init() {
        if (initialized) {
            return;
        }
        initialized = true;
        DebugOptions.DEV_ROOT_PATH = "engine/src/main/resources/";
        ModuleManager moduleManager;
        EntitySystemManager entitySystemManager;
        try {
            moduleManager = new ModuleManager();
            entitySystemManager = new EntitySystemManager(moduleManager.getEnvironment(), new ComponentManager());
        } catch (Exception ignore) {
            return;
        }
        GL20 mockGL = new MockGL();
        Gdx.gl = mockGL;
        Gdx.gl20 = mockGL;
        final HeadlessApplication application = new HeadlessApplication(new SolApplication(moduleManager, entitySystemManager, 100), new HeadlessApplicationConfiguration());
        game = ((SolApplication) application.getApplicationListener()).getGame();
    }
}

// Following lies the offering to the great vampire gods of SolUniverse, with great praises for them to keep local magic working.
//
//
//               __             _,-"~^"-.
//             _// )      _,-"~`         `.
//           ." ( /`"-,-"`                 ;
//          / 6                             ;
//         /           ,             ,-"     ;
//        (,__.--.      \           /        ;
//         //'   /`-.\   |          |        `._________
//           _.-'_/`  )  )--...,,,___\     \-----------,)
//         ((("~` _.-'.-'           __`-.   )         //
//               ((("`             (((---~"`         //
//                                                  ((________________
//                                                  `----""""~~~~^^^```



// (Read: the hack is ugly, but working and I don't wanna redo it)

@@ -640,68 +640,8 @@
 s;%0A%0A
-import org.destinationsol.entitysystem.EntitySystemManager;%0A
 impo
@@ -685,16 +685,16 @@
 anager;%0A
+
 import c
@@ -1022,90 +1022,8 @@
 ame;
-%0Aimport org.terasology.gestalt.entitysystem.component.management.ComponentManager;
 %0A%0Apu
@@ -1454,57 +1454,8 @@
 er;%0A
-        EntitySystemManager entitySystemManager;%0A
     
@@ -1517,123 +1517,8 @@
 ();%0A
-            entitySystemManager = new EntitySystemManager(moduleManager.getEnvironment(), new ComponentManager());%0A
     
@@ -1660,32 +1660,32 @@
 .gl20 = mockGL;%0A
+
         final He
@@ -1777,29 +1777,8 @@
 ger,
- entitySystemManager,
  100

fix test