Skip to content

Commit

Permalink
net7
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragath authored and Ragath committed Jan 14, 2023
1 parent 0ea7d38 commit bde657a
Show file tree
Hide file tree
Showing 19 changed files with 384 additions and 326 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/dotnet.yml
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 }}
4 changes: 4 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mode: ContinuousDeployment
branches: {}
ignore:
sha: []
2 changes: 1 addition & 1 deletion LICENSE.txt → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Daniel Sör
Copyright (c) 2023 Daniel Sör

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
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)
24 changes: 24 additions & 0 deletions Tyxel/Extensions.cs
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));
}
}
17 changes: 17 additions & 0 deletions Tyxel/Model/Migrations.cs
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);
}
}
23 changes: 11 additions & 12 deletions Tyxel/Model/ProjectConfig.cs
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;
}
14 changes: 0 additions & 14 deletions Tyxel/Model/ProjectConfigConverter.Migrations.cs

This file was deleted.

28 changes: 0 additions & 28 deletions Tyxel/Model/ProjectConfigConverter.cs

This file was deleted.

17 changes: 8 additions & 9 deletions Tyxel/Model/TilesetConfig.cs
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";
}
53 changes: 19 additions & 34 deletions Tyxel/Program.cs
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();
}
23 changes: 10 additions & 13 deletions Tyxel/ProjectExtensions.cs
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);
}
63 changes: 31 additions & 32 deletions Tyxel/ProjectManager.cs
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;
}

}

}

0 comments on commit bde657a

Please sign in to comment.