Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move codeblocks into single json config file #749

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AICUpdater/AICUpdaterHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UCPAIConversion;
Expand Down
2 changes: 1 addition & 1 deletion AICUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void Main(string[] args)
Console.WriteLine("The property names of the following .aic files will be updated.");
Console.WriteLine("Any custom comments will be lost in the process!");
Console.WriteLine();
foreach(string file in files)
foreach (string file in files)
{
Console.WriteLine(Path.GetFileName(file));
}
Expand Down
1 change: 0 additions & 1 deletion AICUpdater/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
Expand Down
18 changes: 16 additions & 2 deletions CodeBlox/CodeBlock.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;

/* Unmerged change from project 'UnofficialCrusaderPatch'
Before:
using System.Text;
using System.IO;
using System.Globalization;
After:
using System.IO;
using System.Linq;
*/
using System.IO;
using System.Text;

namespace CodeBlox
{
Expand Down Expand Up @@ -42,6 +50,12 @@ public static implicit operator Element(bool wildcard)
public int Length { get { return elements.Length; } }
public IEnumerable<Element> Elements { get { return this.elements; } }

public static CodeBlock Get(string codeBlockName)
{
string codeBlock = CodeBlockRetriever.CodeBlocks[codeBlockName];
return new CodeBlock(new MemoryStream(Encoding.UTF8.GetBytes(codeBlock)));
}

public CodeBlock(Stream stream)
{
List<Element> list = new List<Element>((int)stream.Length / 2);
Expand Down
20 changes: 20 additions & 0 deletions CodeBlox/CodeBlockRetriever.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Web.Script.Serialization;

namespace CodeBlox
{
public class CodeBlockRetriever
{

public static Dictionary<string, string> CodeBlocks { get; set; }
static CodeBlockRetriever()
{
Assembly asm = Assembly.GetExecutingAssembly();
string file = string.Format("UCP.CodeBlocks.CodeBlocks.json");
using (Stream stream = asm.GetManifestResourceStream(file))
CodeBlocks = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(new StreamReader(stream).ReadToEnd());
}
}
}
2 changes: 2 additions & 0 deletions CodeBlox/CodeBlox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -43,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CodeBlock.cs" />
<Compile Include="CodeBlockRetriever.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions CodeBlox/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using System.IO;

namespace CodeBlox
{
Expand Down
1 change: 0 additions & 1 deletion CodeBlox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Allgemeine Informationen über eine Assembly werden über die folgenden
Expand Down
4 changes: 1 addition & 3 deletions IDAParser/AICharacters/AICCollection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Linq;

namespace UCP.AICharacters
{
Expand Down
8 changes: 1 addition & 7 deletions IDAParser/AICharacters/AICIndex.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
/// <summary>
/// Indices with which each AI is identified in the game, the order is defined Crusader-intern
Expand Down
7 changes: 1 addition & 6 deletions IDAParser/AICharacters/AICharacter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
/// <summary>
/// The topmost character class which contains the AI's personality, its Crusader-intern index and more in the future
Expand Down
7 changes: 1 addition & 6 deletions IDAParser/AICharacters/AIFileHeader.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
public class AIFileHeader
{
Expand Down
6 changes: 1 addition & 5 deletions IDAParser/AICharacters/AIPersonality.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection;

namespace UCP.AICharacters
{
Expand Down
7 changes: 3 additions & 4 deletions IDAParser/AICharacters/AIReader.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Text;

namespace UCP.AICharacters
{
Expand Down Expand Up @@ -91,7 +90,7 @@ void CheckComments(ref string line)
return default(T);

} while (line != type.Name);

T result = new T();
this.Read(result);
return result;
Expand All @@ -115,7 +114,7 @@ void Read(object o)
{
if (line == "}")
break;

// get name of field
string fieldName;
int endIndex = line.IndexOfAny(whiteSpaces);
Expand Down
12 changes: 6 additions & 6 deletions IDAParser/AICharacters/AIWriter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace UCP.AICharacters
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public void CloseCommentSec()
this.WriteLine("*/");
commenting = false;
}

public void Write(object o, string name = null)
{
if (o == null)
Expand All @@ -87,9 +87,9 @@ public void Write(object o, string name = null)
this.WriteLine(name ?? type.Name);
this.OpenSec();

foreach(FieldInfo fi in type.GetFields(Flags))
foreach (FieldInfo fi in type.GetFields(Flags))
{
object value = fi.GetValue(o);
object value = fi.GetValue(o);
this.Write(value, fi.Name);
}

Expand All @@ -104,7 +104,7 @@ public void WriteInfo(Type type, string name = null, string comment = null)
{
if (type == null)
throw new ArgumentNullException("type");

if (!String.IsNullOrWhiteSpace(name))
{
sb.Append(name);
Expand Down
7 changes: 1 addition & 6 deletions IDAParser/AICharacters/PersonalityEnums/Buildings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
/// <summary>
/// Crusader-intern military unit IDs
Expand Down
7 changes: 1 addition & 6 deletions IDAParser/AICharacters/PersonalityEnums/Resources.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
/// <summary>
/// Crusader-intern resource IDs
Expand Down
7 changes: 1 addition & 6 deletions IDAParser/AICharacters/PersonalityEnums/SiegeEngines.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
/// <summary>
/// Crusader-intern military unit IDs
Expand Down
7 changes: 1 addition & 6 deletions IDAParser/AICharacters/PersonalityEnums/TargetingType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCP.AICharacters
namespace UCP.AICharacters
{
/// <summary> How the AI determines its next attack target. </summary>
public enum TargetingType
Expand Down
Loading