Skip to content

Commit

Permalink
Update the app to use a plug-in style system where each monster forma…
Browse files Browse the repository at this point in the history
…t is its own assembly (#17)

* Extract and add converter specific logic to the converter classes

This is a first of several commits to pluggable converter architecture. Converter logic was remove from the MonsterFileProcessor class. Each converter must be able to identify what it supports and implement the appropriate logic.

* Update logic in MonsterFileProcessor to only use information provided from the converterclasses instead of hardcoded logic

* Work on organizing and sperating each converter into its own assembly

Move each converter into its own assembly.
Move generic Monster classes into its own assembly.
Fixed UI code to use parsed converter types instead of being hardcoded (WIP, mostly fixed compilation errors)
Working on pluginhelper class which finds available converters on the local system

* dynamically load hardcoded list of converters

* Update project to .NET5

* Remove test code from pluginhelper class

* Change plugin helper instance to async to ensure it's loaded all dlls before use

* Fix command line usage with use of new pluginhelper class

* update nuget packages

* update github actions for .net 5 workload

* update readme
  • Loading branch information
soul4soul authored May 23, 2021
1 parent 3d7b37b commit df43b90
Show file tree
Hide file tree
Showing 38 changed files with 641 additions and 371 deletions.
62 changes: 9 additions & 53 deletions .github/workflows/wpfdotnet-core.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test and package a WPF desktop application
# built on .NET Core.
# To learn how to migrate your existing WPF application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: WPF .NET Core
name: Build on Windows

on:
push:
Expand All @@ -52,30 +14,24 @@ jobs:
matrix:
configuration: [Debug, Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: windows-latest

env:
Solution_Name: OTMonsterConverter.sln # Replace with your solution name, i.e. MyWpfApp.sln.
SolutionPath: app\OTMonsterConverter.sln

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
dotnet-version: 5.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@2008f912f56e61277eefaac6d1888b750582aa16
- name: Restore dependencies
run: dotnet restore $env:SolutionPath

# Restore the WPF application to populate the obj folder with RuntimeIdentifiers
- name: Restore the WPF application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
- name: Build
run: dotnet build $env:SolutionPath --no-restore --configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}
25 changes: 0 additions & 25 deletions OTMonsterConverter.sln

This file was deleted.

16 changes: 0 additions & 16 deletions OTMonsterConverter/Converter/IMonsterConverter.cs

This file was deleted.

22 changes: 0 additions & 22 deletions OTMonsterConverter/OTMonsterConverter.csproj

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tibia OT Monster Converter is a tool for converting monster files between the va

## Technology

- .NET Core 3.1
- .NET 5
- WPF
- Visual Studio 2019

Expand Down Expand Up @@ -49,6 +49,6 @@ Options:
Improvements and bug fixes are welcome, via pull requests
For questions, suggestions and bug reports, submit an issue.

Another to contribute to this project is by contributing to [TibiaWiki](https://tibia.fandom.com) to improve creature information.
Another way to contribute to this project is by contributing to [TibiaWiki](https://tibia.fandom.com) to improve creature information.

![image](https://vignette.wikia.nocookie.net/tibia/images/d/d9/Tibiawiki_Small.gif/revision/latest?cb=20150129101832&path-prefix=en)
32 changes: 32 additions & 0 deletions app/MonsterConverterInterface/IMonsterConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using MonsterConverterInterface.MonsterTypes;
using System;

namespace MonsterConverterInterface
{
public enum FileSource
{
LocalFiles,
Web
}

// name, isreadsupported, and iswritesupported can all be metadataattributes should that be valuable localfile source too
// none of those fields deal with function they all are for information only
public interface IMonsterConverter
{
string ConverterName { get; }

string FileExt { get; }

FileSource FileSource { get; }

bool IsReadSupported { get; }

bool IsWriteSupported { get; }

string[] GetFilesForConversion(string directory);

bool ReadMonster(string filename, out Monster monster);

bool WriteMonster(string directory, ref Monster monster);
}
}
31 changes: 31 additions & 0 deletions app/MonsterConverterInterface/MonsterConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using MonsterConverterInterface.MonsterTypes;

namespace MonsterConverterInterface
{
public abstract class MonsterConverter : IMonsterConverter
{
public abstract string ConverterName { get; }

public abstract string FileExt { get; }

public virtual FileSource FileSource { get => FileSource.LocalFiles; }

public abstract bool IsReadSupported { get; }

public abstract bool IsWriteSupported { get; }

public virtual string[] GetFilesForConversion(string directory)
{
string searchPattern = "*." + FileExt;
return Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories);
}

public abstract bool ReadMonster(string filename, out Monster monster);

public abstract bool WriteMonster(string directory, ref Monster monster);
}
}
11 changes: 11 additions & 0 deletions app/MonsterConverterInterface/MonsterConverterInterface.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.9.20" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
//todo should we add outfit ID to this class?
public class DetailedLookType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public enum Condition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public class Loot
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public class Monster
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public class Spell
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public enum SpellCategory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public class Summon
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace OTMonsterConverter.MonsterTypes
namespace MonsterConverterInterface.MonsterTypes
{
public class Voice
{
Expand Down
25 changes: 25 additions & 0 deletions app/MonsterConverterPyOt/MonsterConverterPyOt.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\bin\$(Configuration)</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\bin\$(Configuration)</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.9.20" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MonsterConverterInterface\MonsterConverterInterface.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
using OTMonsterConverter.MonsterTypes;
using MonsterConverterInterface;
using MonsterConverterInterface.MonsterTypes;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Globalization;
using System.IO;
using System.Text;

namespace OTMonsterConverter.Converter
namespace MonsterConverterPyOt.Converter
{
// https://bitbucket.org/vapus/pyot/src/0aa7c38f46814f502f375b84ac905e7f5ebef1a3/game/monster.py?at=default
public class PyOtConverter : IMonsterConverter
[Export(typeof(IMonsterConverter))]
public class PyOtConverter : MonsterConverter
{
public string FileExtRegEx { get => "*.py"; }
public override string ConverterName { get => "pyOT"; }

public override string FileExt { get => "py"; }

public override bool IsReadSupported { get => false; }

public override bool IsWriteSupported { get => true; }

// Functions
public bool ReadMonster(string filename, out Monster monster)
public override bool ReadMonster(string filename, out Monster monster)
{
monster = new Monster();
return false; // Not Implemented
}

public bool WriteMonster(string directory, ref Monster monster)
public override bool WriteMonster(string directory, ref Monster monster)
{
string lowerName = monster.Name.ToLower(); // TODO Remove special chars spaces etc.. want a-z_ for characters... Can we just use a fixed variable name such as "monster"?

Expand All @@ -42,7 +51,7 @@ public bool WriteMonster(string directory, ref Monster monster)
GenericToPyOTVoice(lowerName, ref monster),
GenericToPyOTLoot(lowerName, ref monster)
};
string fileName = Path.Combine(directory, monster.FileName + ".py");
string fileName = Path.Combine(directory, monster.FileName + "." + FileExt);
File.WriteAllLines(fileName, lines);

return true;
Expand Down
Loading

0 comments on commit df43b90

Please sign in to comment.