Added formatter classes

This commit is contained in:
Greg Edwards
2015-04-13 19:48:36 -04:00
parent 98fefa0416
commit 5e714435a1
4 changed files with 82 additions and 0 deletions

View File

@@ -86,6 +86,7 @@
<Compile Include="Structures\ByteStatValues.cs" />
<Compile Include="Structures\ContestStatValues.cs" />
<Compile Include="Structures\DressupRecord4.cs" />
<Compile Include="Structures\Format.cs" />
<Compile Include="Structures\GtsRecord5.cs" />
<Compile Include="Structures\Enums.cs" />
<Compile Include="Structures\GtsRecord4.cs" />

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PkmnFoundations.Structures
{
public static class Format
{
private static String[] m_marks = new String[] { "●", "▲", "■", "♥", "★", "♦" };
public static String Markings(Markings markings, String trueFormat, String falseFormat, String delimiter)
{
StringBuilder result = new StringBuilder();
int marking = 1;
for (int value = 0; value < 6; value++)
{
if (marking > 1) result.Append(delimiter);
String format = (((int)markings & marking) != 0) ? trueFormat : falseFormat;
result.Append(String.Format(format, m_marks[value]));
marking <<= 1;
}
return result.ToString();
}
public static String GenderSymbol(Genders gender)
{
switch (gender)
{
case Genders.Male:
return "♂";
case Genders.Female:
return "♀";
default:
return "";
}
}
}
}

39
web/src/WebFormat.cs Normal file
View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using PkmnFoundations.Structures;
namespace PkmnFoundations.Web
{
public static class WebFormat
{
public static String Markings(Markings markings)
{
return Format.Markings(markings, "<span class=\"m\">{0}</span>", "<span>{0}</span>", "");
}
public static String PokemonImage(PokemonPartyBase pokemon)
{
return (pokemon.IsShiny ? "~/images/pkmn-lg-s/" : "~/images/pkmn-lg/") +
PokemonImage2(pokemon) + ".png";
}
private static String PokemonImage2(PokemonPartyBase pkmn)
{
// todo: spinda
StringBuilder builder = new StringBuilder();
builder.Append(pkmn.SpeciesID);
if (pkmn.Form.Suffix.Length > 0)
{
builder.Append('-');
builder.Append(pkmn.Form.Suffix);
}
if (pkmn.Species.GenderVariations && pkmn.Gender == Genders.Female)
builder.Append("-f");
return builder.ToString();
}
}
}

View File

@@ -3587,6 +3587,7 @@
<Compile Include="src\RetinaImage.cs" />
<Compile Include="src\RetinaImageBase.cs" />
<Compile Include="src\WebException.cs" />
<Compile Include="src\WebFormat.cs" />
<Compile Include="test\BoxUp.aspx.cs">
<DependentUpon>BoxUp.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>