Permalink
Browse files

Page generation with images working

  • Loading branch information...
bsinky committed Jun 8, 2017
1 parent 5fc027f commit 88b53d0eff75e9c6c9a3ac61489a4b81f9c989bd
@@ -21,8 +21,6 @@ public HtmlGenerator(string pageTitle, IPokemonSaveInfo saveInfo)
public string Title => _title;
public IEnumerable<IPokemonInfo> PartyPokemon => throw new NotImplementedException();
public void Write(string outputDirectory, IPokemonSaveInfo saveInfo)
{
AppDomain domain = null;
@@ -84,9 +82,12 @@ public IEnumerable<string> CopyCSS(string outputDirectory)
return CSSFilesToCopy.Values;
}
private void CopyImages(string outputDirectory)
private void CopyImages(string outputDirectory, IPokemonSaveInfo saveInfo)
{
throw new NotImplementedException();
foreach (var pokemon in saveInfo.PartyMembers)
{
}
}
}
}
@@ -8,6 +8,7 @@ public interface IPokemonInfo
string Pokeball { get; }
string Ability { get; }
string Nickname { get; }
string ImagePath { get; }
int CurrentLevel { get; }
@@ -1,5 +1,6 @@
using pk_site.Html;
using System.Collections.Generic;
using System.Drawing;
namespace pk_site.Pokemon
{
@@ -11,7 +12,8 @@ public interface IPokemonSaveInfo
string GetSpecies(int species);
string GetAbility(int ability);
string GetMove(int move);
string Generation { get; }
string GameTitle { get; }
string Version { get; }
IHtmlGenerator GetHtmlGenerator();
}
}
@@ -1,6 +1,8 @@
using pk_site.Html;
using PKHeX.Core;
using PKHeX.WinForms;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
@@ -9,13 +11,48 @@ namespace pk_site.Pokemon
public class PKHeXSaveInfo : IPokemonSaveInfo
{
private SaveFile _saveFile;
private GameInfo.GameStrings _gameStrings;
private string _outputDirectory;
private Dictionary<(int, int, int, int, bool, bool, int), (string, string, Image)> _pokemonImageCache = new Dictionary<(int, int, int, int, bool, bool, int), (string, string, Image)>();
private string outputImageRelativeDirectory => "img";
private string outputImageDirectory => Path.Combine(_outputDirectory, outputImageRelativeDirectory);
public PKHeXSaveInfo(string language, string saveFilePath)
public PKHeXSaveInfo(string language, string saveFilePath, string outputDirectory)
{
_saveFile = SaveUtil.getVariantSAV(File.ReadAllBytes(saveFilePath));
_gameStrings = GameInfo.getStrings(language);
_outputDirectory = outputDirectory;
Directory.CreateDirectory(outputImageDirectory);
foreach (var pokemon in _saveFile.PartyData)
{
ProcessPokemon(pokemon);
}
}
private (int, int, int, int, bool, bool, int) GetImageKey(PKM pkm)
=> (pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format);
private void ProcessPokemon(PKM pkm)
{
var imageKey = GetImageKey(pkm);
Image generatedImage = PKMUtil.getSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format);
string imageFileName = ImageKeyToFileName(imageKey) + ".png";
string relativePath = string.Join("/", outputImageRelativeDirectory, imageFileName);
string outputPath = string.Join("/", outputImageDirectory, imageFileName);
_pokemonImageCache[imageKey] = (outputPath, relativePath, generatedImage);
}
private string GetImagePath(PKM pkm)
{
var imageKey = GetImageKey(pkm);
if (_pokemonImageCache.TryGetValue(imageKey, out (string, string, Image) foundImage))
{
return foundImage.Item2;
}
return "";
}
public IEnumerable<IPokemonInfo> PartyMembers =>
@@ -25,7 +62,8 @@ public PKHeXSaveInfo(string language, string saveFilePath)
GetAbility(member.Ability),
member.Nickname,
member.CurrentLevel,
member.Moves.Select(move => GetMove(move))));
member.Moves.Select(move => GetMove(move)),
GetImagePath(member)));
public ITrainerInfo TrainerInfo => new TrainerInfo(
_saveFile.OT,
@@ -38,11 +76,32 @@ public PKHeXSaveInfo(string language, string saveFilePath)
public string GetBall(int ball) => _gameStrings.balllist[ball];
public string GetMove(int move) => _gameStrings.movelist[move];
public string GetSpecies(int species) => _gameStrings.specieslist[species];
public string Generation => _gameStrings.gamelist[_saveFile.Generation];
public string GameTitle => _gameStrings.gamelist[_saveFile.Generation];
public string Version => _saveFile.Version.ToString();
public IHtmlGenerator GetHtmlGenerator()
{
return new HtmlGenerator(Generation, this);
WriteImagesToDisk();
return new HtmlGenerator($"{GameTitle} ({Version})", this);
}
private void WriteImagesToDisk()
{
foreach(var (absolutePath, _, image) in _pokemonImageCache.Values)
{
image.Save(absolutePath);
}
}
private string ImageKeyToFileName((int,int,int,int,bool,bool,int) imageKey)
{
var (species, form, gender, item, isEgg, isShiny, generation) = imageKey;
return ImageKeyToFileName(species, form, gender, item, isEgg, isShiny, generation);
}
private string ImageKeyToFileName(int species, int form, int gender, int item, bool isEgg, bool isShiny, int generation)
{
return $"p{species}-{form}-{gender}-{item}-{(isEgg ? 1 : 0)}-{(isShiny ? 1 : 0)}-{generation}";
}
}
}
@@ -10,16 +10,18 @@ public class PokemonInfo : IPokemonInfo
private string _nickname;
private int _level;
private IEnumerable<string> _moves;
private string _imagePath;
public PokemonInfo(string species, string ball, string ability,
string nickname, int level, IEnumerable<string> moves)
string nickname, int level, IEnumerable<string> moves, string imagePath)
{
_species = species;
_ball = ball;
_ability = ability;
_nickname = nickname;
_level = level;
_moves = moves;
_imagePath = imagePath;
}
public string Species => _species;
@@ -28,5 +30,6 @@ public class PokemonInfo : IPokemonInfo
public string Nickname => _nickname;
public int CurrentLevel => _level;
public IEnumerable<string> Moves => _moves;
public string ImagePath => _imagePath;
}
}
@@ -23,7 +23,7 @@ public class TrainerInfo : ITrainerInfo
public string Name => _name;
public Genders Gender => _gender;
public uint Money => _money;
public string FormattedMoney => _money.ToString("C");
public string FormattedMoney => _money.ToString("C0");
public IEnumerable<string> Badges => _badges;
public string PlayTime => _playTime;
}
@@ -17,7 +17,7 @@ public static void Main(string[] args)
return;
}
IPokemonSaveInfo saveInfo = new PKHeXSaveInfo(options.Language, options.SaveFilePath);
IPokemonSaveInfo saveInfo = new PKHeXSaveInfo(options.Language, options.SaveFilePath, options.OutputDirectory);
IHtmlGenerator renderer = saveInfo.GetHtmlGenerator();
renderer.Write(options.OutputDirectory, saveInfo);
@@ -1,4 +1,4 @@
@charset "UTF-8"
@charset "UTF-8"
body {
background-color: #d1d1f5;
@@ -38,8 +38,18 @@ body {
margin-top: 8px;
}
.moves > .move {
.moves .move {
display: block;
padding: 5px;
width: 100%;
width: 97%;
border-bottom: 1px dashed #6a6777;
}
.pokemon-image {
display: inline;
}
.pokemon-image img {
vertical-align: middle;
width: 75px;
}
@@ -9,21 +9,28 @@
<head>
</head>
<body>
<h1>@Model.Generation</h1>
<h1>@Model.GameTitle</h1>
<div class="trainer">
<label>Name: @Model.TrainerInfo.Name</label>
<label>@Model.TrainerInfo.Gender</label>
<label>Money: @Model.TrainerInfo.Money</label>
<label>Money: @Model.TrainerInfo.FormattedMoney</label>
<label>Play Time: @Model.TrainerInfo.PlayTime</label>
</div>
<div class="pokemon-container">
@foreach (var pokemon in Model.PartyMembers)
{
<div class="pokemon">
<label>@pokemon.Nickname</label>
<label>Lvl. @pokemon.CurrentLevel @pokemon.Species</label>
<label>@pokemon.Ability</label>
<div class="card">
<div class="sub-card">
<label>@pokemon.Nickname</label>
<label>Lvl. @pokemon.CurrentLevel @pokemon.Species</label>
<label>@pokemon.Ability</label>
</div>
<div class="pokemon-image sub-card">
<img src="@pokemon.ImagePath"/>
</div>
</div>
<div class="moves">
@foreach (string move in pokemon.Moves)
{
@@ -47,6 +47,7 @@
<package id="System.Threading" version="4.3.0" targetFramework="net46" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net46" />
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net46" />
<package id="System.ValueTuple" version="4.3.1" targetFramework="net46" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net46" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net46" />
</packages>
@@ -57,6 +57,7 @@
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
</Reference>
@@ -95,6 +96,9 @@
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
@@ -129,6 +133,10 @@
<Project>{62aa7aec-786c-41e4-856f-161c0fcb1c50}</Project>
<Name>PKHeX.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\lib\PKHeX\PKHeX.WinForms\PKHeX.WinForms.csproj">
<Project>{d1b91861-a448-4762-a313-c7bc179f4415}</Project>
<Name>PKHeX.WinForms</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\template.cshtml">

0 comments on commit 88b53d0

Please sign in to comment.