Skip to content

Commit

Permalink
Got system for localization
Browse files Browse the repository at this point in the history
Localized Octgn.Cure, Octgn.DataNew, Octgn.Library, Octgn.ProxyGenerator, Octgn.Server
  • Loading branch information
kellyelton committed Oct 3, 2014
1 parent 7e5261d commit b216e6b
Show file tree
Hide file tree
Showing 22 changed files with 1,174 additions and 132 deletions.
1 change: 1 addition & 0 deletions OCTGN.sln.DotSettings
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Octgn_002ELibrary_002EAnnotations/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">/* This Source Code Form is subject to the terms of the Mozilla Public&#xD;
* License, v. 2.0. If a copy of the MPL was not distributed with this&#xD;
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */</s:String></wpf:ResourceDictionary>
37 changes: 19 additions & 18 deletions octgnFX/Octgn.Core/DataExtensionMethods/CardExtensionMethods.cs
Expand Up @@ -5,20 +5,21 @@
using System.Diagnostics;
using Octgn.Library;
using Octgn.Library.Exceptions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

namespace Octgn.Core.DataExtensionMethods
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using Octgn.Core.DataManagers;
using Octgn.DataNew.Entities;

using Octgn.Core.DataManagers;
using Octgn.DataNew.Entities;
using log4net;
using Octgn.Library.Localization;

using log4net;
namespace Octgn.Core.DataExtensionMethods
{

public static class CardExtensionMethods
{
Expand Down Expand Up @@ -87,9 +88,9 @@ public static string GetPicture(this ICard card)
var path = set.ImagePackUri;
if (Directory.Exists(path) == false)
{
throw new UserMessageException("Can not find directory {0}. This ususally means something is wrong with your game definition.");
throw new UserMessageException(L.D.Exception__CanNotFindDirectoryGameDefBroken_Format,path);
}
var files = Directory.GetFiles(set.ImagePackUri, card.GetImageUri() + ".*").OrderBy(x=>x.Length).ToArray();
var files = Directory.GetFiles(set.ImagePackUri, card.GetImageUri() + ".*").OrderBy(x => x.Length).ToArray();
if (files.Length == 0) //Generate or grab proxy
{
files = Directory.GetFiles(set.ProxyPackUri, card.GetImageUri() + ".png");
Expand Down Expand Up @@ -124,7 +125,7 @@ public static string GetPicture(this ICard card)
return uri.LocalPath;
}
else
{
{
return uri.LocalPath;
}
}
Expand Down Expand Up @@ -154,7 +155,7 @@ public static string GetImageUri(this ICard card)

public static bool HasProperty(this Card card, string name)
{
return card.Properties[card.Alternate].Properties.Any(x => x.Key.Name.Equals(name,StringComparison.InvariantCultureIgnoreCase) && x.Key.IsUndefined == false);
return card.Properties[card.Alternate].Properties.Any(x => x.Key.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) && x.Key.IsUndefined == false);
}

public static Dictionary<string, string> GetProxyMappings(this ICard card)
Expand All @@ -169,14 +170,14 @@ public static bool HasProperty(this Card card, string name)

public static IDictionary<PropertyDef, object> PropertySet(this ICard card)
{
var ret = card.Properties[card.Alternate].Properties.Where(x=>x.Key.IsUndefined == false).ToDictionary(x=>x.Key,x=>x.Value);
var ret = card.Properties[card.Alternate].Properties.Where(x => x.Key.IsUndefined == false).ToDictionary(x => x.Key, x => x.Value);
return ret;
}

public static void SetPropertySet(this Card card, string propertyType = "")
{
if (String.IsNullOrWhiteSpace(propertyType)) propertyType = "";
if(card.Properties.Any(x=>x.Key.Equals(propertyType,StringComparison.InvariantCultureIgnoreCase)))
if (card.Properties.Any(x => x.Key.Equals(propertyType, StringComparison.InvariantCultureIgnoreCase)))
card.Alternate = propertyType;
}

Expand All @@ -197,7 +198,7 @@ public static MultiCard Clone(this MultiCard card)
Alternate = card.Alternate.Clone() as string,
ImageUri = card.ImageUri.Clone() as string,
Quantity = card.Quantity,
Properties = new Dictionary<string,CardPropertySet>(),
Properties = new Dictionary<string, CardPropertySet>(),
SetId = card.SetId
};
foreach (var p in card.Properties)
Expand Down
33 changes: 17 additions & 16 deletions octgnFX/Octgn.Core/DataExtensionMethods/DeckExtensionMethods.cs
Expand Up @@ -16,6 +16,8 @@
using Octgn.Library.Exceptions;

using log4net;
using Octgn.Library.Localization;

