First commit on my server, yey!

This commit is contained in:
Sebastian Bularca
2026-03-19 18:12:07 +01:00
parent 5139ec2cec
commit fedd1961a0
602 changed files with 101587 additions and 6 deletions

View File

@@ -0,0 +1,79 @@
using Jovian.SaveSystem;
using Nox.Core;
using System;
using System.Linq;
using UnityEngine;
using PlayMode = Nox.Core.PlayMode;
namespace Nox.Game {
public class NoxSaveData {
public static NoxSavedDataSet RestoreSavedData(
ISaveSystem saveSystem,
GameDataState gameDataState,
ref AdventureData adventureData) {
var sessions = saveSystem.GetAllSessions().OrderByDescending(s => s.lastSaveDateUtc).ToList();
if(sessions.Count == 0) {
return null;
}
var latestSession = sessions[0];
var slots = saveSystem.GetSlots(latestSession.sessionId).OrderByDescending(s => s.timestampUtc).ToList();
if(slots.Count == 0) {
return null;
}
var latestSlot = slots[0];
var saveData = saveSystem.Load<NoxSavedDataSet>(latestSlot);
Debug.Log($"Loaded save {latestSlot.DisplayLabel}");
if(saveData == null) {
Debug.LogError("Failed to load save data");
return null;
}
gameDataState.activeSessionId = latestSession.sessionId;
gameDataState.savedPartyPosition = saveData.partyPosition.ToVector3();
gameDataState.ActiveParty = saveData.partyData;
adventureData = saveData.adventureData;
return saveData;
}
}
/// <summary>
/// The game's save data snapshot. Contains all state needed to restore a game session.
/// This is the TData passed to the save system package.
/// </summary>
[Serializable]
public sealed class NoxSavedDataSet {
// game state
public PlayMode activePlayMode;
//game mode specific data
public AdventureData adventureData;
// Party
public PartyData partyData;
public SerializableVector3 partyPosition;
}
/// <summary>
/// JSON-friendly Vector3 representation for save data.
/// </summary>
[Serializable]
public struct SerializableVector3 {
public float x;
public float y;
public float z;
public static SerializableVector3 Zero => new SerializableVector3 { x = 0, y = 0, z = 0 };
public static SerializableVector3 FromVector3(Vector3 value) {
return new SerializableVector3 { x = value.x, y = value.y, z = value.z };
}
public Vector3 ToVector3() {
return new Vector3(x, y, z);
}
}
}