Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Cleaning up loader and file parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Feb 4, 2020
1 parent cf9d9bc commit 2aed7b5
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 108 deletions.
Binary file removed Disks/RunnerTools/BootTool/sprites.psd
Binary file not shown.
6 changes: 3 additions & 3 deletions Runners/CSharpRunner/CSharpRunner.cs
Expand Up @@ -71,7 +71,7 @@ private void LoadDefaultGame()
};

// Create a new dictionary to store the file binary data
var gameFiles = new Dictionary<string, string>();
var gameFiles = new List<string>();

// Get only the files we need from the directory base on their extension above.
var files = from p in Directory.EnumerateFiles(gamePath)
Expand All @@ -82,7 +82,7 @@ where fileExtensions.Any(val => p.EndsWith(val))
foreach (string file in files)
{
// Read the binary data and save it along with the file name to the dictionary.
gameFiles.Add(Path.GetFileName(file), file);
gameFiles.Add(file);
}

// Configure a new PV8 engine to play the game
Expand All @@ -91,7 +91,7 @@ where fileExtensions.Any(val => p.EndsWith(val))
tmpEngine.ActivateChip("GameChip", new EmptyTemplateDemoChip());

// Process the files
ProcessFiles(tmpEngine, gameFiles);
ProcessFiles(tmpEngine, gameFiles.ToArray(), false, Path.DirectorySeparatorChar);

}

Expand Down
14 changes: 9 additions & 5 deletions Runners/GameRunner/GameRunner.Desktop.csproj
Expand Up @@ -70,15 +70,15 @@
<Content Include="Icon.icns" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\bios.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\bios.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!-- Shader Effects -->
<Content Include="..\..\Effects\*.*">
<Link>Content\Effects\%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<!-- Core Runner Tools -->
<!-- Core Runner Tools -->
<Content Include="..\..\Disks\RunnerTools\BootTool\*.*">
<Link>Content\BootTool\%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -104,9 +104,13 @@
<Project>{6d75e618-19ca-4c51-9546-f10965fbc0b8}</Project>
<Name>MonoVision.OpenGL</Name>
</ProjectReference>
<ProjectReference Include="..\PixelVision8\PixelVision8Runner.Desktop.csproj">
<Project>{CC887541-6129-484B-8122-009F54E21AD1}</Project>
<Name>PixelVision8Runner.Desktop</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\SDK\PixelVision8.SDK.projitems" Label="Shared" />
<Import Project="..\..\SDK\PixelVision8.Lua.projitems" Label="Shared" />
<Import Project="..\..\SDK\PixelVision8.Workspace.projitems" Label="Shared" />
</Project>
</Project>
2 changes: 1 addition & 1 deletion Runners/PixelVision8/Program.cs
Expand Up @@ -21,7 +21,6 @@
using System;
using System.Globalization;
using System.IO;
using PixelVision8.Runner;

namespace Desktop
{
Expand Down Expand Up @@ -50,6 +49,7 @@ private static void Main(string[] args)
{
game.Run();
}

}
}
}
2 changes: 1 addition & 1 deletion Runners/PixelVision8/Runner/Editors/GameEditor.cs
Expand Up @@ -1116,7 +1116,7 @@ public bool LoadImage(string path)
loadService.targetEngine = targetGame;

loadService.AddParser(new ColorParser(pngReader, targetGame.ColorChip));
loadService.AddParser(new TilemapParser(pngReader, null, targetGame));
loadService.AddParser(new TilemapParser(pngReader, targetGame));

loadService.LoadAll();

Expand Down
12 changes: 6 additions & 6 deletions SDK/Runner/GameRunner.cs
Expand Up @@ -328,14 +328,14 @@ public virtual void DisplayWarning(string message)
/// <param name="tmpEngine"></param>
/// <param name="files"></param>
/// <param name="displayProgress"></param>
public virtual void ProcessFiles(IEngine tmpEngine, Dictionary<string, string> files,
bool displayProgress = false)
public virtual void ProcessFiles(IEngine tmpEngine, string[] files,
bool displayProgress = false, char directorySeparatorChar = '/')
{
this.displayProgress = displayProgress;

this.tmpEngine = tmpEngine;

ParseFiles(files);
ParseFiles(files, null, directorySeparatorChar);

if (!displayProgress)
{
Expand Down Expand Up @@ -428,7 +428,7 @@ protected override void Draw(GameTime gameTime)
}
}

