Beispiel #1
0
        static void Main(string[] args)
        {
            // Set up the startup path of the application.
            StartupPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Check the folders and files in the system.
            FolderSystem.Check();

            // Load the game data.
            DataManager.Load();

            // Start the network.
            NetworkManager.Initialize();

            // Initialize the scripting system.
            ScriptManager.Initialize();

            // Set up the Destroy Server event handlers.
            Console.WriteLine("[IMPORTANT INFORMATION] : ");
            Console.WriteLine("------------------------------------------------------------------------------");
            Console.WriteLine("Remember to turn off the server by pressing [CTRL + C] or [CTRL + BREAK].");
            Console.WriteLine("If you do not, all online player's data will NOT be saved.");
            Console.WriteLine("------------------------------------------------------------------------------");
            Console.CancelKeyPress += (s, e) => {
                Destroy();
            };

            //new Form1().Show();

            // Start the gameloop.
            GameLoop();
        }
Beispiel #2
0
    public SaveableScene prepareNextScene(string sceneName, List <IRestorableGameObject> transferToNextScene, bool loadScene = true)
    {
        SaveableScene result = getScene(sceneName);

        FirstTimeSceneLoaded = !loadScene;
        ///check if the scene is loaded already
        if (result == null)
        {
            ///if the scene was not loaded, check if it is even existing as a file in the game folder
            if (sceneExists(sceneName))
            {
                ///if the scene exists in a file load it
                result = GameDataController.LoadSaveable <SaveableScene>(FolderSystem.getSceneSavePath(GameName, sceneName));
                /////create new Scene list. Since its marked as "NonSerialized" its null after loading
                //AllScenes = new List<SaveableScene>();
                addScene(result);
            }
            else
            {
                ///if the scene doesnt exist in file, create a new scene
                result = addNewScene(sceneName);
                ///since the scene was not existing already, "KeepExistingObjects"
                ///is set to true, as the scene objects
                ///should not be deleted when first entering a scene
                FirstTimeSceneLoaded = true;
            }
        }
        CurrentScene = result;
        CurrentScene.initiateLoadedScene();

        CurrentScene.TransferedObjectTree = transferToNextScene;
        return(result);
    }
