Skip to content

Commit

Permalink
Merge branch 'experiments/moonsharp' of https://github.com/ixxyxr/ope…
Browse files Browse the repository at this point in the history
…n-brush into experiments/moonsharp
  • Loading branch information
andybak committed Apr 16, 2024
2 parents 69f1e72 + 2fbe853 commit 0bbacb2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
17 changes: 17 additions & 0 deletions Assets/Scripts/API/ApiMethods.GlobalCommands.cs
Expand Up @@ -33,6 +33,23 @@ public static void SaveOverwrite()
SketchControlsScript.m_Instance.IssueGlobalCommand(rEnum, -1, -1);
}

[ApiEndpoint(
"save.as",
"Saves the current scene under a new name. (No need to include the .tilt suffix)",
"newSketch"
)]
public static void SaveAs(string filename)
{
string suffix = SaveLoadScript.TILT_SUFFIX;
if (filename.EndsWith(suffix))
{
filename = filename.Substring(0, filename.Length - suffix.Length);
}
var rEnum = SketchControlsScript.GlobalCommands.SaveAs;
SketchControlsScript.m_Instance.IssueGlobalCommand(rEnum, sParam: filename);
}

[ApiEndpoint("save.new", "Saves the current scene in a new slot")]
public static void SaveNew()
{
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/API/ApiMethods.cs
Expand Up @@ -594,6 +594,16 @@ public static ImageWidget ImportImage(string location)
return imageWidget;
}

[ApiEndpoint(
"image.extrude",
"Sets an image to be extruded by a given depth and color. Set depth to 0 to remove extrusion.",
"0.5, 0.5, 0.5, 1")]
public static void ExtrudeImage(int index, float depth, Color color)
{
var imageWidget = _GetActiveImage(index);
imageWidget.SetExtrusion(depth, color);
}

[ApiEndpoint(
"environment.type",
"Sets the current environment",
Expand Down
62 changes: 31 additions & 31 deletions Assets/Scripts/Save/SaveLoadScript.cs
Expand Up @@ -263,13 +263,17 @@ public void ResetLastFilename()
}

// Create a name that is guaranteed not to exist.
public string GenerateNewUntitledFilename(string directory, string extension)
public string GenerateNewFilename(string desiredFilename, string directory, string extension)
{
int iIndex = m_LastNonexistentFileIndex;
int iSanity = 9999;
while (iSanity > 0)
{
string attempt = UNTITLED_PREFIX + iIndex.ToString();
string attempt = desiredFilename;
if (iIndex > 0)
{
attempt += "_" + iIndex;
}
--iSanity;
++iIndex;

Expand All @@ -280,35 +284,23 @@ public string GenerateNewUntitledFilename(string directory, string extension)
return attempt;
}
}

Debug.Assert(false, "Could not generate a name");
return null;
}


// Create a name that is guaranteed not to exist.
public string GenerateNewUntitledFilename(string directory, string extension)
{
string filename = UNTITLED_PREFIX;
return GenerateNewFilename(filename, directory, extension);
}

// Create a Tiltasaurus based name that is guaranteed not to exist.
public string GenerateNewTiltasaurusFilename(string directory, string extension)
{
int iIndex = 0;
int iSanity = 9999;
while (iSanity > 0)
{
string attempt = TILTASAURUS_PREFIX + Tiltasaurus.m_Instance.Prompt;
if (iIndex > 0)
{
attempt += "_" + iIndex.ToString();
}
--iSanity;
++iIndex;

attempt = Path.Combine(directory, attempt) + extension;
if (!File.Exists(attempt) && !Directory.Exists(attempt))
{
return attempt;
}
}

Debug.Assert(false, "Could not generate a name");
return null;
string filename = TILTASAURUS_PREFIX + Tiltasaurus.m_Instance.Prompt;
return GenerateNewFilename(filename, directory, extension);
}

public void SaveOverwriteOrNewIfNotAllowed()
Expand Down Expand Up @@ -355,11 +347,21 @@ public string TransferredSourceIdFrom(SceneFileInfo info)
}
}

public DiskSceneFileInfo GetNewNameSceneFileInfo(bool tiltasaurusMode = false)
public DiskSceneFileInfo GetNewNameSceneFileInfo(bool tiltasaurusMode = false, string filename = null)
{
DiskSceneFileInfo fileInfo = tiltasaurusMode
? new DiskSceneFileInfo(GenerateNewTiltasaurusFilename(m_SaveDir, TILT_SUFFIX))
: new DiskSceneFileInfo(GenerateNewUntitledFilename(m_SaveDir, TILT_SUFFIX));
string uniquePath;
// If no filename is passed in then generate one
if (string.IsNullOrWhiteSpace(filename))
{
uniquePath = tiltasaurusMode
? GenerateNewTiltasaurusFilename(m_SaveDir, TILT_SUFFIX)
: GenerateNewUntitledFilename(m_SaveDir, TILT_SUFFIX);
}
else
{
uniquePath = GenerateNewFilename(filename, m_SaveDir, TILT_SUFFIX);
}
DiskSceneFileInfo fileInfo = new DiskSceneFileInfo(uniquePath);
if (m_LastSceneFile.Valid)
{
fileInfo.SourceId = TransferredSourceIdFrom(m_LastSceneFile);
Expand Down Expand Up @@ -407,9 +409,7 @@ public IEnumerator<Timeslice> SaveNewName(bool tiltasaurusMode = false)

public IEnumerator<Timeslice> SaveAs(string filename)
{
string path = Path.Join(m_SaveDir, filename);
Debug.Log($"SaveAs: {path}");
return SaveLow(GetSceneFileInfoFromName(path));
return SaveLow(GetNewNameSceneFileInfo(false, filename));
}

/// In order to for this to work properly:
Expand Down

0 comments on commit 0bbacb2

Please sign in to comment.