namespace Octgn.Core.DataExtensionMethods
{
public static class DeckExtensionMethods
Expand Down Expand Up @@ -63,17 +65,17 @@ public static void Save(this IDeck deck, Game game, string path)
}
catch (PathTooLongException)
{
throw new UserMessageException("Could not save deck to {0}, the file path would be too long.", path);
throw new UserMessageException(L.D.Exception__CanNotSaveDeckPathTooLong_Format, path);
}
catch (IOException e)
{
Log.Error(String.Format("Problem saving deck to path {0}", path), e);
throw new UserMessageException("Could not save deck to {0}, {1}", path, e.Message);
throw new UserMessageException(L.D.Exception__CanNotSaveDeckIOError_Format, path, e.Message);
}
catch (Exception e)
{
Log.Error(String.Format("Problem saving deck to path {0}", path), e);
throw new UserMessageException("Could not save deck to {0}, there was an unspecified problem.", path);
throw new UserMessageException(L.D.Exception__CanNotSaveDeckUnspecified_Format, path);
}
}

Expand All @@ -100,17 +102,17 @@ public static void ExportAsText(this IDeck deck, Game game, string path)
}
catch (PathTooLongException)
{
throw new UserMessageException("Could not export deck to {0}, the file path would be too long.", path);
throw new UserMessageException(L.D.Exception__CanNotSaveDeckPathTooLong_Format, path);
}
catch (IOException e)
{
Log.Warn(String.Format("Problem exporting deck to path {0}", path), e);
throw new UserMessageException("Could not exporting deck to {0}, {1}", path, e.Message);
throw new UserMessageException(L.D.Exception__CanNotSaveDeckIOError_Format, path, e.Message);
}
catch (Exception e)
{
Log.Warn(String.Format("Problem saving deck to path {0}", path), e);
throw new UserMessageException("Could not export deck to {0}, there was an unspecified problem.", path);
throw new UserMessageException(L.D.Exception__CanNotSaveDeckUnspecified_Format, path);
}
}

