Exemple #1
0
        public static void CreateBackendFolder()
        {
            var path = GetCurrentDirectoryPath();

            if (AssetDatabase.IsValidFolder(path + "/Backend"))
            {
                EditorUtility.DisplayDialog(
                    "Backend folder creation failed",
                    "Folder named 'Backend' already exists in this directory.",
                    "OK"
                    );
                return;
            }

            AssetDatabase.CreateFolder(path, "Backend");

            Templates.CreateScriptFromTemplate(
                path + "/Backend/PlayerEntity.cs",
                "PlayerEntity.txt",
                null
                );

            var preferences = UnisavePreferences.LoadOrCreate();

            preferences.BackendFolder = Str.Start(path + "/Backend", "Assets/")
                                        .Substring("Assets/".Length); // remove the first assets folder
            preferences.Save();
            Debug.Log(
                "New backend folder path has been stored in Unisave preferences"
                );
        }
Exemple #2
0
        public static void SetFolderAsBackend()
        {
            var path = GetSelectedDirectoryPath();

            if (path == null)
            {
                Debug.LogError("Selected asset is not a folder");
                return;
            }

            if (path.StartsWith("Assets/"))
            {
                path = path.Substring("Assets/".Length);
            }

            var preferences = UnisavePreferences.LoadOrCreate();

            preferences.BackendFolder = path;
            preferences.Save();

            Uploader
            .GetDefaultInstance()
            .UploadBackend(
                verbose: true,
                useAnotherThread: true
                );
        }
        private void TokensSlide()
        {
            TutorialGUI.Paragraph(
                "Copy the game token and editor key you will see after " +
                "game creation into these fields and click the button."
                );

            TutorialGUI.Form(() => {
                if (preferences == null)
                {
                    preferences = UnisavePreferences.LoadOrCreate();
                }

                preferences.GameToken = EditorGUILayout.TextField(
                    "Game token", preferences.GameToken
                    );
                preferences.EditorKey = EditorGUILayout.TextField(
                    "Editor key", preferences.EditorKey
                    );

                if (GUILayout.Button("Save preferences & upload the backend"))
                {
                    preferences.BackendFolder = BackendFolderPath;
                    preferences.Save();

                    Uploader
                    .GetDefaultInstance()
                    .UploadBackend(
                        verbose: true,
                        useAnotherThread: true
                        );
                }
            });
        }
Exemple #4
0
        private static ClientApplication CreateDefaultApplication()
        {
            SetNewFromPreferences(UnisavePreferences.LoadOrCreate());

            RegisterDisposeCaller(ClientApp);

            return(clientApp);
        }
        public override bool ShouldCloseImmediately()
        {
            if (preferences == null)
            {
                preferences = UnisavePreferences.LoadOrCreate();
            }

            return(preferences.BackendFolder == BackendFolderPath);
        }
Exemple #6
0
        /// <summary>
        /// Creates the default instance of the uploader
        /// that uses correct preferences.
        /// </summary>
        public static Uploader GetDefaultInstance()
        {
            // NOTE: There's not an easy way to keep the value.
            // Static field gets reset when the game is started.
            // It would have to use editor preferences which is an overkill.

            return(new Uploader(
                       UnisavePreferences.LoadOrCreate()
                       ));
        }
        public virtual void SetUp()
        {
            var env = new Env();

            SetUpDefaultEnv(env);

            // override with additional test configuration
            var preferences = UnisavePreferences.LoadOrCreate();

            if (preferences.TestingEnv != null)
            {
                var overrideEnv = Env.Parse(preferences.TestingEnv.text);
                env.OverrideWith(overrideEnv);
            }

            base.SetUp(
                GetGameAssemblyTypes(),
                env
                );
        }
        public virtual void SetUp()
        {
            // create testing client application
            ClientApp = new ClientApplication(
                UnisavePreferences.LoadOrCreate()
                );

            // prepare environment
            var env = new EnvStore();

            DownloadEnvFile(env);

            // create testing backend application
            App = Bootstrap.Boot(
                GetGameAssemblyTypes(),
                env,
                new SpecialValues()
                );

            // execute backend code locally
            ClientApp.Singleton <FacetCaller>(
                _ => new TestingFacetCaller(App, ClientApp)
                );

            // logging should go direct, we don't want to wait for app disposal
            // for writing logs to special values
            // HACK: this is a hack, see the ClientSideLog class for more
            App.Singleton <ILog>(_ => new ClientSideLog());

            // bind facades
            Facade.SetApplication(App);
            ClientFacade.SetApplication(ClientApp);

            // start with a blank slate
            ClientApp.Resolve <ClientSessionIdRepository>().StoreSessionId(null);
            ClearDatabase();
        }
 void OnDestroy()
 {
     ClientApplication.GetInstance().SetPreferences(
         UnisavePreferences.LoadOrCreate()
         );
 }
