Skip to content

Commit 6c4cd92

Browse files
committed
feat(core): add tutorial interlude 3 code
1 parent f5681bc commit 6c4cd92

6 files changed

Lines changed: 37 additions & 8 deletions

File tree

Assets/Scripts/GameData.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ public class GameData : BinarySerializable
4343
public GamePlayerData[] players;
4444
public Vector3 camPosition;
4545

46-
private static string _GetFilePath()
46+
public static string GetFolderPath()
4747
=> System.IO.Path.Combine(
4848
Application.persistentDataPath,
4949
DATA_DIRECTORY,
5050
"Games",
51-
gameUid,
52-
DATA_FILE_NAME);
51+
gameUid);
52+
53+
private static string _GetFilePath()
54+
=> System.IO.Path.Combine(GetFolderPath(), DATA_FILE_NAME);
5355

5456
public GameData() { }
5557

Assets/Scripts/Managers/MainMenuManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ private void _PopulateLoadsList()
258258
map = mapsByScene[sceneName];
259259
GameObject g = Instantiate(menuScenePickPrefab, loadGameScrollview);
260260
t = g.transform;
261-
s = Resources.Load<Sprite>($"MapCaptures/{map.sceneName}");
261+
s = Utils.LoadSpriteFromFile(
262+
System.IO.Path.Combine(gamePath, "minimap.jpg"));
262263
t.Find("MapCapture").GetComponent<Image>().sprite = s;
263264
t.Find("Data/Name").GetComponent<Text>().text = map.mapName;
264265
t.Find("Data/Desc").GetComponent<Text>().text =

Assets/Scripts/Managers/MinimapManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[RequireComponent(typeof(Camera))]
66
public class MinimapManager : MonoBehaviour
77
{
8+
public static bool IS_ENABLED = true;
89
private static Material _indicatorMat;
910

1011
public float lineWidth;
@@ -20,6 +21,7 @@ private void Start()
2021

2122
public void OnPostRender()
2223
{
24+
if (!IS_ENABLED) return;
2325
(Vector3 minWorldPoint, Vector3 maxWorldPoint) = Utils.GetCameraWorldBounds();
2426
Vector3 minViewportPoint = _minimapCam.WorldToViewportPoint(minWorldPoint);
2527
Vector3 maxViewportPoint = _minimapCam.WorldToViewportPoint(maxWorldPoint);

Assets/Scripts/Tools/DataHandler.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ public static void SaveGameData()
4646
// save game scene data
4747
GameData.gameUid = CoreDataHandler.instance.GameUID;
4848
GameData.Save(SerializeGameData());
49+
// save game scene current minimap
50+
Camera minimapCamera = GameObject.Find("CameraMinimap").GetComponent<Camera>();
51+
MinimapManager.IS_ENABLED = false;
52+
MinimapCapture.TakeScreenshot(
53+
"minimap",
54+
new Vector2Int(512, 512),
55+
minimapCamera,
56+
GameData.GetFolderPath());
57+
MinimapManager.IS_ENABLED = true;
4958
}
5059

5160
public static void DeserializeGameData()

Assets/Scripts/Tools/MinimapCapture.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
public static class MinimapCapture
55
{
6-
public static void TakeScreenshot(string name, Vector2Int size, Camera camera)
6+
public static void TakeScreenshot(string name, Vector2Int size, Camera camera, string folderPath = "")
77
{
88
RenderTexture prevRt = camera.targetTexture;
99

@@ -24,9 +24,12 @@ public static void TakeScreenshot(string name, Vector2Int size, Camera camera)
2424
Object.DestroyImmediate(output);
2525

2626
// write to a file in the project folder
27-
string folderPath = Application.dataPath + "/Resources/MapCaptures";
28-
if (!Directory.Exists(folderPath))
29-
Directory.CreateDirectory(folderPath);
27+
if (folderPath == "")
28+
{
29+
folderPath = Application.dataPath + "/Resources/MapCaptures";
30+
if (!Directory.Exists(folderPath))
31+
Directory.CreateDirectory(folderPath);
32+
}
3033
string filePath = $"{folderPath}/{name}.jpg";
3134
File.WriteAllBytes(filePath, bytes);
3235

Assets/Scripts/Tools/Utils.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,16 @@ public static (Vector3, Vector3) GetCameraWorldBounds()
246246

247247
return (bottomLeft, topRight);
248248
}
249+
250+
public static Sprite LoadSpriteFromFile(string filePath)
251+
{
252+
if (!System.IO.File.Exists(filePath)) return null;
253+
254+
byte[] byteArray = System.IO.File.ReadAllBytes(filePath);
255+
Texture2D tex = new Texture2D(2, 2);
256+
bool isLoaded = tex.LoadImage(byteArray); // this auto-resizes the texture
257+
if (isLoaded)
258+
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), 64f);
259+
return null;
260+
}
249261
}

0 commit comments

Comments
 (0)