Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Feature/custom snapshot launch (#1098)
Browse files Browse the repository at this point in the history
* Custom snapshot launch added

Allows user to set a custom snapshot for local launch. The snapshot can be selected at the GDK tools configuration window

* Disabled the custom snapshot path text field

* Changelog edit with the pull request #

* Implemented changes suggested by Martijn

Removed custom snapshot path from GdkToolsConfiguration class / Single local launch button that will load the selected snapshot

* Added customSnapshotPath PlayerPref abstraction

Added customSnapshotPath PlayerPref abstraction to the GdkToolsConfiguration class / When opening the snapshot selection window it now opens on the currently selected snapshot file folder.

* Update workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs

Co-Authored-By: Jamie Brynes <[email protected]>

* Update workers/unity/Packages/io.improbable.gdk.tools/LocalLaunch.cs

Co-Authored-By: Jamie Brynes <[email protected]>

* Update workers/unity/Packages/io.improbable.gdk.tools/LocalLaunch.cs

Co-Authored-By: Jamie Brynes <[email protected]>

* Suggested changes and fixed default folder

* Fix for initial case

* CHANGELOG.md conflict solved?

* CHANGELOG conflict solved - take 2

* CHANGELOG conflict solved - take 3

* Fixed wording on the CHANGELOG

* Update CHANGELOG.md

Co-Authored-By: Paul Balaji <[email protected]>

* Fixed minor issues

Removed unused directive and extra newline
  • Loading branch information
JayImprobable authored Aug 14, 2019
1 parent 1febf58 commit 3aa596c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Added the ability to connect to an arbitrary host/port combo for the `AlphaLocatorFlow`. [#1105](https://github.com/spatialos/gdk-for-unity/pull/1105)
- Added a `SpatialdManager` class for managing local deployments with `SpatialD` into `io.improbable.gdk.testutils`. [#1104](https://github.com/spatialos/gdk-for-unity/pull/1104)
- Added the ability to specify a snapshot to be used when launching a deployment in the Editor. [#1098](https://github.com/spatialos/gdk-for-unity/pull/1098)

### Changed

Expand Down
8 changes: 0 additions & 8 deletions workers/unity/Assets/Plugins/Editor.meta

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
Expand All @@ -20,6 +20,14 @@ public class GdkToolsConfiguration
public string DevAuthTokenFilepath => Path.Combine(DevAuthTokenFullDir, "DevAuthToken.txt");
public int DevAuthTokenLifetimeHours => TimeSpan.FromDays(DevAuthTokenLifetimeDays).Hours;

private const string CustomSnapshotPathPrefKey = "CustomSnapshotPath";

public string CustomSnapshotPath
{
get => PlayerPrefs.GetString(CustomSnapshotPathPrefKey, Path.GetFullPath("../../snapshots/default.snapshot"));
set => PlayerPrefs.SetString(CustomSnapshotPathPrefKey, value);
}

private static readonly string JsonFilePath = Path.GetFullPath("Assets/Config/GdkToolsConfiguration.json");

private GdkToolsConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class GdkToolsConfigurationWindow : EditorWindow
private const string DevAuthTokenSectionLabel = "Dev Auth Token Settings";
private const string DevAuthTokenLifetimeLabel = "Token lifetime (days)";
private const string CodeGeneratorLabel = "Code generator";
private const string CustomSnapshotPathLabel = "Selected snapshot path";
private const string ResetConfigurationButtonText = "Reset to default";
private const string SaveConfigurationButtonText = "Save";

Expand Down Expand Up @@ -85,6 +86,8 @@ public void OnGUI()

DrawCodeGenerationOptions();

DrawCustomSnapshotDir();

if (check.changed)
{
configErrors = toolsConfig.Validate();
Expand Down Expand Up @@ -160,5 +163,28 @@ private void DrawCodeGenerationOptions()

EditorGUIUtility.labelWidth = previousWidth;
}

private void DrawCustomSnapshotDir()
{
GUILayout.Label(CustomSnapshotPathLabel, EditorStyles.boldLabel);
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUI.DisabledScope(true))
{
EditorGUILayout.TextField(CustomSnapshotPathLabel, toolsConfig.CustomSnapshotPath);
}

if (GUILayout.Button("Open", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
{
var path = EditorUtility.OpenFilePanel("Select snapshot", toolsConfig.CustomSnapshotPath, "snapshot");

if (!string.IsNullOrEmpty(path))
{
toolsConfig.CustomSnapshotPath = path;
}
}
}
}
}
}
12 changes: 10 additions & 2 deletions workers/unity/Packages/io.improbable.gdk.tools/LocalLaunch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ private static void BuildConfigMenu()
[MenuItem("SpatialOS/Local launch %l", false, MenuPriorities.LocalLaunch)]
private static void LaunchMenu()
{
Debug.Log("Launching SpatialOS locally...");
GdkToolsConfiguration toolsConfig = GdkToolsConfiguration.GetOrCreateInstance();
if (!File.Exists(toolsConfig.CustomSnapshotPath))
{
Debug.LogError($"Snapshot {toolsConfig.CustomSnapshotPath} not found. Make sure the file exists and it has not been moved or renamed");
return;
}

Debug.Log($"Launching SpatialOS locally with snapshot {toolsConfig.CustomSnapshotPath}.");
EditorApplication.delayCall += LaunchLocalDeployment;
}

Expand Down Expand Up @@ -202,9 +209,10 @@ private static string GetClientLogFileFullPath()
public static void LaunchLocalDeployment()
{
BuildConfig();
GdkToolsConfiguration toolsConfig = GdkToolsConfiguration.GetOrCreateInstance();

var command = Common.SpatialBinary;
var commandArgs = "local launch --enable_pre_run_check=false";
var commandArgs = $"local launch --enable_pre_run_check=false --snapshot \"{toolsConfig.CustomSnapshotPath}\"";

var runtimeIp = EditorPrefs.GetString(Common.RuntimeIpEditorPrefKey);
if (!string.IsNullOrEmpty(runtimeIp))
Expand Down

0 comments on commit 3aa596c

Please sign in to comment.