Exemple #10
0
        void OnGUI()
        {
            if (preferences == null)
            {
                preferences = UnisavePreferences.LoadOrCreate();
                OnPreferencesLoaded();
            }

            windowScroll = GUILayout.BeginScrollView(windowScroll);

            DrawUnisaveLogo();

            GUILayout.Label("Unisave server connection", EditorStyles.boldLabel);
            preferences.ServerUrl = EditorGUILayout.TextField("Server URL", preferences.ServerUrl);
            preferences.GameToken = EditorGUILayout.TextField("Game token", preferences.GameToken);
            preferences.EditorKey = EditorGUILayout.TextField("Editor key", preferences.EditorKey);

            GUILayout.Space(15f);

            GUILayout.Label("Backend folder uploading", EditorStyles.boldLabel);
            preferences.BackendFolder             = EditorGUILayout.TextField("Backend assets folder", preferences.BackendFolder);
            preferences.AutomaticBackendUploading = EditorGUILayout.Toggle("Automatic", preferences.AutomaticBackendUploading);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Manual", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
            if (GUILayout.Button("Upload", GUILayout.Width(50f)))
            {
                RunManualCodeUpload();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Last upload at", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
            EditorGUILayout.LabelField(preferences.LastBackendUploadAt?.ToString("yyyy-MM-dd H:mm:ss") ?? "Never");
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Backend hash", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
            EditorGUILayout.LabelField(
                string.IsNullOrWhiteSpace(preferences.BackendHash)
                                        ? "<not computed yet>"
                                        : preferences.BackendHash
                );
            EditorGUILayout.EndHorizontal();

//			GUILayout.Label("Environment configuration", EditorStyles.boldLabel);
//			preferences.DevelopmentEnv = (TextAsset) EditorGUILayout.ObjectField(
//				"Development", preferences.DevelopmentEnv, typeof(TextAsset), false
//			);
//			preferences.TestingEnv = (TextAsset) EditorGUILayout.ObjectField(
//				"Testing", preferences.TestingEnv, typeof(TextAsset), false
//			);

            GUILayout.Space(30f);

            GUILayout.Label("Changes to configuration are saved automatically.");

            GUILayout.Space(30f);

            GUILayout.Label("Unisave framework version: " + FrameworkMeta.Version);

            GUILayout.EndScrollView();

            // detect mouse leave
            if (Event.current.type == EventType.MouseLeaveWindow)
            {
                OnLostFocus();
            }
        }
        protected override IPromise <JsonValue> PerformFacetCall(
            string facetName,
            string methodName,
            JsonArray arguments
            )
        {
            var env = new Env();

            // override with additional dev configuration
            var preferences = UnisavePreferences.LoadOrCreate();

            if (preferences.DevelopmentEnv != null)
            {
                var overrideEnv = Env.Parse(preferences.DevelopmentEnv.text);
                env.OverrideWith(overrideEnv);
            }

            var app = Bootstrap.Boot(
                GetGameAssemblyTypes(),
                env,
                new SpecialValues()
                );

            Facade.SetApplication(app);

            PerformContainerSurgery(app);

            JsonValue returnedJson;

            try
            {
                // BEGIN RUN THE APP

                var methodParameters = new FacetCallKernel.MethodParameters(
                    facetName,
                    methodName,
                    arguments,
                    SessionId
                    );

                var kernel = app.Resolve <FacetCallKernel>();

                returnedJson = kernel.Handle(methodParameters);

                // END RUN THE APP
            }
            finally
            {
                SaveDatabase();

                Facade.SetApplication(null);

                var specialValues = app.Resolve <SpecialValues>();

                app.Dispose();

                SessionId = specialValues.Read("sessionId").AsString;
                LogPrinter.PrintLogsFromFacetCall(specialValues.Read("logs"));

                OnFacetCalled?.Invoke();
            }

            return(Promise <JsonValue> .Resolved(returnedJson));
        }