-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ragath
authored and
Ragath
committed
Jan 14, 2023
1 parent
0ea7d38
commit bde657a
Showing
19 changed files
with
384 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
|
||
name: .NET | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
tags: [ "v*" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} # checkout the correct branch name | ||
fetch-depth: 0 | ||
|
||
- name: Install GitVersion | ||
uses: gittools/actions/gitversion/setup@v0.9.7 | ||
with: | ||
versionSpec: '5.x' | ||
|
||
- name: Determine Version | ||
uses: gittools/actions/gitversion/execute@v0.9.7 | ||
with: | ||
useConfigFile: true | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 7.0.x | ||
|
||
- name: Build | ||
run: dotnet build -p:Version=$GITVERSION_NUGETVERSION | ||
|
||
- name: Test | ||
run: dotnet test --no-build --verbosity normal | ||
|
||
- name: Pack | ||
run: dotnet pack --no-build -o ./ -p:Version=$GITVERSION_NUGETVERSION | ||
|
||
- name: Push | ||
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | ||
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key $APIKey | ||
env: | ||
APIKey: ${{ secrets.NUGETKEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mode: ContinuousDeployment | ||
branches: {} | ||
ignore: | ||
sha: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Tyxel - [*Quickstart guide*](./Docs/Getting_started.md) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/ghf0md1regh88xgx/branch/master?svg=true)](https://ci.appveyor.com/project/Ragath/tyxel/branch/master) | ||
Pyxel->Tiled Converter. Observes changes in *.pyxel file and (re-)generates a Tiled-tilesheet. | ||
Pyxel->Tiled Converter. Observes changes in *.pyxel file and generates a Tiled-tilesheet. | ||
Built ontop of [PyxelParser.Net](https://github.com/Ragath/PyxelParser.Net/) Sample project included in Sample.json and Sample.pyxel. | ||
|
||
![tyxel](https://cloud.githubusercontent.com/assets/1191717/22309491/befe966c-e34b-11e6-8636-240b0d4a3001.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using SkiaSharp; | ||
|
||
namespace Tyxel; | ||
static class Extensions | ||
{ | ||
|
||
public static void Draw(this SKBitmap bitmap, Action<SKCanvas> action) | ||
{ | ||
if (!bitmap.ReadyToDraw) | ||
throw new Exception(nameof(bitmap.ReadyToDraw)); | ||
|
||
using var canvas = new SKCanvas(bitmap); | ||
action(canvas); | ||
canvas.Flush(); | ||
} | ||
|
||
|
||
public static void Save(this SKBitmap bitmap, string path) | ||
{ | ||
using var stream = File.Create(path); | ||
if (!bitmap.Encode(stream, SKEncodedImageFormat.Png, 100)) | ||
throw new Exception(nameof(bitmap.Encode)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Tyxel.Model; | ||
|
||
internal static class Migrations | ||
{ | ||
static IReadOnlyList<Action<ProjectConfig>> MigrationActions { get; } = new Action<ProjectConfig>[] | ||
{ | ||
data => data.Version = 1 | ||
}; | ||
|
||
public static int CurrentVersion => MigrationActions.Count; | ||
|
||
public static void ApplyMigrations(this ProjectConfig cfg) | ||
{ | ||
while (cfg.Version < CurrentVersion) | ||
MigrationActions[cfg.Version](cfg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
using Newtonsoft.Json; | ||
namespace Tyxel.Model; | ||
|
||
namespace Tyxel.Model | ||
public class ProjectConfig : IJsonOnDeserialized, IJsonOnDeserializing | ||
{ | ||
[JsonConverter(typeof(ProjectConfigConverter))] | ||
public class ProjectConfig | ||
{ | ||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] | ||
public int Version { get; set; } = ProjectConfigConverter.Migrations.Count; | ||
public string Pyxel { get; set; } | ||
public TilesetConfig Tileset { get; set; } | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] | ||
public int Version { get; set; } = Migrations.CurrentVersion; | ||
public string Pyxel { get; set; } = null!; | ||
public TilesetConfig Tileset { get; set; } = null!; | ||
|
||
[JsonIgnore] | ||
public string Root { get; set; } | ||
} | ||
[JsonIgnore] | ||
public string? Root { get; set; } | ||
|
||
public void OnDeserialized() => Migrations.ApplyMigrations(this); | ||
public void OnDeserializing() => Version = default; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
namespace Tyxel.Model | ||
namespace Tyxel.Model; | ||
|
||
public class TilesetConfig | ||
{ | ||
public class TilesetConfig | ||
{ | ||
public string OutputDir { get; set; } | ||
public string Name { get; set; } | ||
public ushort Spacing { get; set; } | ||
public string OutputDir { get; set; } = null!; | ||
public string Name { get; set; } = null!; | ||
public ushort Spacing { get; set; } | ||
|
||
public string ImageFile => $"{Name}.png"; | ||
public string TilesetFile => $"{Name}.json"; | ||
} | ||
public string ImageFile => $"{Name}.png"; | ||
public string TilesetFile => $"{Name}.json"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,26 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Tyxel.Model; | ||
|
||
namespace Tyxel | ||
if (!args.Any()) | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
if (!args.Any()) | ||
{ | ||
Console.WriteLine("Please use this program to open a <project>.json file."); | ||
Console.WriteLine("Drag & drop the *.json file onto the .exe is one way of doing so."); | ||
return; | ||
} | ||
|
||
var input = string.Join(" ", args); | ||
if (!File.Exists(input)) | ||
throw new FileNotFoundException(); | ||
Console.WriteLine("Please use this program to open a <project>.json file."); | ||
Console.WriteLine("Drag & drop the *.json file onto the .exe is one way of doing so."); | ||
return; | ||
} | ||
|
||
var input = string.Join(" ", args); | ||
if (!File.Exists(input)) | ||
throw new FileNotFoundException(); | ||
|
||
ProjectConfig project; | ||
if (Path.GetExtension(input).Equals(".pyxel", StringComparison.InvariantCultureIgnoreCase)) | ||
project = ProjectManager.CreateProject(input); | ||
else | ||
project = ProjectManager.LoadProject(input); | ||
|
||
ProjectConfig project; | ||
if (Path.GetExtension(input).Equals(".pyxel", StringComparison.InvariantCultureIgnoreCase)) | ||
project = ProjectManager.CreateProject(input); | ||
else | ||
project = ProjectManager.LoadProject(input); | ||
|
||
var pyxelPath = project.Pyxel; | ||
Console.WriteLine($"Observing: {pyxelPath}"); | ||
using (var watcher = new Watcher(pyxelPath, filename => PyxelProcessing.ProcessFile(project))) | ||
{ | ||
while (true) | ||
watcher.WaitForChange(); | ||
} | ||
} | ||
|
||
} | ||
var pyxelPath = project.Pyxel; | ||
Console.WriteLine($"Observing: {pyxelPath}"); | ||
using (var watcher = new Watcher(pyxelPath, filename => PyxelProcessing.ProcessFile(project))) | ||
{ | ||
while (true) | ||
watcher.WaitForChange(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
using System.IO; | ||
namespace Tyxel; | ||
|
||
namespace Tyxel | ||
static class ProjectExtensions | ||
{ | ||
static class ProjectExtensions | ||
{ | ||
public static string GetOutputDir(this Model.ProjectConfig project) | ||
=> Path.IsPathRooted(project.Tileset.OutputDir) ? project.Tileset.OutputDir : Path.Combine(project.Root, project.Tileset.OutputDir); | ||
public static string GetPyxelPath(this Model.ProjectConfig project) | ||
=> Path.IsPathRooted(project.Pyxel) ? project.Pyxel : Path.Combine(project.Root, project.Pyxel); | ||
public static string GetTilesetJsonPath(this Model.ProjectConfig project) | ||
=> Path.Combine(project.GetOutputDir(), project.Tileset.TilesetFile); | ||
public static string GetTilesetImagePath(this Model.ProjectConfig project) | ||
=> Path.Combine(project.GetOutputDir(), project.Tileset.ImageFile); | ||
} | ||
public static string GetOutputDir(this Model.ProjectConfig project) | ||
=> Path.IsPathRooted(project.Tileset.OutputDir) ? project.Tileset.OutputDir : Path.Combine(project.Root!, project.Tileset.OutputDir); | ||
public static string GetPyxelPath(this Model.ProjectConfig project) | ||
=> Path.IsPathRooted(project.Pyxel) ? project.Pyxel : Path.Combine(project.Root!, project.Pyxel); | ||
public static string GetTilesetJsonPath(this Model.ProjectConfig project) | ||
=> Path.Combine(project.GetOutputDir(), project.Tileset.TilesetFile); | ||
public static string GetTilesetImagePath(this Model.ProjectConfig project) | ||
=> Path.Combine(project.GetOutputDir(), project.Tileset.ImageFile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
using System; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using Tyxel.Model; | ||
namespace Tyxel; | ||
|
||
namespace Tyxel | ||
static class ProjectManager | ||
{ | ||
static class ProjectManager | ||
public static ProjectConfig LoadProject(string path) | ||
{ | ||
public static ProjectConfig LoadProject(string path) | ||
Console.WriteLine($"Opening project: {path}"); | ||
var project = JsonSerializer.Deserialize<ProjectConfig>(File.ReadAllText(path), new JsonSerializerOptions(JsonSerializerDefaults.Web) | ||
{ | ||
Console.WriteLine($"Opening project: {path}"); | ||
var project = JsonConvert.DeserializeObject<ProjectConfig>(File.ReadAllText(path)); | ||
project.Root = Path.GetDirectoryName(Path.GetFullPath(path)); | ||
return project; | ||
} | ||
ReadCommentHandling = JsonCommentHandling.Skip | ||
}) ?? throw new NullReferenceException(); | ||
|
||
project.Root = Path.GetDirectoryName(Path.GetFullPath(path)); | ||
|
||
return project; | ||
} | ||
|
||
public static ProjectConfig CreateProject(string pyxelPath) | ||
public static ProjectConfig CreateProject(string pyxelPath) | ||
{ | ||
var projectPath = Path.ChangeExtension(Path.GetFullPath(pyxelPath), ".json"); | ||
if (File.Exists(projectPath)) | ||
return LoadProject(projectPath); | ||
else | ||
{ | ||
var projectPath = Path.ChangeExtension(Path.GetFullPath(pyxelPath), ".json"); | ||
if (File.Exists(projectPath)) | ||
return LoadProject(projectPath); | ||
else | ||
var project = new ProjectConfig() | ||
{ | ||
var project = new ProjectConfig() | ||
Pyxel = Path.GetFileName(pyxelPath), | ||
Root = Path.GetDirectoryName(Path.GetFullPath(projectPath)), | ||
Tileset = new TilesetConfig() | ||
{ | ||
Pyxel = Path.GetFileName(pyxelPath), | ||
Root = Path.GetDirectoryName(Path.GetFullPath(projectPath)), | ||
Tileset = new TilesetConfig() | ||
{ | ||
Name = Path.GetFileNameWithoutExtension(projectPath) + "_Tileset", | ||
OutputDir = "Output", | ||
Spacing = 1 | ||
} | ||
}; | ||
Console.WriteLine($"Creating project: {projectPath}"); | ||
File.WriteAllText(projectPath, JsonConvert.SerializeObject(project, Formatting.Indented)); | ||
return project; | ||
} | ||
Name = Path.GetFileNameWithoutExtension(projectPath) + "_Tileset", | ||
OutputDir = "Output", | ||
Spacing = 1 | ||
} | ||
}; | ||
Console.WriteLine($"Creating project: {projectPath}"); | ||
File.WriteAllText(projectPath, JsonSerializer.Serialize(project, new JsonSerializerOptions { WriteIndented = true })); | ||
return project; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.