diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-10 16:06:54 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-10 16:06:54 +0300 |
| commit | 0456aaa884f36bf3a5181f37b29a72af0db39c05 (patch) | |
| tree | 15f834485a0a2eacb020faf3c275b194fe889503 | |
| parent | 2962d37ae5d1a2590d48cd236d7765bc52158ec0 (diff) | |
| download | Mundus-0456aaa884f36bf3a5181f37b29a72af0db39c05.tar Mundus-0456aaa884f36bf3a5181f37b29a72af0db39c05.tar.gz Mundus-0456aaa884f36bf3a5181f37b29a72af0db39c05.zip | |
Transferred game event logs to MySQL database (database Mundus, table GameEventLogs) using Entity Framework Core.
| -rw-r--r-- | Mundus/Data/Crafting/CraftingTableContext.cs | 3 | ||||
| -rw-r--r-- | Mundus/Data/DataBaseContext.cs | 15 | ||||
| -rw-r--r-- | Mundus/Data/GameEventLogContext.cs | 43 | ||||
| -rw-r--r-- | Mundus/Data/Log.cs | 10 | ||||
| -rw-r--r-- | Mundus/Mundus.csproj | 4 | ||||
| -rw-r--r-- | Mundus/Program.cs | 13 | ||||
| -rw-r--r-- | Mundus/Service/GameEventLog.cs | 16 | ||||
| -rw-r--r-- | Mundus/Service/LogController.cs | 10 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Crafting/CraftingController.cs | 3 |
9 files changed, 85 insertions, 32 deletions
diff --git a/Mundus/Data/Crafting/CraftingTableContext.cs b/Mundus/Data/Crafting/CraftingTableContext.cs index 0a8c6c1..760131a 100644 --- a/Mundus/Data/Crafting/CraftingTableContext.cs +++ b/Mundus/Data/Crafting/CraftingTableContext.cs @@ -6,11 +6,10 @@ using Mundus.Service.Tiles.Items.Presets; namespace Mundus.Data.Crafting { public class CraftingTableContext : DbContext {
- public DbSet<CraftingRecipe> CraftingRecipes { get; set; }
+ public DbSet<CraftingRecipe> CraftingRecipes { get; private set; }
public CraftingTableContext() : base()
{ }
-
public void AddRecipes() { ResetTable(); diff --git a/Mundus/Data/DataBaseContext.cs b/Mundus/Data/DataBaseContext.cs new file mode 100644 index 0000000..5e9076a --- /dev/null +++ b/Mundus/Data/DataBaseContext.cs @@ -0,0 +1,15 @@ +using System; +using Mundus.Data.Crafting; + +namespace Mundus.Data { + public static class DataBaseContext { + public static CraftingTableContext CTContext { get; private set; } + public static GameEventLogContext GELContext { get; private set; } + + public static void CreateInstances() { + CTContext = new CraftingTableContext(); + CTContext.AddRecipes(); + GELContext = new GameEventLogContext(); + } + } +} diff --git a/Mundus/Data/GameEventLogContext.cs b/Mundus/Data/GameEventLogContext.cs new file mode 100644 index 0000000..be1fe53 --- /dev/null +++ b/Mundus/Data/GameEventLogContext.cs @@ -0,0 +1,43 @@ +using System; +using System.Linq; +using Microsoft.EntityFrameworkCore; +using Mundus.Service; + +namespace Mundus.Data { + public class GameEventLogContext : DbContext { + public DbSet<GameEventLog> GameEventLogs { get; private set; } + + public GameEventLogContext() :base() + { + ResetTable(); + } + + private void ResetTable() { + GameEventLogs.RemoveRange(GameEventLogs); + this.SaveChanges(); + } + + public void AddMessage(string message) { + GameEventLogs.Add(new GameEventLog(message)); + this.SaveChanges(); + } + + public string GetMessage(int id) { + return GameEventLogs.Single(x => x.ID == id).Message; + } + + public int GetCount() { + return GameEventLogs.Count(); + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + optionsBuilder.UseMySQL( + "server=localhost;" + + "port=3306;" + + "user id=root; " + + "password=password; " + + "database=Mundus; " + + "SslMode=none"); + } + } +} diff --git a/Mundus/Data/Log.cs b/Mundus/Data/Log.cs deleted file mode 100644 index 0da7e92..0000000 --- a/Mundus/Data/Log.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Mundus.Data { - public static class Log { - public static List<string> LogMessages { get; set; } - - - } -} diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index 1a23716..46985db 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -267,7 +267,6 @@ <Compile Include="Data\SuperLayers\Sky.cs" />
<Compile Include="Service\SuperLayers\Generators\SkySuperLayerGenerator.cs" />
<Compile Include="Data\Difficulty.cs" />
- <Compile Include="Data\Log.cs" />
<Compile Include="Service\LogController.cs" />
<Compile Include="Views\Windows\LogWindow.cs" />
<Compile Include="gtk-gui\Mundus.Views.Windows.LogWindow.cs" />
@@ -293,6 +292,9 @@ <Compile Include="Views\Windows\GameWindows\MediumGameWindow.cs" />
<Compile Include="Views\Windows\GameWindows\SmallGameWindow.cs" />
<Compile Include="Data\Crafting\CraftingTableContext.cs" />
+ <Compile Include="Data\GameEventLogContext.cs" />
+ <Compile Include="Service\GameEventLog.cs" />
+ <Compile Include="Data\DataBaseContext.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Service\" />
diff --git a/Mundus/Program.cs b/Mundus/Program.cs index 48992b5..2750469 100644 --- a/Mundus/Program.cs +++ b/Mundus/Program.cs @@ -1,28 +1,19 @@ using Gtk; +using Mundus.Data; using Mundus.Data.Crafting; using Mundus.Data.Dialogues; using Mundus.Data.Superlayers.Mobs; using Mundus.Data.SuperLayers; using Mundus.Data.Windows; -using Mundus.Data; -using Mundus.Service; -using Mundus.Service.Tiles.Crafting; -using Mundus.Service.Tiles.Items.Presets; namespace Mundus { public static class MainClass { public static bool runGame = true; - public static CraftingTableContext CTController { get; private set; } public static void Main(string[] args) { - //DBController = new DatabaseController(); - //Data.Crafting.CraftingTableContext.CreateRecipes(); - CTController = new CraftingTableContext(); - CTController.AddRecipes(); - + DataBaseContext.CreateInstances(); Application.Init(); //All windows and dialogues that are used by user (instances) are saved and created in WindowInstances.cs - LogController.Initialize(); WI.CreateInstances(); DI.CreateInstances(); LI.CreateInstances(); diff --git a/Mundus/Service/GameEventLog.cs b/Mundus/Service/GameEventLog.cs new file mode 100644 index 0000000..f718e82 --- /dev/null +++ b/Mundus/Service/GameEventLog.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Mundus.Service { + [Table("GameEventLogs", Schema = "Mundus")] + public class GameEventLog { + [Key] + public int ID { get; private set; } + public string Message { get; private set; } + + public GameEventLog(string message) { + this.Message = message; + } + } +} diff --git a/Mundus/Service/LogController.cs b/Mundus/Service/LogController.cs index ca4feb4..07a0f3a 100644 --- a/Mundus/Service/LogController.cs +++ b/Mundus/Service/LogController.cs @@ -4,20 +4,16 @@ using Mundus.Data; namespace Mundus.Service { public static class LogController { - public static void Initialize() { - Log.LogMessages = new List<string>(); - } - public static void AddMessage(string logMessage) { - Log.LogMessages.Add(logMessage); + DataBaseContext.GELContext.AddMessage(logMessage); } public static string GetMessagage(int index) { - return (0 <= index && index < GetCount()) ? Log.LogMessages[index] : null; + return (0 <= index && index < GetCount()) ? DataBaseContext.GELContext.GetMessage(index + 1) : null; } public static int GetCount() { - return Log.LogMessages.Count; + return DataBaseContext.GELContext.GetCount(); } } }
\ No newline at end of file diff --git a/Mundus/Service/Tiles/Crafting/CraftingController.cs b/Mundus/Service/Tiles/Crafting/CraftingController.cs index aedaa3a..8a61c90 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingController.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingController.cs @@ -5,6 +5,7 @@ using Mundus.Data.Superlayers.Mobs; using Mundus.Service.Tiles.Mobs; using Mundus.Service.Tiles.Items; using Mundus.Service.Tiles.Items.Presets; +using Mundus.Data; namespace Mundus.Service.Tiles.Crafting { public static class CraftingController { @@ -13,7 +14,7 @@ namespace Mundus.Service.Tiles.Crafting { /// </summary> /// <returns>All avalable recipies.</returns> public static CraftingRecipe[] GetAvalableRecipes() { - return MainClass.CTController.GetAvalableRecipes(); + return DataBaseContext.CTContext.GetAvalableRecipes(); } /// <summary> |
