Exemple #1
0
            /// Save data to Json File
            ///
            /// @param fileName
            ///     the file name
            /// @param saveData
            ///     Data to save
            /// @param onOverwriteDelegate
            ///     Function that is called if file already exists
            ///
            public static void SaveDataToJsonFile <T>(string fileName, T saveData, FileSystem.Location location = FileSystem.Location.Persistent, System.Func <string, bool> onOverwriteDelegate = null)
            {
#if UNITY_WEBGL
                return;
#endif

                string data = JsonWrapper.Serialize(saveData);

                if (FileSystem.DoesDirectoryExist(fileName, location))
                {
                    if ((onOverwriteDelegate == null) || (onOverwriteDelegate(fileName) == true))
                    {
                        FileSystem.WriteTextFile(data, fileName, location);
                    }
                }
                else
                {
                    FileSystem.WriteTextFile(data, fileName, location);
                }

#if UNITY_EDITOR
                //Only do refresh if were on the main thread
                if (GlobalDirector.Service <TaskSchedulerService>().IsMainThread())
                {
                    UnityEditor.AssetDatabase.Refresh();
                }
#endif
            }
Exemple #2
0
        /// Start of the Resolve state
        ///
        private void EnterStateResolve()
        {
            // Update moves
            SetMovesLeft(m_movesLeft - 1);

            // Pop the tiles
            m_coroutine = GlobalDirector.ExecuteCoroutine(StaggerTilesPop(() =>
            {
                m_coroutine = GlobalDirector.ExecuteCoroutine(StaggerReplaceTiles(() =>
                {
                    if (IsLevelCompleted() == true)
                    {
                        // Level success
                        m_fsm.ExecuteAction(k_actionWin);
                    }
                    else if (m_movesLeft > 0)
                    {
                        m_fsm.ExecuteAction(k_actionIdle);
                    }
                    else if (IsLevelCompleted() == true)
                    {
                        // Level success
                        m_fsm.ExecuteAction(k_actionWin);
                    }
                    else
                    {
                        // Level fail
                        m_fsm.ExecuteAction(k_actionLose);
                    }
                }));
            }));
        }
        /// @param cost
        ///     The cost to display
        ///
        /// @return The formatted cost string
        ///
        public static string LocaliseColouredCost(this CurrencyItem cost)
        {
            if (m_cachedBankService == null)
            {
                m_cachedBankService = GlobalDirector.Service <BankService>();
            }

            string costString = string.Empty;

            if (k_currencies.Contains(cost.m_currencyID) == true)
            {
                costString = cost.LocaliseCost();
            }
            else
            {
                if (cost.IsFree() == true)
                {
                    costString = k_free.LocaliseGame();
                }
                else
                {
                    int    current       = Math.Min(m_cachedBankService.GetBalance(cost.m_currencyID), cost.m_value);
                    string currentString = TextUtils.GetFormattedCurrencyString(current);
                    string formatID      = k_costFail;
                    if (m_cachedBankService.CanAfford(cost) == true)
                    {
                        formatID = k_costSuccess;
                    }
                    costString = string.Format(formatID.LocaliseGame(), cost.m_currencyID, TextUtils.GetFormattedCurrencyString(cost.m_value), currentString);
                }
            }
            return(costString);
        }
Exemple #4
0
 /// Start of the Load state
 ///
 private void EnterStateLoad()
 {
     // Create the level
     m_coroutine = GlobalDirector.ExecuteCoroutine(StaggerLevelCreation(() =>
     {
         // We're done loading
         m_fsm.ExecuteAction(k_actionNext);
     }));
 }
Exemple #5
0
 /// @param scores
 ///     The scores to achieve
 ///
 public void InitialiseScores(List <int> scores)
 {
     m_audioService = GlobalDirector.Service <AudioService>();
     m_scoreText.SafeText(TextUtils.GetFormattedCurrencyString(m_score));
     m_scores = scores;
     foreach (var star in m_starsProgress)
     {
         star.SetProgress(0.0f);
     }
 }
Exemple #6
0
        /// Initialise function
        ///
        protected override void Initialise()
        {
            m_bankService  = GlobalDirector.Service <BankService>();
            m_audioService = GlobalDirector.Service <AudioService>();
            m_popupService = GlobalDirector.Service <PopupService>();
            m_sceneService = GlobalDirector.Service <SceneService>();

            m_sceneService.OnSceneActive += OnSceneActive;
            if (s_instance.Contains(this) == false)
            {
                s_instance.Add(this);
            }
        }
Exemple #7
0
        /// @param newScore
        ///     The score to set
        /// @param callback
        ///     The function to call when the score finished updated
        ///
        public void SetScore(int newScore, Action callback = null)
        {
            // Update the text
            m_loopedSFX  = m_audioService.PlaySFXLooped(AudioIdentifiers.k_loopScoreCounting);
            m_tweenCount = m_scoreText.DOCount(m_score, newScore, 1.0f, () =>
            {
                m_loopedSFX.SafeStop();
                m_score = newScore;
            });

            // Update the stars
            m_coroutine = GlobalDirector.ExecuteCoroutine(StaggerStarProgress(newScore, callback));
        }
Exemple #8
0
        /// @param localDirector
        ///     The local director owner of the Controller
        /// @param view
        ///     The view of the scene
        /// @param cameraController
        ///     The camera controller
        ///
        public StartupController(LocalDirector localDirector, StartupView view)
            : base(localDirector, view)
        {
            m_view = view;

            m_saveService = GlobalDirector.Service <SaveService>();

            m_audioService.PlayMusic(AudioIdentifiers.k_musicMain);

            m_fsm.RegisterStateCallback(k_stateLoad, EnterStateLoad, null, null);
            m_fsm.RegisterStateCallback(k_stateOutro, EnterStateOutro, null, null);
            m_fsm.ExecuteAction(k_actionNext);
        }