public void ParseFiles(Dictionary<string, string> files, IEngine engine, SaveFlags saveFlags,
public void ParseFiles(string[] files, IEngine engine, SaveFlags saveFlags,
bool autoLoad = true)
{
loadService.ParseFiles(files, engine, saveFlags);
Expand Down Expand Up @@ -544,7 +544,7 @@ public void ResetResolution()
activeEngine.ControllerChip.MouseScale(scale.X, scale.Y);
}

protected void ParseFiles(Dictionary<string, string> files, SaveFlags? flags = null)
protected void ParseFiles(string[] files, SaveFlags? flags = null, char directorySeparatorChar = '/')
{
if (!flags.HasValue)
{
Expand All @@ -560,7 +560,7 @@ protected void ParseFiles(Dictionary<string, string> files, SaveFlags? flags = n
flags |= SaveFlags.MetaSprites;
}

loadService.ParseFiles(files, tmpEngine, flags.Value);
loadService.ParseFiles(files, tmpEngine, flags.Value, directorySeparatorChar);
}

public virtual void RunGame()
Expand Down
2 changes: 1 addition & 1 deletion SDK/Runner/IRunner.cs
Expand Up @@ -26,7 +26,7 @@ namespace PixelVision8.Runner
public interface IRunner
{
IEngine activeEngine { get; }
void ProcessFiles(IEngine tmpEngine, Dictionary<string, string> files, bool displayProgress = false);
void ProcessFiles(IEngine tmpEngine, string[] files, bool displayProgress = false, char directorySeparatorChar = '/');
void DisplayWarning(string message);
int Volume(int? value = null);
bool Mute(bool? value = null);
Expand Down
8 changes: 4 additions & 4 deletions SDK/Runner/LuaRunner.cs
Expand Up @@ -81,8 +81,8 @@ private void LoadDefaultGame()
"json"
};

// Create a new dictionary to store the file binary data
var gameFiles = new Dictionary<string, string>();
// Create a new list to store the file paths
var gameFiles = new List<string>();

// Get only the files we need from the directory base on their extension above.
var files = from p in Directory.EnumerateFiles(gamePath)
Expand All @@ -92,7 +92,7 @@ where fileExtensions.Any(val => p.EndsWith(val))
// Loop through each file in the list
foreach (var file in files)
// Read the binary data and save it along with the file name to the dictionary.
gameFiles.Add(Path.GetFileName(file), file);
gameFiles.Add(file);

// Configure a new PV8 engine to play the game
ConfigureEngine();
Expand All @@ -101,7 +101,7 @@ where fileExtensions.Any(val => p.EndsWith(val))
tmpEngine.ActivateChip("GameChip", new LuaGameChip { DefaultScriptPath = "Content/code.lua" });

// Process the files
ProcessFiles(tmpEngine, gameFiles);
ProcessFiles(tmpEngine, gameFiles.ToArray(), false, Path.DirectorySeparatorChar);

controllerChip = activeEngine.ControllerChip;
}
Expand Down
10 changes: 2 additions & 8 deletions SDK/Runner/Parsers/TilemapParser.cs
Expand Up @@ -28,13 +28,8 @@ public class TilemapParser : SpriteParser
private readonly bool autoImport;

private readonly TilemapChip tilemapChip;
// private ITexture2D tileFlagTex;
// private IColor clear;
//
// private int flag;
// private int offset;

public TilemapParser(IImageParser imageParser, byte[] tileFlagData, IEngineChips chips) :
public TilemapParser(IImageParser imageParser, IEngineChips chips) :
base(imageParser, chips)
{
tilemapChip = chips.TilemapChip;
Expand Down Expand Up @@ -74,8 +69,7 @@ protected override void ProcessSpriteData()
var tile = tilemapChip.GetTile(x, y);

tile.spriteID = id;
// tile.flag = flag;
// tile.colorOffset = offset;

}
}
}

0 comments on commit 2aed7b5

Please sign in to comment.