Beispiel #3
0
 public static bool FileExists(string username)
 {
     if (FolderSystem.FileExists(Folder + username + ".xml"))
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// loads all saved games slots, to show the load choices
 /// </summary>
 public void LoadSaveSlots()
 {
     foreach (string s in FolderSystem.getAllSaveSlotNames())
     {
         SaveableGame game = LoadSaveable <SaveableGame>
                                 (FolderSystem.getGameSavePath(Path.GetFileName(s)));
         allSavedGames.Add(game);
     }
 }
        public Task <FolderSystem> GetFolderSystem(FFBUser user)
        {
            if (user.Bookmarks is null || user.Folders is null)
            {
                user.Initialize();
            }

            var sys = new FolderSystem(user);

            return(Task.FromResult(sys));
        }
Beispiel #6
0
    private PersistentGameDataController()
    {
        Debug.Log(FolderSystem.getDefaultSaveSlotPath());

        initializeSavePath();

        CheckForExistingSettings();

        LoadSaveSlots();

        initializeEvents();
    }
Beispiel #7
0
    private GamePersistence()
    {
        Debug.Log("Game Data will be saved here: " + FolderSystem.GetDefaultSaveSlotPath());

        InitializeSavePath();

        CheckForExistingSettings();

        LoadSaveSlots();

        InitializeEvents();
    }
Beispiel #8
0
        static void Main(string[] args)
        {
            // Set up the startup path of the application.
            StartupPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Check the folders and files in the system.
            FolderSystem.Check();

            // Initialize the game form.
            Window = new GameWindow(960, 640);

            // Initialize the event-handlers and properties.
            Window.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            Window.StartPosition   = System.Windows.Forms.FormStartPosition.CenterScreen;
            Window.MaximizeBox     = false;
            Window.FormClosing    += (sender, e) => {
                switch (Program.State)
                {
                case (int)GameState.Wait:
                case (int)GameState.Main:
                    NetworkManager.PacketManager.SendRequestChangeClientState(GameState.Login);
                    break;

                case (int)GameState.Loading:
                    // Do nothing.
                    break;

                case (int)GameState.Game:
                    NetworkManager.PacketManager.SendRequestChangeClientState(GameState.Main);
                    break;

                default:
                    Running = false;
                    break;
                }

                e.Cancel = true;
            };

            // Load the game data.
            DataManager.Load();

            // Initialize the game graphics.
            GraphicsManager.Initialize();

            // Start the network.
            NetworkManager.Initialize();

            // Start the gameloop.
            GameLoop();
        }
        private static bool DropChecks(FolderSystem data, BaseBookmarkData dropped, BaseBookmarkData droppedOn)
        {
            if (data is null || dropped is null || droppedOn is null)
            {
                return(false);
            }

            if (dropped.Id == droppedOn.Id)
            {
                return(false);
            }

            return(true);
        }
Beispiel #10
0
        public static bool VerifyAccount(string username, string password)
        {
            if (FolderSystem.FileExists(Folder + username + ".xml"))
            {
                Account player = new Account();
                player = Serialization.Deserialize <Account>(Folder + username + ".xml", player.GetType());

                if (player.Password == Encryption.Encrypt(password))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #11
0
    /// <summary>
    /// will load the existing settings or create them, if they didnt exist before.
    /// </summary>
    private void CheckForExistingSettings()
    {
        string settingsSavepath = FolderSystem.getSettingsPath();

        ///initialize and save if not exisiting
        if (!File.Exists(settingsSavepath))
        {
            settings = new Settings();
            Save(settingsSavepath, settings);
        }
        else
        {
            ///save, if settings file exists
            settings = LoadSaveable <Settings>(settingsSavepath);
        }
    }
Beispiel #12
0
        // The main point of entry for the application.
        private static void Main(string[] args)
        {
            // Check the folders and files in the system.
            FolderSystem.Check();

            // Load the game data.
            DataManager.Load();

            // Initialize the audio system.
            AudioManager.Initialize();

            // Initialize the game graphics.
            GraphicsManager.Initialize();

            // Start the game-loop.
            TowerDefense.GameLoop();
        }
Beispiel #13
0
    private void SaveGameAndScenesToFile(string saveName)
    {
        FolderSystem.createNewSaveSlotDirectory(saveName);

        ///save game
        Save(FolderSystem.getGameSavePath(currentGame.GameName), currentGame);

        ///create or overwrite all changed scenes
        foreach (SaveableScene s in currentGame.AllScenes)
        {
            ///if the scene exists, but was not changed since the last save, it doesnt need to be saved again
            if (s.DirtyData)
            {
                Save(FolderSystem.getSceneSavePath(currentGame, s.SceneName), s);
                s.DirtyData = false;
            }
        }
    }
        public static void CompleteReorder(FolderSystem data, BaseBookmarkData dropped, BaseBookmarkData droppedOn, int indexMod)
        {
            if (!DropChecks(data, dropped, droppedOn))
            {
                return;
            }

            switch (dropped)
            {
            case InteractiveFolder folder:
                DroppedFolder(data, folder, droppedOn, indexMod);
                break;

            case FanficBookmark fic:
                DroppedFic(data, fic, droppedOn, indexMod);
                break;
            }
        }
Beispiel #15
0
        // The main point of entry for the application.
        private static void Main(string[] args)
        {
            // Check the folders and files in the system.
            FolderSystem.Check();

            // Load the game data.
            DataManager.Load();

            // Initialize the audio system.
            AudioManager.Initialize();
            AudioManager.Player.PlayMusic("McGameJam.flac", true);

            // Initialize the game graphics.
            GraphicsManager.Initialize();

            // Start the game-loop.
            Game.GameLoop();
        }
Beispiel #16
0
    public void loadGame(GamePersistence gameDataController)
    {
        SaveableGame.GameDataController = gameDataController;

        SaveableScene loadedScene = GameDataController.LoadSaveable <SaveableScene>
                                        (FolderSystem.getSceneSavePath(GameName,
                                                                       CurrentSceneName));

        ///reset scene list so no changes made before loading are interfering
        AllScenes = new List <SaveableScene>();

        addScene(loadedScene);
        CurrentScene = loadedScene;
        CurrentScene.initiateLoadedScene();

        ///load new scene
        SceneManager.LoadScene(CurrentSceneName);
    }
        private static int GetIndex(FolderSystem data, BaseBookmarkData item)
        {
            if (InteractiveFolder.TryGetFolder(data.Home, item.Parent ?? data.Home, out InteractiveFolder f))
            {
                switch (item)
                {
                case FanficBookmark mark:
                    return(f.Contents.IndexOf(mark));

                case InteractiveFolder folder:
                    return(f.Folders.IndexOf(folder));

                case BookmarkFolder bFolder:
                    return(f.Folders.FindIndex(x => x.Id == bFolder.Id));
                }
            }

            return(-1);
        }
Beispiel #18
0
    /// <summary>
    /// returns a list of all scenen names which are in the scene folder of
    /// the current game, but are not in the list of all scenes
    /// </summary>
    /// <returns></returns>
    public List <string> getAllNotLoadedScenePaths()
    {
        List <string> result = new List <string>();

        string defaultScenePath = FolderSystem.getDefaulScenePath(GameName);

        ///read all scenes of current game
        foreach (string s in Directory.GetFiles(defaultScenePath))
        {
            string currentFileName = Path.GetFileNameWithoutExtension(s);
            ///every not loaded scene is added to list
            if (!isSceneLoaded(currentFileName))
            {
                result.Add(s);
            }
        }

        return(result);
    }
    private static void checkAsset <T>(string currentPath, T assetRef, System.Func <T, string> getName, System.Action <T, string> onCheckDone = null) where T : Object, IAssetRefMaintainer
    {
        string newRelativeAssetPath;

        assetRef.GetInitializer().InitializeAsset(assetRef);
        IAssetReferencer r = assetRef.GetReferencer();

        r.AssetExtension = Path.GetExtension(currentPath).Remove(0, 1);
        ///check if the prefab is already in the correct directory
        if (currentPath.IndexOf(RelativeResourceFolderPath) != 0)
        {
            newRelativeAssetPath = currentPath.Insert
                                       (currentPath.IndexOf("/"), "/" + RESOURCE_FOLDER_NAME + "/" + r.AssetExtension);
        }
        else
        {
            newRelativeAssetPath = currentPath;
        }

        string newRelativePrefabDirectory = newRelativeAssetPath.Substring(0, newRelativeAssetPath.LastIndexOf('/'));
        string assetMoveErrorMessage      = null;

        ///only move the asset when its not already located in the resourceFolder
        if (currentPath.IndexOf(RelativeResourceFolderPath) != 0)
        {
            FolderSystem.createAssetPath(newRelativePrefabDirectory.Split('/'));
            assetMoveErrorMessage = AssetDatabase.MoveAsset(currentPath, newRelativeAssetPath);
        }

        if (string.IsNullOrEmpty(assetMoveErrorMessage))
        {
            r.AssetName = getName(assetRef);
            string pathFromAssetFolder = newRelativePrefabDirectory.Remove(0, RelativeResourceFolderPath.Length + 1);
            r.WasAlreadyValidated      = true;
            r.RelativePathFromResource = pathFromAssetFolder;
            onCheckDone?.Invoke(assetRef, newRelativeAssetPath);
        }
        else
        {
            Debug.LogError("Asset couldnt be moved to path: " + newRelativePrefabDirectory + ". Error: " + assetMoveErrorMessage);
        }
    }
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();

            // Check the folders and files in the system.
            FolderSystem.Check();

            // Load the client data.
            DataManager.Load();

            // Start the network.
            NetworkManager.Initialize();

            // Initialize the plugin manager.
            PluginManager.Initialize();

            // Initialize the scripting system.
            ScriptManager.Initialize();

            Application.Run(Window);
        }
Beispiel #21
0
    public void LoadGame_(int index)
    {
        timer.start("started loading");
        lock (SyncRoot)
        {
            IsDataRestored = true;

            IsLoading = true;

            internIsLoading = true;

            ///reload game out of file (in case a reference changed something)
            allSavedGames[index] = LoadSaveable <SaveableGame>
                                       (FolderSystem.getGameSavePath(allSavedGames[index].GameName));

            timer.addCheckPoint("read data out of file");

            ///clones the save slot, so it can be edited without altering the save slot
            currentGame = allSavedGames[index];

            currentGame.loadGame(this);
        }
    }
        private static void DroppedFolder(FolderSystem data, InteractiveFolder folder, BaseBookmarkData droppedOn, int indexMod)
        {
            // Dont worry about adding a negative index mod, because then it moves the item two spaces instead of one.
            var         index = GetIndex(data, droppedOn) + (indexMod > 0 ? 1 : 0);
            FolderModel folderModel;

            switch (droppedOn)
            {
            case InteractiveFolder droppedOnFolder:
                if (indexMod == 0)
                {
                    folderModel = new FolderModel(folder, 0)
                    {
                        ParentFolder = droppedOnFolder.Id.ToString()
                    };
                    data.UpdateFolder(folderModel);
                }
                else
                {
                    folderModel = new FolderModel(folder, index)
                    {
                        ParentFolder = droppedOnFolder.Parent?.Id.ToString() ?? Guid.Empty.ToString()
                    };
                    data.UpdateFolder(folderModel);
                }
                break;

            case FanficBookmark droppedOnFic:
                folderModel = new FolderModel(folder, index)
                {
                    ParentFolder = droppedOnFic.Parent?.Id.ToString() ?? Guid.Empty.ToString()
                };
                data.UpdateFolder(folderModel);
                break;
            }
        }
        private static void DroppedFic(FolderSystem data, FanficBookmark fic, BaseBookmarkData droppedOn, int indexMod)
        {
            var         index = GetIndex(data, droppedOn) + (indexMod > 0 ? 1 : 0);
            FanficModel ficModel;

            switch (droppedOn)
            {
            case InteractiveFolder droppedOnFolder:
                ficModel = new FanficModel(fic, 0)
                {
                    ParentFolder = droppedOnFolder.Id.ToString()
                };
                data.UpdateFanfic(ficModel);
                break;

            case FanficBookmark droppedOnFic:
                ficModel = new FanficModel(fic, index)
                {
                    ParentFolder = droppedOnFic.Parent?.Id.ToString() ?? Guid.Empty.ToString()
                };
                data.UpdateFanfic(ficModel);
                break;
            }
        }
Beispiel #24
0
 private void SaveSettings_()
 {
     Save(FolderSystem.getSettingsPath(), settings);
 }
Beispiel #25
0
 private void initializeSavePath()
 {
     FolderSystem.createDefaultFolderSystem();
 }
Beispiel #26
0
 public void Update(FolderSystem system)
 {
     Folders   = system.Folders;
     Bookmarks = system.Bookmarks;
 }
Beispiel #27
0
 /// <summary>
 /// returns true when the requested scene is either in the scenelist or saved to a file
 /// </summary>
 /// <param name="sceneName"></param>
 /// <returns></returns>
 public bool sceneExists(string sceneName)
 {
     return(isSceneLoaded(sceneName) ||
            FolderSystem.sceneExists(GameName, sceneName));
 }
Beispiel #28
0
    private bool SaveGame_(string saveName, out string resultMessage)
    {
        timer.start("Save Game");
        bool result = true;
        // try
        // {
        SaveableGame overwriteThis =
            allSavedGames.Where(game => game.GameName == saveName).FirstOrDefault();

        ///if a game is overwritten, and its not the current game,
        ///or a new save slot is created the current
        ///game has to be reloaded from file, to avoid two games
        ///in the game list have the same reference
        bool overwriteCurrent = saveName == currentGame.GameName;

        ///the current game index is used, to destroy the reference between the
        ///original loaded game and the new save slot.
        int currentGameIndex = -1;

        ///this is only needed, when a different save slot than the current
        ///is used or no save slot is overwritten (new one or other)
        if (!overwriteCurrent || overwriteThis == null)
        {
            currentGameIndex = allSavedGames.IndexOf(currentGame);
        }

        string oldGameName = currentGame.GameName;

        ///converts all objects into saveable objects
        currentGame.saveCurrentScene(PersistentGameDataController.SaveType.Game);

        timer.addCheckPoint("current scene saved");

        currentGame.GameName = saveName;

        if (overwriteThis != null && !overwriteCurrent)
        {
            allSavedGames.Remove(overwriteThis);
            FolderSystem.DeleteGame(overwriteThis);
            overwriteThis = null;
        }

        ///store game and loaded scenes in file
        SaveGameAndScenesToFile(saveName);

        ///if a new save slot is created, all not loaded scenes must be copied
        ///in the new director, so all data is transfered
        if (overwriteThis == null)
        {
            ///only copy if the current game exists in the savedGameList
            if (currentGameIndex >= 0)
            {
                CopyAllNotLoadedScenesToDirectory
                    (FolderSystem.getDefaulScenePath(saveName));
            }
            allSavedGames.Add(currentGame);
        }

        ///if the index is bigger equals zero the old game should/will be reloaded
        ///to avoid two saved games reference to the same saveableGame
        if (currentGameIndex >= 0)
        {
            ///load old game and set it in the savedgame list
            allSavedGames[currentGameIndex] = LoadSaveable <SaveableGame>
                                                  (FolderSystem.getGameSavePath(oldGameName));
        }

        resultMessage = "Game saved.";
        result        = true;

        /*  }
         * catch (System.Exception ex)
         * {
         *    ///if an error occured, the first attempt to fix it, is to
         *    ///reload the existing games out of the files
         *    loadSaveSlots();
         *    resultMessage = "An error occured while saving the game: " +
         *        ex.ToString() + ", StackTrace:" + ex.StackTrace;
         *    result = false;
         *    Debug.LogWarning(resultMessage);
         * }*/
        timer.finish("finished saving");
        return(result);
    }