Skip to content

Commit

Permalink
New string format
Browse files Browse the repository at this point in the history
  • Loading branch information
alyral authored Jul 6, 2021
1 parent 92759c9 commit cef6e35
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions Werewolf for Telegram/Database/AchievementsReworked.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
using System;
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Database
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
//Your code goes here
var useXml = false;
var achvs = Enum.GetValues(typeof(AchievementsReworked)).Cast<AchievementsReworked>().ToList();
var text = "Result:";
foreach (var achv in achvs)
{
text += Environment.NewLine;
if (!useXml)
{
text += Environment.NewLine;
}
text += GetResult(achv, useXml);
}
Console.WriteLine(text);
}
public static string GetResult(AchievementsReworked a, bool useXml)
{
string name = a.GetName();
string name_string = a.GetName(false);
string descr = a.GetDescription();
string descr_string = a.GetDescription(false);
if (useXml)
{
// Lines
var string_key_name = $" <string key=\"{name_string}\">";
var string_key_descr = $" <string key=\"{descr_string}\">";
var string_closure = $" </string>";
var string_value_name = $" <value>{name}</value>";
var string_value_descr = $" <value>{descr}</value>";
var n = Environment.NewLine;
// Strings
var rTxt = string_key_name + n + string_value_name + n + string_closure + n;
rTxt += string_key_descr + n + string_value_descr + n + string_closure;
return rTxt;
}
else
{
return $"{name_string}: {name}{Environment.NewLine}{descr_string}: {descr}";
}
}
}
public enum AchievementsReworked
{
[Display(Name = "None"), Description("You haven't played a game yet!")]
Expand Down Expand Up @@ -223,10 +272,7 @@ public static string GetDescription(this AchievementsReworked value, bool text =
return value.ToString();
}
else
{
var achvId = (int)value;
return $"Achievement{achvId.ToString()}Descr";
}
return $"Achievement{value.ToString()}Descr";
}
public static string GetName(this AchievementsReworked value, bool text = true)
{
Expand All @@ -241,10 +287,7 @@ public static string GetName(this AchievementsReworked value, bool text = true)
return (descriptionAttributes.Length > 0) ? descriptionAttributes[0].Name : value.ToString();
}
else
{
var achvId = (int)value;
return $"Achievement{achvId.ToString()}Name";
}
return $"Achievement{value.ToString()}Name";
}

public static byte[] ToByteArray(this BitArray bits)
Expand Down

0 comments on commit cef6e35

Please sign in to comment.