Skip to content
Permalink
Browse files

Got system for localization

Localized Octgn.Cure, Octgn.DataNew, Octgn.Library, Octgn.ProxyGenerator, Octgn.Server
  • Loading branch information...
kellyelton committed Oct 3, 2014
1 parent 7e5261d commit b216e6b1423894f65f13495b332b1f5290388bb4
@@ -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>
@@ -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
{
@@ -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");
@@ -124,7 +125,7 @@ public static string GetPicture(this ICard card)
return uri.LocalPath;
}
else
{
{
return uri.LocalPath;
}
}
@@ -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)
@@ -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;
}

@@ -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)
@@ -16,6 +16,8 @@
using Octgn.Library.Exceptions;

using log4net;
using Octgn.Library.Localization;

namespace Octgn.Core.DataExtensionMethods
{
public static class DeckExtensionMethods
@@ -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);
}
}

@@ -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);
}
}

@@ -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);
@@ -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;
}
@@ -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));
}
@@ -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;
}
@@ -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());
@@ -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;
}

@@ -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)
@@ -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>();
@@ -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)
@@ -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>();
@@ -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)

0 comments on commit b216e6b

Please sign in to comment.
You can’t perform that action at this time.