mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
Implement simple save system
Implement simple save system
This commit is contained in:
1 parent
a7edeeb319
commit
3b62ced28c
36 files changed
+355
-145
No files matched your search
@@ -12,7 +12,7 @@ namespace Pal3.Actor
|
||||
using MetaData;
|
||||
using UnityEngine;
|
||||
|
||||
public class LongKuiController : MonoBehaviour,
|
||||
public sealed class LongKuiController : MonoBehaviour,
|
||||
ICommandExecutor<LongKuiSwitchModeCommand>
|
||||
{
|
||||
private Actor _actor;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Pal3.Audio
|
||||
using State;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour,
|
||||
public sealed class AudioManager : MonoBehaviour,
|
||||
ICommandExecutor<PlaySfxCommand>,
|
||||
ICommandExecutor<PlayMusicCommand>,
|
||||
ICommandExecutor<PlaySfxAtGameObjectRequest>,
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Pal3.Camera
|
||||
using UnityEngine.InputSystem.OnScreen;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CameraManager : MonoBehaviour,
|
||||
public sealed class CameraManager : MonoBehaviour,
|
||||
ICommandExecutor<CameraSetTransformCommand>,
|
||||
ICommandExecutor<CameraSetDefaultTransformCommand>,
|
||||
ICommandExecutor<CameraShakeEffectCommand>,
|
||||
@@ -78,6 +78,8 @@ namespace Pal3.Camera
|
||||
|
||||
private GameObject _lookAtGameObject;
|
||||
|
||||
private int _currentAppliedDefaultTransformOption = 0;
|
||||
|
||||
private RectTransform _joyStickRect;
|
||||
private float _joyStickMovementRange;
|
||||
private bool _isTouchEnabled;
|
||||
@@ -361,6 +363,11 @@ namespace Pal3.Camera
|
||||
waiter?.CancelWait();
|
||||
}
|
||||
|
||||
public int GetCurrentAppliedDefaultTransformOption()
|
||||
{
|
||||
return _currentAppliedDefaultTransformOption;
|
||||
}
|
||||
|
||||
public void ApplySceneSettings(ScnSceneInfo sceneInfo)
|
||||
{
|
||||
switch (sceneInfo.SceneType)
|
||||
@@ -444,6 +451,7 @@ namespace Pal3.Camera
|
||||
|
||||
_lastLookAtPoint = _gamePlayController.GetPlayerActorLastKnownPosition();
|
||||
ApplyDefaultSettings(command.Option);
|
||||
_currentAppliedDefaultTransformOption = command.Option;
|
||||
_free = true;
|
||||
}
|
||||
|
||||
@@ -689,6 +697,7 @@ namespace Pal3.Camera
|
||||
|
||||
public void Execute(ScenePreLoadingNotification notification)
|
||||
{
|
||||
_currentAppliedDefaultTransformOption = 0;
|
||||
ApplySceneSettings(notification.NewSceneInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Command
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
public static class CommandExtensions
|
||||
{
|
||||
public static string ToString(ICommand command)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
Type type = command.GetType();
|
||||
|
||||
builder.Append(type.Name[..^"Command".Length]);
|
||||
builder.Append(' ');
|
||||
|
||||
foreach (PropertyInfo propertyInfo in type.GetProperties())
|
||||
{
|
||||
builder.Append(propertyInfo.GetValue(command));
|
||||
builder.Append(' ');
|
||||
}
|
||||
|
||||
var commandStr = builder.ToString();
|
||||
if (commandStr.EndsWith(' ')) commandStr = commandStr[..^1];
|
||||
return commandStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c053d9f1ea1a49569557705e30028a3c
|
||||
timeCreated: 1664709809
|
||||
@@ -20,7 +20,7 @@ namespace Pal3.Dev
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MazeSkipper :
|
||||
public sealed class MazeSkipper :
|
||||
ICommandExecutor<ScenePostLoadingNotification>,
|
||||
ICommandExecutor<GameStateChangedNotification>
|
||||
{
|
||||
|
||||
@@ -20,9 +20,10 @@ namespace Pal3.Dev
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.DualShock;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class StorySelector : MonoBehaviour,
|
||||
public sealed class StorySelector : MonoBehaviour,
|
||||
ICommandExecutor<ToggleStorySelectorRequest>,
|
||||
ICommandExecutor<GameSwitchToMainMenuCommand>
|
||||
{
|
||||
@@ -32,6 +33,7 @@ namespace Pal3.Dev
|
||||
private ScriptManager _scriptManager;
|
||||
private GameStateManager _gameStateManager;
|
||||
private SceneManager _sceneManager;
|
||||
private SaveManager _saveManager;
|
||||
private CanvasGroup _storySelectorCanvas;
|
||||
private GameObject _storySelectorButtonPrefab;
|
||||
|
||||
@@ -40,6 +42,8 @@ namespace Pal3.Dev
|
||||
private readonly Dictionary<string, string> _storySelections = new()
|
||||
{
|
||||
{"关闭", ""},
|
||||
{"继续游戏", ""},
|
||||
{"保存当前游戏进度", ""},
|
||||
{"新的游戏", ""},
|
||||
#if PAL3
|
||||
{"永安当-去客房找赵文昌", @"
|
||||
@@ -1262,24 +1266,6 @@ namespace Pal3.Dev
|
||||
BigMapEnableRegion 8 2
|
||||
BigMapEnableRegion 9 1
|
||||
CameraFadeIn"},
|
||||
{"血濡回魂-石村", @"
|
||||
ScriptVarSetValue -32768 71700
|
||||
SceneLoad Q07 Q07y
|
||||
ActorActivate -1 1
|
||||
ActorEnablePlayerControl -1
|
||||
PlayerEnableInput 1
|
||||
ActorSetNavLayer -1 0
|
||||
ActorSetTilePosition -1 142 169
|
||||
BigMapEnableRegion 0 2
|
||||
BigMapEnableRegion 1 2
|
||||
BigMapEnableRegion 2 2
|
||||
BigMapEnableRegion 4 2
|
||||
BigMapEnableRegion 5 2
|
||||
BigMapEnableRegion 6 1
|
||||
BigMapEnableRegion 7 2
|
||||
BigMapEnableRegion 8 2
|
||||
BigMapEnableRegion 9 1
|
||||
CameraFadeIn"},
|
||||
{"血濡回魂-梦醒", @"
|
||||
ScriptVarSetValue -32768 72001
|
||||
SceneLoad m07 3
|
||||
@@ -1447,6 +1433,7 @@ namespace Pal3.Dev
|
||||
BigMapEnableRegion 9 1
|
||||
BigMapEnableRegion 10 2
|
||||
BigMapEnableRegion 11 1
|
||||
CameraSetDefaultTransform 2
|
||||
CameraFadeIn"},
|
||||
{"新安当", @"
|
||||
ScriptVarSetValue -32768 101500
|
||||
@@ -1895,6 +1882,7 @@ namespace Pal3.Dev
|
||||
SceneManager sceneManager,
|
||||
GameStateManager gameStateManager,
|
||||
ScriptManager scriptManager,
|
||||
SaveManager saveManager,
|
||||
CanvasGroup storySelectorCanvas,
|
||||
GameObject storySelectorButtonPrefab)
|
||||
{
|
||||
@@ -1904,6 +1892,7 @@ namespace Pal3.Dev
|
||||
_gameStateManager = gameStateManager;
|
||||
_playerInputActions = inputManager.GetPlayerInputActions();
|
||||
_scriptManager = scriptManager;
|
||||
_saveManager = saveManager;
|
||||
_storySelectorCanvas = storySelectorCanvas;
|
||||
_storySelectorButtonPrefab = storySelectorButtonPrefab;
|
||||
|
||||
@@ -1954,13 +1943,14 @@ namespace Pal3.Dev
|
||||
|
||||
foreach (var story in _storySelections)
|
||||
{
|
||||
if (hideCloseButton && story.Key == "关闭") continue;
|
||||
|
||||
if (hideCloseButton && story.Key is "关闭" or "保存当前游戏进度") continue;
|
||||
|
||||
GameObject selectionButton = Instantiate(_storySelectorButtonPrefab, _storySelectorCanvas.transform);
|
||||
|
||||
var buttonTextUI = selectionButton.GetComponentInChildren<TextMeshProUGUI>();
|
||||
buttonTextUI.text = story.Key;
|
||||
selectionButton.GetComponent<Button>().onClick
|
||||
.AddListener(delegate { StorySelectionButtonClicked(story.Key);});
|
||||
var button = selectionButton.GetComponent<Button>();
|
||||
button.onClick.AddListener(delegate { StorySelectionButtonClicked(story.Key);});
|
||||
_selectionButtons.Add(selectionButton);
|
||||
}
|
||||
|
||||
@@ -1995,7 +1985,8 @@ namespace Pal3.Dev
|
||||
|
||||
InputDevice lastActiveInputDevice = _inputManager.GetLastActiveInputDevice();
|
||||
if (lastActiveInputDevice == Keyboard.current ||
|
||||
lastActiveInputDevice == Gamepad.current)
|
||||
lastActiveInputDevice == Gamepad.current ||
|
||||
lastActiveInputDevice == DualShockGamepad.current)
|
||||
{
|
||||
firstButton.Select();
|
||||
}
|
||||
@@ -2016,6 +2007,32 @@ namespace Pal3.Dev
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ResetGameStateCommand());
|
||||
StartNewGame();
|
||||
break;
|
||||
case "继续游戏":
|
||||
if (!_saveManager.SaveFileExists())
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ResetGameStateCommand());
|
||||
StartNewGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
var commands = _saveManager.LoadFromSaveFile();
|
||||
if (commands == null)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ResetGameStateCommand());
|
||||
StartNewGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecuteCommands(commands);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "保存当前游戏进度":
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(_saveManager.SaveGameStateToFile()
|
||||
? new UIDisplayNoteCommand("游戏保存成功")
|
||||
: new UIDisplayNoteCommand("游戏保存失败"));
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
break;
|
||||
default:
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ResetGameStateCommand());
|
||||
ExecuteCommands(_storySelections[story]);
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Pal3.Effect
|
||||
using Scene;
|
||||
using UnityEngine;
|
||||
|
||||
public class EffectManager : MonoBehaviour,
|
||||
public sealed class EffectManager : MonoBehaviour,
|
||||
ICommandExecutor<EffectAttachToActorCommand>,
|
||||
ICommandExecutor<EffectPlayCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
|
||||
@@ -11,13 +11,15 @@ namespace Pal3.Effect
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
public class PostProcessManager : MonoBehaviour,
|
||||
public sealed class PostProcessManager : MonoBehaviour,
|
||||
ICommandExecutor<EffectSetScreenEffectCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
private PostProcessVolume _postProcessVolume;
|
||||
private PostProcessLayer _postProcessLayer;
|
||||
|
||||
private int _currentAppliedEffectMode = -1;
|
||||
|
||||
public void Init(PostProcessVolume volume,
|
||||
PostProcessLayer postProcessLayer)
|
||||
{
|
||||
@@ -35,6 +37,11 @@ namespace Pal3.Effect
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
public int GetCurrentAppliedEffectMode()
|
||||
{
|
||||
return _currentAppliedEffectMode;
|
||||
}
|
||||
|
||||
public void Execute(EffectSetScreenEffectCommand command)
|
||||
{
|
||||
switch (command.Mode)
|
||||
@@ -68,6 +75,8 @@ namespace Pal3.Effect
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_currentAppliedEffectMode = command.Mode;
|
||||
}
|
||||
|
||||
public void Execute(ResetGameStateCommand command)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Pal3.Feature
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CaptionRenderer : MonoBehaviour,
|
||||
public sealed class CaptionRenderer : MonoBehaviour,
|
||||
ICommandExecutor<UIDisplayCaptionCommand>
|
||||
{
|
||||
private const float CAPTION_ANIMATION_DURATION = 10f;
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace Pal3.Feature
|
||||
using Command.SceCommands;
|
||||
using MetaData;
|
||||
|
||||
public class FavorManager :
|
||||
public sealed class FavorManager :
|
||||
ICommandExecutor<FavorAddCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
private const int DEFAULT_FAVOR_AMOUNT = 20;
|
||||
private const int BASE_FAVOR_AMOUNT = 20;
|
||||
|
||||
private readonly Dictionary<int, int> _actorFavor = new ();
|
||||
|
||||
@@ -37,14 +37,19 @@ namespace Pal3.Feature
|
||||
foreach (var actorId in Enum.GetValues(typeof(PlayerActorId)).Cast<int>())
|
||||
{
|
||||
if (actorId == 0) continue; // Skip for the main actor
|
||||
_actorFavor[actorId] = DEFAULT_FAVOR_AMOUNT;
|
||||
_actorFavor[actorId] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, int> GetAllActorFavorInfo()
|
||||
{
|
||||
return _actorFavor;
|
||||
}
|
||||
|
||||
public int GetFavorByActor(int actorId)
|
||||
{
|
||||
return _actorFavor.ContainsKey(actorId) ?
|
||||
_actorFavor[actorId] : DEFAULT_FAVOR_AMOUNT;
|
||||
_actorFavor[actorId] + BASE_FAVOR_AMOUNT : BASE_FAVOR_AMOUNT;
|
||||
}
|
||||
|
||||
public void Execute(FavorAddCommand command)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Pal3.Feature
|
||||
using Script;
|
||||
using UnityEngine;
|
||||
|
||||
public class HotelManager : MonoBehaviour,
|
||||
public sealed class HotelManager : MonoBehaviour,
|
||||
ICommandExecutor<UIShowHotelMenuCommand>
|
||||
{
|
||||
private ScriptManager _scriptManager;
|
||||
@@ -58,8 +58,8 @@ namespace Pal3.Feature
|
||||
Rest("Q01", "xn01", (uint)command.AfterRestScriptId);
|
||||
}
|
||||
}
|
||||
|
||||
if (command.HotelScriptName.Equals("DealScript\\rest\\q13rest.txt"))
|
||||
else if (command.HotelScriptName.Equals("DealScript\\rest\\q13rest.txt",
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (vars[ScriptConstants.MainStoryVariableName] == 120301)
|
||||
{
|
||||
@@ -68,7 +68,8 @@ namespace Pal3.Feature
|
||||
}
|
||||
}
|
||||
#elif PAL3A
|
||||
if (command.HotelScriptName.Equals("DealScript\\rest\\q10rest.txt"))
|
||||
if (command.HotelScriptName.Equals("DealScript\\rest\\q10rest.txt",
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (vars[ScriptConstants.MainStoryVariableName] == 140300)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Pal3
|
||||
/// The Game Resource initializer
|
||||
/// Initialize file system etc.
|
||||
/// </summary>
|
||||
public class GameResourceInitializer : MonoBehaviour
|
||||
public sealed class GameResourceInitializer : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private UnityEngine.Camera uiCamera;
|
||||
[SerializeField] private GameObject startingComponent;
|
||||
@@ -168,7 +168,7 @@ namespace Pal3
|
||||
timer.Start();
|
||||
cpkFileSystem = InitializeCpkFileSystem(path, crcHash, codepage);
|
||||
timer.Stop();
|
||||
Debug.Log($"All files mounted successfully. Total time: {timer.Elapsed.TotalSeconds:0.000}s");
|
||||
Debug.Log($"All cpk files mounted successfully under {path}. Total time: {timer.Elapsed.TotalSeconds:0.000}s");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Pal3.Input
|
||||
using State;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class InputManager
|
||||
public sealed class InputManager
|
||||
{
|
||||
private readonly PlayerInputActions _playerInputActions;
|
||||
private InputDevice _lastActiveInputDevice;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Pal3.MiniGame
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
|
||||
public class AppraisalsMiniGame : ICommandExecutor<MiniGameStartAppraisalsCommand>
|
||||
public sealed class AppraisalsMiniGame : ICommandExecutor<MiniGameStartAppraisalsCommand>
|
||||
{
|
||||
public AppraisalsMiniGame()
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Pal3.MiniGame
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
|
||||
public class CaveExperienceMiniGame : ICommandExecutor<MiniGameStartCaveExperienceCommand>
|
||||
public sealed class CaveExperienceMiniGame : ICommandExecutor<MiniGameStartCaveExperienceCommand>
|
||||
{
|
||||
public CaveExperienceMiniGame()
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Pal3.MiniGame
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
|
||||
public class EncampMiniGame : ICommandExecutor<MiniGameStartEncampCommand>
|
||||
public sealed class EncampMiniGame : ICommandExecutor<MiniGameStartEncampCommand>
|
||||
{
|
||||
public EncampMiniGame()
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Pal3.MiniGame
|
||||
using MetaData;
|
||||
using Script;
|
||||
|
||||
public class HideFightMiniGame : ICommandExecutor<MiniGameStartHideFightCommand>
|
||||
public sealed class HideFightMiniGame : ICommandExecutor<MiniGameStartHideFightCommand>
|
||||
{
|
||||
public HideFightMiniGame()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Pal3.MiniGame
|
||||
using Command.SceCommands;
|
||||
using MetaData;
|
||||
|
||||
public class SailingMiniGame : ICommandExecutor<MiniGameStartSailingCommand>
|
||||
public sealed class SailingMiniGame : ICommandExecutor<MiniGameStartSailingCommand>
|
||||
{
|
||||
public SailingMiniGame()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Pal3.MiniGame
|
||||
using Command.SceCommands;
|
||||
using Script;
|
||||
|
||||
public class SkiMiniGame : ICommandExecutor<MiniGameStartSkiCommand>
|
||||
public sealed class SkiMiniGame : ICommandExecutor<MiniGameStartSkiCommand>
|
||||
{
|
||||
private readonly ScriptManager _scriptManager;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Pal3.MiniGame
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
|
||||
public class SwatAFlyMiniGame : ICommandExecutor<MiniGameStartSwatAFlyCommand>
|
||||
public sealed class SwatAFlyMiniGame : ICommandExecutor<MiniGameStartSwatAFlyCommand>
|
||||
{
|
||||
public SwatAFlyMiniGame()
|
||||
{
|
||||
|
||||
+44
-83
@@ -48,7 +48,7 @@ namespace Pal3
|
||||
/// <summary>
|
||||
/// Pal3 game model
|
||||
/// </summary>
|
||||
public class Pal3 : Singleton<Pal3>
|
||||
public sealed class Pal3 : Singleton<Pal3>
|
||||
{
|
||||
// Camera
|
||||
[SerializeField] private UnityEngine.Camera mainCamera;
|
||||
@@ -137,7 +137,8 @@ namespace Pal3
|
||||
private FavorManager _favorManager;
|
||||
private CaptionRenderer _captionRenderer;
|
||||
private CursorManager _cursorManager;
|
||||
|
||||
private SaveManager _saveManager;
|
||||
|
||||
// Mini games
|
||||
#if PAL3
|
||||
private AppraisalsMiniGame _appraisalsMiniGame;
|
||||
@@ -199,24 +200,6 @@ namespace Pal3
|
||||
_caveExperienceMiniGame = new CaveExperienceMiniGame();
|
||||
ServiceLocator.Instance.Register(_caveExperienceMiniGame);
|
||||
#endif
|
||||
|
||||
_mazeSkipper = new MazeSkipper(_gameStateManager,
|
||||
_sceneManager,
|
||||
mazeSkipperCanvasGroup,
|
||||
mazeEntranceButton,
|
||||
mazeExitButton);
|
||||
ServiceLocator.Instance.Register(_mazeSkipper);
|
||||
|
||||
_storySelector = gameObject.AddComponent<StorySelector>();
|
||||
_storySelector.Init(
|
||||
_inputManager,
|
||||
eventSystem,
|
||||
_sceneManager,
|
||||
_gameStateManager,
|
||||
_scriptManager,
|
||||
storySelectionCanvasGroup,
|
||||
storySelectionButtonPrefab);
|
||||
ServiceLocator.Instance.Register(_storySelector);
|
||||
|
||||
_videoManager = gameObject.AddComponent<VideoManager>();
|
||||
_videoManager.Init(_gameResourceProvider,_inputActions, videoPlayerCanvas, videoPlayer);
|
||||
@@ -299,12 +282,41 @@ namespace Pal3
|
||||
_effectManager = gameObject.AddComponent<EffectManager>();
|
||||
_effectManager.Init(_sceneManager);
|
||||
ServiceLocator.Instance.Register(_effectManager);
|
||||
|
||||
_saveManager = new SaveManager(_sceneManager,
|
||||
_playerManager,
|
||||
_teamManager,
|
||||
_bigMapManager,
|
||||
_scriptManager,
|
||||
_favorManager,
|
||||
_cameraManager,
|
||||
_postProcessManager);
|
||||
ServiceLocator.Instance.Register(_saveManager);
|
||||
|
||||
_mazeSkipper = new MazeSkipper(_gameStateManager,
|
||||
_sceneManager,
|
||||
mazeSkipperCanvasGroup,
|
||||
mazeEntranceButton,
|
||||
mazeExitButton);
|
||||
ServiceLocator.Instance.Register(_mazeSkipper);
|
||||
|
||||
_storySelector = gameObject.AddComponent<StorySelector>();
|
||||
_storySelector.Init(
|
||||
_inputManager,
|
||||
eventSystem,
|
||||
_sceneManager,
|
||||
_gameStateManager,
|
||||
_scriptManager,
|
||||
_saveManager,
|
||||
storySelectionCanvasGroup,
|
||||
storySelectionButtonPrefab);
|
||||
ServiceLocator.Instance.Register(_storySelector);
|
||||
|
||||
DebugLogManager.Instance.OnLogWindowShown += OnDebugWindowShown;
|
||||
DebugLogManager.Instance.OnLogWindowHidden += OnDebugWindowHidden;
|
||||
|
||||
DebugLogConsole.AddCommand("vars", "List current global variables.", ListCurrentGlobalVariables);
|
||||
DebugLogConsole.AddCommand("save", "Save game state into executable commands.", ConvertCurrentGameStateToCommands);
|
||||
DebugLogConsole.AddCommand("save", "Save game state into executable commands.", ConvertCurrentGameStateToCommandStr);
|
||||
DebugLogConsole.AddCommand("info", "Get current game info.", GetCurrentGameInfo);
|
||||
|
||||
_settingsManager = new SettingsManager();
|
||||
@@ -326,7 +338,8 @@ namespace Pal3
|
||||
_sceneManager.Dispose();
|
||||
_touchControlUIManager.Dispose();
|
||||
_favorManager.Dispose();
|
||||
|
||||
_mazeSkipper.Dispose();
|
||||
|
||||
#if PAL3
|
||||
_appraisalsMiniGame.Dispose();
|
||||
_sailingMiniGame.Dispose();
|
||||
@@ -337,12 +350,9 @@ namespace Pal3
|
||||
_caveExperienceMiniGame.Dispose();
|
||||
#endif
|
||||
|
||||
_mazeSkipper.Dispose();
|
||||
|
||||
Destroy(_videoManager);
|
||||
Destroy(_playerGamePlayController);
|
||||
Destroy(_cameraManager);
|
||||
Destroy(_cameraManager);
|
||||
Destroy(_audioManager);
|
||||
Destroy(_informationManager);
|
||||
Destroy(_dialogueManager);
|
||||
@@ -351,6 +361,12 @@ namespace Pal3
|
||||
Destroy(_storySelector);
|
||||
Destroy(_captionRenderer);
|
||||
Destroy(_postProcessManager);
|
||||
Destroy(_effectManager);
|
||||
|
||||
if (_cursorManager != null)
|
||||
{
|
||||
Destroy(_cursorManager);
|
||||
}
|
||||
|
||||
DebugLogManager.Instance.OnLogWindowShown -= OnDebugWindowShown;
|
||||
DebugLogManager.Instance.OnLogWindowHidden -= OnDebugWindowHidden;
|
||||
@@ -375,46 +391,10 @@ namespace Pal3
|
||||
}
|
||||
}
|
||||
|
||||
private string ConvertCurrentGameStateToCommands()
|
||||
private string ConvertCurrentGameStateToCommandStr()
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene() is not { } currentScene) return null;
|
||||
|
||||
var playerActorMovementController = currentScene
|
||||
.GetActorGameObject((byte) _playerManager.GetPlayerActor()).GetComponent<ActorMovementController>();
|
||||
Vector2Int playerActorTilePosition = playerActorMovementController.GetTilePosition();
|
||||
var varsToSave = _scriptManager.GetGlobalVariables()
|
||||
.Where(_ => _.Key == ScriptConstants.MainStoryVariableName); // Save main story var only
|
||||
ScnSceneInfo currentSceneInfo = currentScene.GetSceneInfo();
|
||||
|
||||
var commands = new List<ICommand>
|
||||
{
|
||||
new ResetGameStateCommand(),
|
||||
};
|
||||
|
||||
commands.AddRange(varsToSave.Select(var =>
|
||||
new ScriptVarSetValueCommand(var.Key, var.Value)));
|
||||
|
||||
commands.AddRange(new List<ICommand>()
|
||||
{
|
||||
new SceneLoadCommand(currentSceneInfo.CityName, currentSceneInfo.Name),
|
||||
new ActorActivateCommand(ActorConstants.PlayerActorVirtualID, 1),
|
||||
new ActorEnablePlayerControlCommand(ActorConstants.PlayerActorVirtualID),
|
||||
new PlayerEnableInputCommand(1),
|
||||
new ActorSetNavLayerCommand(ActorConstants.PlayerActorVirtualID,
|
||||
playerActorMovementController.GetCurrentLayerIndex()),
|
||||
new ActorSetTilePositionCommand(ActorConstants.PlayerActorVirtualID,
|
||||
playerActorTilePosition.x, playerActorTilePosition.y)
|
||||
});
|
||||
|
||||
commands.AddRange(_teamManager.GetActorsInTeam()
|
||||
.Select(actorId => new TeamAddOrRemoveActorCommand((int) actorId, 1)));
|
||||
// commands.AddRange(_favorManager.GetAllActorFavorInfo()
|
||||
// .Select(favorInfo => new FavorAddCommand(favorInfo.Key, favorInfo.Value)));
|
||||
commands.AddRange(_bigMapManager.GetRegionEnablementInfo()
|
||||
.Select(regionEnablement => new BigMapEnableRegionCommand(regionEnablement.Key, regionEnablement.Value)));
|
||||
commands.Add(new CameraFadeInCommand());
|
||||
|
||||
return string.Join('\n', commands.Select(ToString).ToList());
|
||||
var commands = _saveManager.ConvertCurrentGameStateToCommands(SaveLevel.Minimal);
|
||||
return commands == null ? null : string.Join('\n', commands.Select(CommandExtensions.ToString).ToList());
|
||||
}
|
||||
|
||||
private string GetCurrentGameInfo()
|
||||
@@ -436,25 +416,6 @@ namespace Pal3
|
||||
return info.ToString();
|
||||
}
|
||||
|
||||
private static string ToString(ICommand command)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
Type type = command.GetType();
|
||||
|
||||
builder.Append(type.Name[..^"Command".Length]);
|
||||
builder.Append(' ');
|
||||
|
||||
foreach (PropertyInfo propertyInfo in type.GetProperties())
|
||||
{
|
||||
builder.Append(propertyInfo.GetValue(command));
|
||||
builder.Append(' ');
|
||||
}
|
||||
|
||||
var commandStr = builder.ToString();
|
||||
if (commandStr.EndsWith(' ')) commandStr = commandStr[..^1];
|
||||
return commandStr;
|
||||
}
|
||||
|
||||
private string ListCurrentGlobalVariables()
|
||||
{
|
||||
if (_scriptManager.GetGlobalVariables() is not { Count: > 0 }) return null;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Pal3.Player
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerGamePlayController : MonoBehaviour,
|
||||
public sealed class PlayerGamePlayController : MonoBehaviour,
|
||||
ICommandExecutor<ActorEnablePlayerControlCommand>,
|
||||
ICommandExecutor<ActorSetTilePositionCommand>,
|
||||
ICommandExecutor<PlayerEnableInputCommand>,
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Pal3.Player
|
||||
using Command.SceCommands;
|
||||
using MetaData;
|
||||
|
||||
public class PlayerManager :
|
||||
public sealed class PlayerManager :
|
||||
ICommandExecutor<DialogueRenderActorAvatarCommand>,
|
||||
ICommandExecutor<ActorActivateCommand>,
|
||||
ICommandExecutor<ActorAddSkillCommand>,
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Pal3.Player
|
||||
using Scene;
|
||||
using UnityEngine;
|
||||
|
||||
public class TeamManager :
|
||||
public sealed class TeamManager :
|
||||
ICommandExecutor<TeamOpenCommand>,
|
||||
ICommandExecutor<TeamCloseCommand>,
|
||||
ICommandExecutor<TeamAddOrRemoveActorCommand>,
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Pal3.Scene
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
public class SceneManager :
|
||||
public sealed class SceneManager :
|
||||
ICommandExecutor<SceneLoadCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Pal3.Script
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
public class ScriptManager :
|
||||
public sealed class ScriptManager :
|
||||
ICommandExecutor<ScriptRunCommand>,
|
||||
ICommandExecutor<ScriptVarSetValueCommand>,
|
||||
ICommandExecutor<ScriptVarAddValueCommand>,
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Pal3.Settings
|
||||
using Core.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
public class SettingsManager
|
||||
public sealed class SettingsManager
|
||||
{
|
||||
public void ApplyPlatformSpecificSettings()
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Pal3.State
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameStateManager :
|
||||
public sealed class GameStateManager :
|
||||
ICommandExecutor<PlayVideoCommand>,
|
||||
ICommandExecutor<VideoEndedNotification>,
|
||||
ICommandExecutor<PlayerEnableInputCommand>,
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.State
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Actor;
|
||||
using Camera;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.DataReader.Scn;
|
||||
using Effect;
|
||||
using Feature;
|
||||
using MetaData;
|
||||
using Player;
|
||||
using Scene;
|
||||
using Script;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
public enum SaveLevel
|
||||
{
|
||||
Minimal = 0,
|
||||
Full
|
||||
}
|
||||
|
||||
public class SaveManager
|
||||
{
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly PlayerManager _playerManager;
|
||||
private readonly TeamManager _teamManager;
|
||||
private readonly BigMapManager _bigMapManager;
|
||||
private readonly ScriptManager _scriptManager;
|
||||
private readonly FavorManager _favorManager;
|
||||
private readonly CameraManager _cameraManager;
|
||||
private readonly PostProcessManager _postProcessManager;
|
||||
|
||||
private const string SAVE_FILE_NAME = "save.txt";
|
||||
|
||||
public SaveManager(SceneManager sceneManager,
|
||||
PlayerManager playerManager,
|
||||
TeamManager teamManager,
|
||||
BigMapManager bigMapManager,
|
||||
ScriptManager scriptManager,
|
||||
FavorManager favorManager,
|
||||
CameraManager cameraManager,
|
||||
PostProcessManager postProcessManager)
|
||||
{
|
||||
_sceneManager = sceneManager;
|
||||
_playerManager = playerManager;
|
||||
_teamManager = teamManager;
|
||||
_bigMapManager = bigMapManager;
|
||||
_scriptManager = scriptManager;
|
||||
_favorManager = favorManager;
|
||||
_cameraManager = cameraManager;
|
||||
_postProcessManager = postProcessManager;
|
||||
}
|
||||
|
||||
private string GetSaveFilePath()
|
||||
{
|
||||
return Application.persistentDataPath +
|
||||
Path.DirectorySeparatorChar + SAVE_FILE_NAME;
|
||||
}
|
||||
|
||||
public bool SaveFileExists()
|
||||
{
|
||||
return File.Exists(GetSaveFilePath());
|
||||
}
|
||||
|
||||
public bool SaveGameStateToFile()
|
||||
{
|
||||
string saveFilePath = GetSaveFilePath();
|
||||
try
|
||||
{
|
||||
var commands = ConvertCurrentGameStateToCommands(SaveLevel.Full);
|
||||
File.WriteAllText(saveFilePath, string.Join('\n', commands.Select(CommandExtensions.ToString).ToList()));
|
||||
Debug.Log($"Game state saved to: {saveFilePath}");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to save game state to file: {saveFilePath} with exception: {ex}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public string LoadFromSaveFile()
|
||||
{
|
||||
return !SaveFileExists() ? null : File.ReadAllText(GetSaveFilePath());
|
||||
}
|
||||
|
||||
public List<ICommand> ConvertCurrentGameStateToCommands(SaveLevel saveLevel)
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene() is not { } currentScene) return null;
|
||||
|
||||
var playerActorMovementController = currentScene
|
||||
.GetActorGameObject((byte) _playerManager.GetPlayerActor()).GetComponent<ActorMovementController>();
|
||||
Vector2Int playerActorTilePosition = playerActorMovementController.GetTilePosition();
|
||||
|
||||
var varsToSave = _scriptManager.GetGlobalVariables();
|
||||
if (saveLevel == SaveLevel.Minimal)
|
||||
{
|
||||
varsToSave = new Dictionary<int, int>()
|
||||
{
|
||||
{ScriptConstants.MainStoryVariableName, varsToSave[ScriptConstants.MainStoryVariableName]}
|
||||
}; // Save main story var only
|
||||
}
|
||||
|
||||
ScnSceneInfo currentSceneInfo = currentScene.GetSceneInfo();
|
||||
|
||||
var commands = new List<ICommand>
|
||||
{
|
||||
new ResetGameStateCommand(),
|
||||
};
|
||||
|
||||
commands.AddRange(varsToSave.Select(var =>
|
||||
new ScriptVarSetValueCommand(var.Key, var.Value)));
|
||||
|
||||
commands.AddRange(new List<ICommand>()
|
||||
{
|
||||
new SceneLoadCommand(currentSceneInfo.CityName, currentSceneInfo.Name),
|
||||
new ActorActivateCommand(ActorConstants.PlayerActorVirtualID, 1),
|
||||
new ActorEnablePlayerControlCommand(ActorConstants.PlayerActorVirtualID),
|
||||
new PlayerEnableInputCommand(1),
|
||||
new ActorSetNavLayerCommand(ActorConstants.PlayerActorVirtualID,
|
||||
playerActorMovementController.GetCurrentLayerIndex()),
|
||||
new ActorSetTilePositionCommand(ActorConstants.PlayerActorVirtualID,
|
||||
playerActorTilePosition.x, playerActorTilePosition.y)
|
||||
});
|
||||
|
||||
commands.AddRange(_teamManager.GetActorsInTeam()
|
||||
.Select(actorId => new TeamAddOrRemoveActorCommand((int) actorId, 1)));
|
||||
|
||||
if (saveLevel == SaveLevel.Full)
|
||||
{
|
||||
commands.AddRange(_favorManager.GetAllActorFavorInfo()
|
||||
.Select(favorInfo => new FavorAddCommand(favorInfo.Key, favorInfo.Value)));
|
||||
}
|
||||
|
||||
commands.AddRange(_bigMapManager.GetRegionEnablementInfo()
|
||||
.Select(regionEnablement => new BigMapEnableRegionCommand(regionEnablement.Key, regionEnablement.Value)));
|
||||
|
||||
var currentEffectMode = _postProcessManager.GetCurrentAppliedEffectMode();
|
||||
if (currentEffectMode != -1)
|
||||
{
|
||||
commands.Add(new EffectSetScreenEffectCommand(currentEffectMode));
|
||||
}
|
||||
|
||||
var defaultCameraTransformOption = _cameraManager.GetCurrentAppliedDefaultTransformOption();
|
||||
if (defaultCameraTransformOption != 0)
|
||||
{
|
||||
commands.Add(new CameraSetDefaultTransformCommand(defaultCameraTransformOption));
|
||||
}
|
||||
|
||||
commands.Add(new CameraFadeInCommand());
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c5da1dd6a4f4057abd64a2bcc020669
|
||||
timeCreated: 1664709051
|
||||
@@ -22,7 +22,7 @@ namespace Pal3.UI
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BigMapManager : MonoBehaviour,
|
||||
public sealed class BigMapManager : MonoBehaviour,
|
||||
ICommandExecutor<BigMapEnableRegionCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>,
|
||||
ICommandExecutor<GameSwitchRenderingStateCommand>,
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Pal3.UI
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.DualShock;
|
||||
|
||||
public class CursorManager : MonoBehaviour,
|
||||
public sealed class CursorManager : MonoBehaviour,
|
||||
ICommandExecutor<ActiveInputDeviceChangedNotification>
|
||||
{
|
||||
private Texture2D _cursorTextureNormal;
|
||||
|
||||
@@ -23,9 +23,10 @@ namespace Pal3.UI
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.DualShock;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DialogueManager : MonoBehaviour,
|
||||
public sealed class DialogueManager : MonoBehaviour,
|
||||
ICommandExecutor<DialogueRenderActorAvatarCommand>,
|
||||
ICommandExecutor<DialogueRenderTextCommand>,
|
||||
ICommandExecutor<DialogueAddSelectionsCommand>,
|
||||
@@ -488,7 +489,8 @@ namespace Pal3.UI
|
||||
|
||||
InputDevice lastActiveInputDevice = _inputManager.GetLastActiveInputDevice();
|
||||
if (lastActiveInputDevice == Keyboard.current ||
|
||||
lastActiveInputDevice == Gamepad.current)
|
||||
lastActiveInputDevice == Gamepad.current ||
|
||||
lastActiveInputDevice == DualShockGamepad.current)
|
||||
{
|
||||
firstButton.Select();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Pal3.UI
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(FpsCounter))]
|
||||
public class InformationManager : MonoBehaviour,
|
||||
public sealed class InformationManager : MonoBehaviour,
|
||||
ICommandExecutor<UIDisplayNoteCommand>,
|
||||
ICommandExecutor<UIShowDealerMenuCommand>
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Pal3.UI
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TouchControlUIManager :
|
||||
public sealed class TouchControlUIManager :
|
||||
ICommandExecutor<GameStateChangedNotification>,
|
||||
ICommandExecutor<ActiveInputDeviceChangedNotification>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user