Expand All @@ -127,7 +129,7 @@ public static IDeck Load(this IDeck deck, string path, bool cloneCards = true)
game = Octgn.Core.DataManagers.GameManager.Get().GetById(gameId);
if (game == null)
{
throw new UserMessageException("Could not load deck from {0}, you do not have the associated game installed.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckGameNotInstalled_Format, path);
}
}
return deck.Load(game, path, cloneCards);
Expand All @@ -139,7 +141,7 @@ public static IDeck Load(this IDeck deck, string path, bool cloneCards = true)
catch (Exception e)
{
Log.Error(String.Format("Problem loading deck from path {0}", path), e);
throw new UserMessageException("Could not load deck from {0}, there was an unspecified problem.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckUnspecified_Format, path);
}
return null;
}
Expand Down Expand Up @@ -175,8 +177,7 @@ public static IDeck Load(this IDeck deck, Game game, string path, bool cloneCard
var cardN = cardelem.Value;
card = cards.FirstOrDefault(x => x.Name.Equals(cardN, StringComparison.CurrentCultureIgnoreCase));
if (card == null)
throw new UserMessageException(
"Problem loading deck {0}. The card with id: {1} and name: {2} is not installed.", path, cardId, cardN);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckCardNotInstalled_Format, path, cardId, cardN);
}
(section.Cards as IList<IMultiCard>).Add(card.ToMultiCard(cardq, cloneCards));
}
Expand Down Expand Up @@ -234,31 +235,31 @@ public static IDeck Load(this IDeck deck, Game game, string path, bool cloneCard
catch (FormatException e)
{
Log.Error(String.Format("Problem loading deck from path {0}", path), e);
throw new UserMessageException("The deck {0} is corrupt.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckCorrupt_Format, path);
}
catch (NullReferenceException e)
{
Log.Error(String.Format("Problem loading deck from path {0}", path), e);
throw new UserMessageException("The deck {0} is corrupt.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckCorrupt_Format, path);
}
catch (XmlException e)
{
Log.Error(String.Format("Problem loading deck from path {0}", path), e);
throw new UserMessageException("The deck {0} is corrupt.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckCorrupt_Format, path);
}
catch (FileNotFoundException)
{
throw new UserMessageException("Could not save deck to {0}, could not file the file.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckFileNotFound_Format, path);
}
catch (IOException e)
{
Log.Error(String.Format("Problem loading deck from path {0}", path), e);
throw new UserMessageException("Could not load deck from {0}, {1}", path, e.Message);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckIOError_Format, path, e.Message);
}
catch (Exception e)
{
Log.Error(String.Format("Problem loading deck from path {0}", path), e);
throw new UserMessageException("Could not load deck from {0}, there was an unspecified problem.", path);
throw new UserMessageException(L.D.Exception__CanNotLoadDeckUnspecified_Format, path);
}
return ret;
}
Expand Down
57 changes: 29 additions & 28 deletions octgnFX/Octgn.Core/DataExtensionMethods/GameExtensionMethods.cs
@@ -1,25 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.IO.Abstractions;
using System.Linq;

using Octgn.Core.DataManagers;
using Octgn.DataNew;
using Octgn.DataNew.Entities;
using Octgn.Library;
using Octgn.Library.Exceptions;
using Octgn.Library.Localization;
using Octgn.ProxyGenerator;
namespace Octgn.Core.DataExtensionMethods
{
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.IO.Abstractions;
using System.Linq;

using Octgn.Core.DataManagers;
using Octgn.DataNew;
using Octgn.DataNew.Entities;
using Octgn.Library;
using Octgn.Library.Exceptions;
using Octgn.ProxyGenerator;

public static class GameExtensionMethods
{
internal static IFileSystem IO {
internal static IFileSystem IO
{
get
{
return io ?? (io = new FileSystem());
Expand Down Expand Up @@ -59,8 +60,8 @@ public static Game UpdateGameHash(this Game game, string hash)
public static Deck CreateDeck(this Game game)
{
var deck = new Deck { GameId = game.Id };
deck.Sections = game.DeckSections.Select(x=> new Section{Name=x.Value.Name.Clone() as string,Cards = new List<IMultiCard>(),Shared = x.Value.Shared}).ToList();
deck.Sections = deck.Sections.Concat(game.SharedDeckSections.Select(x=> new Section{Name=x.Value.Name.Clone() as string,Cards = new List<IMultiCard>(),Shared = x.Value.Shared})).ToList();
deck.Sections = game.DeckSections.Select(x => new Section { Name = x.Value.Name.Clone() as string, Cards = new List<IMultiCard>(), Shared = x.Value.Shared }).ToList();
deck.Sections = deck.Sections.Concat(game.SharedDeckSections.Select(x => new Section { Name = x.Value.Name.Clone() as string, Cards = new List<IMultiCard>(), Shared = x.Value.Shared })).ToList();
return deck;
}

Expand Down Expand Up @@ -92,7 +93,7 @@ public static Card GetCardByName(this Game game, string name)
{
//var g = GameManager.Get().GetById(game.Id);
//if (g == null) return null;
return game.Sets().SelectMany(x => x.Cards).FirstOrDefault(y => y.Name.Equals(name,StringComparison.InvariantCultureIgnoreCase));
return game.Sets().SelectMany(x => x.Cards).FirstOrDefault(y => y.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}

public static Card GetCardById(this Game game, Guid id)
Expand All @@ -109,7 +110,7 @@ public static Set GetSetById(this Game game, Guid id)
return g.Sets().FirstOrDefault(x => x.Id == id);
}

public static IEnumerable<Marker> GetAllMarkers( this Game game)
public static IEnumerable<Marker> GetAllMarkers(this Game game)
{
var g = GameManager.Get().GetById(game.Id);
if (g == null) return new List<Marker>();
Expand All @@ -127,7 +128,7 @@ public static IEnumerable<PropertyDef> AllProperties(this Game game)
{
var g = GameManager.Get().GetById(game.Id);
if (g == null) return new List<PropertyDef>();
return Enumerable.Repeat(new PropertyDef{Name="Name", Type = PropertyType.String}, 1).Union(game.CustomProperties);
return Enumerable.Repeat(new PropertyDef { Name = "Name", Type = PropertyType.String }, 1).Union(game.CustomProperties);
}

public static IEnumerable<Card> AllCards(this Game game)
Expand All @@ -140,7 +141,7 @@ public static IEnumerable<Card> AllCards(this Game game)
public static DataTable ToDataTable(this IEnumerable<Card> cards, Game game)
{
DataTable table = new DataTable();

var values = new object[game.CustomProperties.Count + 5 - 1];
var defaultValues = new object[game.CustomProperties.Count + 5 - 1];
var indexes = new Dictionary<int, string>();
Expand Down Expand Up @@ -191,24 +192,24 @@ public static DataTable ToDataTable(this IEnumerable<Card> cards, Game game)
values[i] = defaultValues[i];
}
values[0] = item.Name;
if(!setCache.ContainsKey(item.SetId))
setCache.Add(item.SetId,item.GetSet().Name);
if (!setCache.ContainsKey(item.SetId))
setCache.Add(item.SetId, item.GetSet().Name);
values[1] = setCache[item.SetId];
values[2] = item.SetId;
values[3] = item.ImageUri;
values[4] = item.Id;
foreach (var prop in item.PropertySet())
{
if (prop.Key.Name == "Name") continue;
var ix = indexes.Where(x => x.Value == prop.Key.Name).Select(x=>new {Key=x.Key,Value=x.Value}).FirstOrDefault();
if(ix == null)
throw new UserMessageException("The game you are trying to make a deck for has a missing property on a card. Please contact the game developer and let them know.");
var ix = indexes.Where(x => x.Value == prop.Key.Name).Select(x => new { Key = x.Key, Value = x.Value }).FirstOrDefault();
if (ix == null)
throw new UserMessageException(L.D.Exception__CanNotCreateDeckMissingCardProperty);
values[ix.Key] = prop.Value;
}

table.Rows.Add(values);
}
return table;
return table;
}

public static ProxyDefinition GetCardProxyDef(this Game game)
Expand Down

0 comments on commit b216e6b

Please sign in to comment.