Bugfix not using binary directory path for assets

This commit is contained in:
Alessandro Proto 2023-07-24 14:16:41 +02:00
parent b85adb960b
commit 2b8eb54a8b
3 changed files with 33 additions and 24 deletions

View file

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using static Capy64.Utils;
@ -56,21 +57,24 @@ public class Capy64 : Game
public const int FreeTickrate = 60;
}
public static readonly string AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static readonly string AssetsPath = Path.Combine(AssemblyPath, "Assets");
public static string AppDataPath {
get {
public static string AppDataPath
{
get
{
string baseDir =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
?
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create)
: RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolderOption.Create)
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolderOption.Create)
:
"./";
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData,
Environment.SpecialFolderOption.Create) :
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolderOption.Create) :
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ?
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolderOption.Create) :
"./";
return Path.Combine(baseDir, "Capy64");
}
@ -94,7 +98,8 @@ public class Capy64 : Game
public Color BorderColor { get; set; } = Color.Black;
public Borders Borders = new() {
public Borders Borders = new()
{
Top = 0,
Bottom = 0,
Left = 0,
@ -181,7 +186,8 @@ public class Capy64 : Game
private void OnWindowSizeChange(object sender, EventArgs e)
{
if (EngineMode == EngineMode.Classic) {
if (EngineMode == EngineMode.Classic)
{
UpdateSize(true);
return;
}
@ -214,7 +220,8 @@ public class Capy64 : Game
private void ResetBorder()
{
var size = (int)(Scale * DefaultParameters.BorderMultiplier);
Borders = new Borders {
Borders = new Borders
{
Top = size,
Bottom = size,
Left = size,
@ -233,10 +240,10 @@ public class Capy64 : Game
}
if (!File.Exists(settingsPath))
{
File.Copy("Assets/default.json", settingsPath);
File.Copy(Path.Combine(AssetsPath, "default.json"), settingsPath);
}
configBuilder.AddJsonFile("Assets/default.json", false);
configBuilder.AddJsonFile(Path.Combine(AssetsPath, "default.json"), false);
configBuilder.AddJsonFile(settingsPath, false);
Configuration = configBuilder.Build();
@ -297,7 +304,8 @@ public class Capy64 : Game
// Register user input
_inputManager.Update(IsActive);
EventEmitter.RaiseTick(new() {
EventEmitter.RaiseTick(new()
{
GameTime = gameTime,
TotalTicks = _totalTicks,
IsActiveTick = (int)_totalTicks % everyTick == 0,
@ -322,7 +330,8 @@ public class Capy64 : Game
SpriteBatch.Draw(renderTarget, new(Borders.Left, Borders.Top), null, Color.White, 0f, Vector2.Zero, Scale,
SpriteEffects.None, 0);
EventEmitter.RaiseOverlay(new() {
EventEmitter.RaiseOverlay(new()
{
GameTime = gameTime,
TotalTicks = _totalTicks,
});

View file

@ -54,7 +54,7 @@ public class Drawing : IDisposable
public Drawing()
{
_fontSystem = new FontSystem();
_fontSystem.AddFont(File.ReadAllBytes(@"Assets/font.ttf"));
_fontSystem.AddFont(File.ReadAllBytes(Path.Combine(Capy64.AssetsPath, "font.ttf")));
}
public void Begin()

View file

@ -124,7 +124,7 @@ internal class RuntimeManager : IComponent
luaState.Thread.PushCFunction(L_Exit);
luaState.Thread.SetGlobal("exit");
var status = luaState.Thread.LoadFile("Assets/Lua/bios.lua");
var status = luaState.Thread.LoadFile(Path.Combine(Capy64.AssetsPath, "Lua/bios.lua"));
if (status != LuaStatus.OK)
{
throw new LuaException(luaState.Thread.ToString(-1));
@ -164,7 +164,7 @@ internal class RuntimeManager : IComponent
private void LoadFirmware()
{
var firmwareContent = File.ReadAllText("Assets/Lua/firmware.lua");
var firmwareContent = File.ReadAllText(Path.Combine(Capy64.AssetsPath, "Lua/firmware.lua"));
var errored = luaState.Thread.DoString(firmwareContent);
if(errored)
{
@ -194,7 +194,7 @@ internal class RuntimeManager : IComponent
var installedFilePath = Path.Combine(Capy64.AppDataPath, ".installed");
if (!File.Exists(installedFilePath) || force)
{
FileSystemLib.CopyDirectory("Assets/Lua/CapyOS", FileSystemLib.DataPath, true, true);
FileSystemLib.CopyDirectory(Path.Combine(Capy64.AssetsPath, "Lua/CapyOS"), FileSystemLib.DataPath, true, true);
File.Create(installedFilePath).Dispose();
}
}