Working saving / loading from the IC10Editor mod. Removed all patches until they can be properly re-implemented
All checks were successful
CI/CD Pipeline / test (pull_request) Successful in 35s
CI/CD Pipeline / build (pull_request) Has been skipped
CI/CD Pipeline / release (pull_request) Has been skipped

This commit is contained in:
2025-12-24 01:24:16 -07:00
parent 5230c620e8
commit 42b0b0acf9
9 changed files with 57 additions and 430 deletions

View File

@@ -1,27 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace Slang;
public static class GlobalCode
{
public const string SLANG_REF = "#SLANG_REF:";
public const string SLANG_SRC = "SLANG_SRC";
/// <summary>
/// This is the OLD way of handling saving / loading. This has been replaced with a native
/// save / load from IC10 Editor. However; this needs to remain for compatibility with
/// previous versions of code not compiled with 0.4.2 or later.
/// </summary>
public const string SLANG_SRC = "#SLANG_SRC:";
// This is a Dictionary of ENCODED source code, compressed
// so that save file data is smaller
private static Dictionary<Guid, string> codeDict = new();
// This Dictionary stores the source maps for the given SLANG_REF, where
// the key is the IC10 line, and the value is a List of Slang ranges where that
// line would have come from
/// <summary>
/// This Dictionary stores the source maps for the given SLANG_REF, where
/// the key is the IC10 line, and the value is a List of Slang ranges where that
/// line would have come from
/// </summary>
private static Dictionary<Guid, Dictionary<uint, List<Range>>> sourceMaps = new();
public static void ClearCache()
{
codeDict.Clear();
}
public static void SetSourceMap(Guid reference, List<SourceMapEntry> sourceMapEntries)
{
var builtDictionary = new Dictionary<uint, List<Range>>();
@@ -69,49 +69,4 @@ public static class GlobalCode
slangSpan = foundRange[0];
return true;
}
public static string GetSource(Guid reference)
{
if (!codeDict.ContainsKey(reference))
{
return string.Empty;
}
return DecodeSource(codeDict[reference]);
}
public static void SetSource(Guid reference, string source)
{
codeDict[reference] = EncodeSource(source);
}
public static string? GetEncoded(Guid reference)
{
if (!codeDict.ContainsKey(reference))
return null;
return codeDict[reference];
}
public static void SetEncoded(Guid reference, string encodedSource)
{
if (codeDict.ContainsKey(reference))
{
codeDict[reference] = encodedSource;
}
else
{
codeDict.Add(reference, encodedSource);
}
}
private static string EncodeSource(string source)
{
return SlangFormatter.EncodeSource(source, SLANG_SRC);
}
private static string DecodeSource(string source)
{
return SlangFormatter.DecodeSource(source, SLANG_SRC);
}
}