Exemple #9
0
        /// @param localDirector
        ///     The local director owner of the Controller
        /// @param view
        ///     The view of the scene
        /// @param cameraController
        ///     The camera controller
        ///
        public MapController(LocalDirector localDirector, MapView view, CameraController cameraContoller)
            : base(localDirector, view, SceneIdentifiers.k_main)
        {
            m_view             = view;
            m_cameraController = cameraContoller;

            m_popupService = GlobalDirector.Service <PopupService>();

            m_audioService.PlayMusicFadeCross(AudioIdentifiers.k_musicMain);

            m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null);
            m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle);
            m_fsm.ExecuteAction(k_actionNext);
        }
Exemple #10
0
        /// @param localDirector
        ///     The local director owner of the Controller
        /// @param view
        ///     The view of the scene
        /// @param cameraController
        ///     The camera controller
        ///
        public LevelEditorController(LocalDirector localDirector, LevelEditorView view)
            : base(localDirector, view)
        {
            m_view = view;

            m_popupService = GlobalDirector.Service <PopupService>();
            m_levelService = GlobalDirector.Service <LevelService>();
            m_levelLoader  = GlobalDirector.Service <MetadataService>().GetLoader <LevelData>() as LevelDataLoader;

            m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null);
            m_fsm.RegisterStateCallback(k_stateLoad, EnterStateLoad, null, null);
            m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle);
            m_fsm.ExecuteAction(k_actionNext);
        }
Exemple #11
0
        /// @param localDirector
        ///     The local director owner of the Controller
        /// @param view
        ///     The view of the scene
        /// @param cameraController
        ///     The camera controller
        ///
        public MapNodeController(LocalDirector localDirector, MapNodeView view)
            : base(localDirector, view)
        {
            m_audioService = GlobalDirector.Service <AudioService>();
            m_popupService = GlobalDirector.Service <PopupService>();
            m_levelService = GlobalDirector.Service <LevelService>();

            MapNodeView = view;
            LevelModel  = m_levelService.GetLevelModel(MapNodeView.LevelIndex);
            MapNodeView.SetName(MapNodeView.LevelIndex.ToString());

            m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null);
            m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle);
            m_fsm.RegisterStateCallback(k_stateLocked, EnterStateLocked, null, ExitStateLocked);
            m_fsm.RegisterStateCallback(k_stateUnlock, null, null, ExitStateUnlock);
            m_fsm.RegisterStateCallback(k_stateDone, EnterStateDone, null, ExitStateDone);
            m_fsm.ExecuteAction(k_actionNext);
        }
        /// @param text
        ///     The text to localise
        /// @param category
        ///     The category to check
        /// @oaram args
        ///     The format arguments
        ///
        public static string LocaliseRandom(this string text, string category, params object[] args)
        {
            // Cache the localisation service if needed
            if (m_cachedLocalisationService == null)
            {
                m_cachedLocalisationService = GlobalDirector.Service <LocalisationService>();
            }

            // Localise the text
            string localisedText = m_cachedLocalisationService.GetRandomText(category, text);

            // Apply arguments if available
            if (args.Length > 0)
            {
                localisedText = string.Format(localisedText, args);
            }
            return(localisedText);
        }
Exemple #13
0
        /// @param localDirector
        ///     The local director owner of the Controller
        /// @param view
        ///     The view of the scene
        /// @param cameraController
        ///     The camera controller
        ///
        public LevelController(LocalDirector localDirector, LevelView view)
            : base(localDirector, view, SceneIdentifiers.k_map)
        {
            m_view = view;

            m_tileFactory      = localDirector.GetFactory <TileFactory>();
            m_levelService     = GlobalDirector.Service <LevelService>();
            m_popupService     = GlobalDirector.Service <PopupService>();
            m_objectiveService = localDirector.GetService <ObjectiveService>();

            m_audioService.PlayMusicFadeCross(AudioIdentifiers.k_musicLevel);

            m_fsm.RegisterStateCallback(k_stateInit, EnterStateInit, null, null);
            m_fsm.RegisterStateCallback(k_stateLoad, EnterStateLoad, null, null);
            m_fsm.RegisterStateCallback(k_stateIdle, EnterStateIdle, null, ExitStateIdle);
            m_fsm.RegisterStateCallback(k_stateShuffle, EnterStateShuffle, null, null);
            m_fsm.RegisterStateCallback(k_stateResolve, EnterStateResolve, null, ExitStateResolve);
            m_fsm.RegisterStateCallback(k_stateWin, EnterStateWin, null, null);
            m_fsm.RegisterStateCallback(k_stateLose, EnterStateLose, null, null);
            m_fsm.ExecuteAction(k_actionNext);
        }
Exemple #14
0
 /// Used to complete the initialisation in case the service depends
 /// on other Services
 ///
 public override void OnCompleteInitialisation()
 {
     m_sceneService = GlobalDirector.Service <SceneService>();
     m_levelLoader  = GlobalDirector.Service <MetadataService>().GetLoader <LevelData>() as LevelDataLoader;
     this.RegisterCaching();
 }
Exemple #15
0
 private void OnClick()
 {
     GlobalDirector.HandleMessage(message);
 }