Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Commit

Permalink
i18n core
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Feb 20, 2018
1 parent 427a219 commit c00d30b
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 44 deletions.
40 changes: 22 additions & 18 deletions CardSharp.I18N/CardSharp.I18N.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>7c7b94d8-9aaf-4d78-888e-42788404976e</ProjectGuid>
<ProjectGuid>{7C7B94D8-9AAF-4D78-888E-42788404976E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CardSharp.I18N</RootNamespace>
Expand All @@ -30,24 +30,28 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>

<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>


<Reference Include="Microsoft.CSharp"/>

<Reference Include="System.Data"/>

<Reference Include="System.Net.Http"/>

<Reference Include="System.Xml"/>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="EmbedResourceReader.cs" />
<Compile Include="Localization.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Lang\zh_CN\dalao.json" />
<EmbeddedResource Include="Lang\zh_CN\kawaii.json" />
<EmbeddedResource Include="Lang\zh_CN\normal.json" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
12 changes: 0 additions & 12 deletions CardSharp.I18N/Class1.cs

This file was deleted.

25 changes: 25 additions & 0 deletions CardSharp.I18N/EmbedResourceReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CardSharp.I18N
{
public class EmbedResourceReader
{
public static string Read(string name)
{
var stream = GetStream(name);
return stream == null ? null : new StreamReader(stream).ReadToEnd();
}

public static Stream GetStream(string name)
{
var currentAssembly = Assembly.GetCallingAssembly();
return currentAssembly.GetManifestResourceStream(name);
}
}
}
4 changes: 0 additions & 4 deletions CardSharp.I18N/Lang/zh_CN/dalao.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"name": "大叔型",
"cards": [
"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A",
"2", "", ""
],
"rules": {
"Rule3": "3带0",
"Rule3With1": "3带1",
Expand Down
4 changes: 0 additions & 4 deletions CardSharp.I18N/Lang/zh_CN/kawaii.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"name": "可爱型",
"cards": [
"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A",
"2", "", ""
],
"rules": {
"Rule3": "3带0",
"Rule3With1": "3带1",
Expand Down
4 changes: 0 additions & 4 deletions CardSharp.I18N/Lang/zh_CN/normal.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"name": "普通型",
"cards": [
"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A",
"2", "", ""
],
"rules": {
"Rule3": "3带0",
"Rule3With1": "3带1",
Expand Down
47 changes: 47 additions & 0 deletions CardSharp.I18N/Localization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace CardSharp.I18N
{
public class Localization
{
public static List<Language> Languages { get; } = GetNames()
.Select(name => new Language(name)).ToList();

public static dynamic Normal { get; } = Languages.First(lang => lang.Name == "normal").Content;

private static IEnumerable<string> GetNames()
{
return Assembly.GetExecutingAssembly().GetManifestResourceNames();
}
}

public class Language
{
public string Name;
public string CultureName;
public JObject Content;

public Language(string filePath)
{
Content = JObject.Parse(EmbedResourceReader.Read(filePath));
SetName(filePath);
}

private void SetName(string filePath)
{
var count = typeof(Language).ToString().Split('.').Length;
var sp = filePath.Split('.').Skip(count).ToArray();
CultureName = sp[0];
Name = sp[1];
}
}

}
4 changes: 4 additions & 0 deletions CardSharp.I18N/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net461" />
</packages>
6 changes: 6 additions & 0 deletions CardSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Origind.Card.Game", "Origin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CardSharp.GUI", "CardSharp.GUI\CardSharp.GUI.csproj", "{48AFBFAC-C4C5-4ECD-A361-76F82A7B16EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CardSharp.I18N", "CardSharp.I18N\CardSharp.I18N.csproj", "{7C7B94D8-9AAF-4D78-888E-42788404976E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -31,6 +33,10 @@ Global
{48AFBFAC-C4C5-4ECD-A361-76F82A7B16EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48AFBFAC-C4C5-4ECD-A361-76F82A7B16EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48AFBFAC-C4C5-4ECD-A361-76F82A7B16EC}.Release|Any CPU.Build.0 = Release|Any CPU
{7C7B94D8-9AAF-4D78-888E-42788404976E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C7B94D8-9AAF-4D78-888E-42788404976E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C7B94D8-9AAF-4D78-888E-42788404976E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C7B94D8-9AAF-4D78-888E-42788404976E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions CardSharp/CardSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,11 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CardSharp.I18N\CardSharp.I18N.csproj">
<Project>{7c7b94d8-9aaf-4d78-888e-42788404976e}</Project>
<Name>CardSharp.I18N</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 2 additions & 0 deletions CardSharp/GameComponents/Desk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public Desk(string deskId, string groupName = "DefaultGroupName")
GroupName = groupName;
_currentParser = new WaitingParser();
_standardParser = new StandardParser();

}

public int Multiplier { get; internal set; }

public bool SuddenDeathEnabled { get; internal set; }

public bool Silence { get; internal set; }
public dynamic Localization;

public GameState State
{
Expand Down
2 changes: 1 addition & 1 deletion CardSharp/GameSteps/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public CommandParser(Desk desk)

public void Prepare(Desk desk)
{
desk.AddMessage(string.Format("请{0}出牌", desk.CurrentPlayer.ToAtCodeWithRole()));
desk.AddMessage(string.Format(desk.Localization.messages.wait_submit, desk.CurrentPlayer.ToAtCodeWithRole()));
RunHostedCheck(desk);
}

Expand Down
2 changes: 1 addition & 1 deletion CardSharp/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static string AddNewLine(this string source)

public static bool IsValidCardString(this string source)
{
return Regex.IsMatch(source, "([2-9]|10|A|王|鬼).*");
return Regex.IsMatch(source, "([2-9]|10|A|王|鬼)+");
}

public static IEnumerable<Card> ToCards(this string source)
Expand Down

0 comments on commit c00d30b

Please sign in to comment.