Skip to content

Commit

Permalink
add export ic functions and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Traineratwot committed Mar 10, 2024
1 parent a951fa1 commit 30da368
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 191 deletions.
49 changes: 47 additions & 2 deletions WikiExtractorMod/BepInEx.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using Assets.Scripts;
using Assets.Scripts.Objects.Electrical;
using BepInEx;
using HarmonyLib;
using Newtonsoft.Json;
Expand All @@ -16,7 +15,7 @@ public class ExtractorBepInEx : BaseUnityPlugin
{
public const string pluginGuid = "net.elmo.stationeers.Extractor";
public const string pluginName = "Extractor";
public const string pluginVersion = "1.1";
public const string pluginVersion = "1.2";

private void Awake()
{
Expand All @@ -40,6 +39,52 @@ public static void Log(string line)
{
Debug.Log("[" + pluginName + "]: " + line);
}

public static void SaveJson(string name, object obj, string folder = "wiki_data")
{
var lang = Localization.CurrentLanguage;
name += ".json";
var json = JsonConvert.SerializeObject(obj);
var path = Path.Combine(
Application.dataPath,
folder,
lang.ToString(),
name
);
var folderPath = Path.Combine(Application.dataPath, folder, lang.ToString());

if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);

using (var writer = new StreamWriter(path))
{
writer.WriteLine(json);
}
}

public static string SpriteToBase64(Sprite sprite)
{
var lang = Localization.CurrentLanguage;
if (lang != LanguageCode.EN)
// убираем избыточноть в остальных языках
return null;

if (sprite == null) return null;

if (sprite.texture == null) return null;

var renderTexture = new RenderTexture(sprite.texture.width, sprite.texture.height, 0);
Graphics.Blit(sprite.texture, renderTexture);

var texture = new Texture2D(sprite.texture.width, sprite.texture.height);
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture.Apply();

var bytes = texture.EncodeToPNG();
var base64String = Convert.ToBase64String(bytes);

return base64String;
}
}

#endregion
Expand Down
Loading

0 comments on commit 30da368

Please sign in to comment.