added JSON dict reading; working on JSON writing

This commit is contained in:
Pecha 2020-09-09 19:56:39 +10:00
parent 570560a202
commit 6cdec74132
17 changed files with 164 additions and 37 deletions

View file

@ -1,11 +1,14 @@
using System; using System;
using Newtonsoft.Json;
namespace creachopedia { namespace creachopedia {
class Creacher { class Creacher {
public string name {get; set;} public string name {get; set;}
// public int kingdom; // public int kingdom;
// public string description; // public string description;
private int _footsies; [JsonProperty]
private int _footsies { get; set; }
[JsonIgnore]
public int footsies {get { return this._footsies; } set { Console.WriteLine("What do you think you're doing?! 0uo Leave those footsies alone!!!"); }} public int footsies {get { return this._footsies; } set { Console.WriteLine("What do you think you're doing?! 0uo Leave those footsies alone!!!"); }}
public string type = "simple creacher"; public string type = "simple creacher";
@ -19,7 +22,7 @@ namespace creachopedia {
} }
public void Step(){ public void Step(){
if(this.footsies == 0){ if(this.footsies == 0){
Console.WriteLine("I cannot stip or step! I have 0 footsies!!!!"); Console.WriteLine("I cannot stip or step! I have 0 footsies! I am however quite powerful in my own way 0u0");
Console.WriteLine("Silly creacher..."); Console.WriteLine("Silly creacher...");
} else { } else {
Console.WriteLine($"The {this.name} steps, and rather well I might add."); Console.WriteLine($"The {this.name} steps, and rather well I might add.");

View file

@ -1,34 +1,61 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using Newtonsoft.Json;
using System.IO;
namespace creachopedia { namespace creachopedia {
class Program { class Program {
static void Main(string[] args) { static void Main(string[] args) {
var creacherdict = new Dictionary<string, Creacher>(); var creacherdict = JsonConvert.DeserializeObject<Dictionary<string, Creacher>>(File.ReadAllText("creachopedia.json"));
// creacherdict.Add("paca", new GroundCreacher("paca", 4));
// creacherdict.Add("llama", new GroundCreacher("llama", 4));
// creacherdict.Add("stingray", new WaterCreacher("stingray", 0));
// var jsonsettings = new JsonSerializerSettings{
// TypeNameHandling = TypeNameHandling.Auto
// };
// string jsonstring = JsonConvert.SerializeObject(creacherdict, Formatting.Indented, jsonsettings);
// File.WriteAllText("creachopedia.json", jsonstring);
creacherdict.Add("paca", new GroundCreacher("paca", 4));
creacherdict.Add("llama", new GroundCreacher("llama", 4));
creacherdict.Add("stingray", new WaterCreacher("stingray", 0));
while (true) { while (true) {
var status = "base";
Console.WriteLine("Please input a creacher name, or (q) to quit 0u0"); Console.WriteLine("Please input a creacher name, or (q) to quit 0u0");
string userin = Console.ReadLine(); string userin = Console.ReadLine();
string luserin = userin.ToLower();
if(userin == "q"){
Console.WriteLine("Thank you for using the CreachoPedia, please come again!!!!");
status = "quit";
}
if (status == "base"){
if (creacherdict.ContainsKey(userin)) { if (creacherdict.ContainsKey(userin)) {
creacherdict[userin].Introduce(); creacherdict[userin].Introduce();
creacherdict[userin].Step(); creacherdict[userin].Step();
creacherdict[userin].footsies = 2;
} }
else if(userin == "q"){ else if(luserin == "heenlo!" || luserin == "henlo" || luserin == "heenlo" || luserin == "henlo!"){
Console.WriteLine("Thank you for using the CreachoPedia!!!!");
return;
}
else if(userin == "heenlo!" || userin == "henlo" || userin == "heenlo"){
Console.WriteLine("Well heenlo to you too! 0u0"); Console.WriteLine("Well heenlo to you too! 0u0");
} }
else if(userin == "*pats*"){
Console.WriteLine("Oh! Thank you!");
}
else if(userin == "a"){
Console.WriteLine("Please enter a new creacher! Or type (b) for previous category, or (q) to cancel addition entirely.");
status = "add";
}
}
else if (status == "add") {
} else if (status == "quit") {
return;
}
else { else {
Console.WriteLine("I don't know what that is! What on boo Earth?!!?!?!?"); Console.WriteLine($"I don't know what {userin} is! What on boo Earth?!!?!?!?");
} }
Console.WriteLine(""); Console.WriteLine("");
Thread.Sleep(1000); Thread.Sleep(1000);

Binary file not shown.

View file

@ -7,9 +7,20 @@
"targets": { "targets": {
".NETCoreApp,Version=v3.1": { ".NETCoreApp,Version=v3.1": {
"creachopedia/1.0.0": { "creachopedia/1.0.0": {
"dependencies": {
"Newtonsoft.Json": "12.0.3"
},
"runtime": { "runtime": {
"creachopedia.dll": {} "creachopedia.dll": {}
} }
},
"Newtonsoft.Json/12.0.3": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "12.0.0.0",
"fileVersion": "12.0.3.23909"
}
}
} }
} }
}, },
@ -18,6 +29,13 @@
"type": "project", "type": "project",
"serviceable": false, "serviceable": false,
"sha512": "" "sha512": ""
},
"Newtonsoft.Json/12.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"path": "newtonsoft.json/12.0.3",
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
} }
} }
} }

View file

@ -5,4 +5,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project> </Project>

View file

@ -1,3 +1,20 @@
{ {
"paca": {
"$type": "creachopedia.GroundCreacher, creachopedia",
"type": "creacher of the land",
"name": "paca",
"_footsies": 4
},
"llama": {
"$type": "creachopedia.GroundCreacher, creachopedia",
"type": "creacher of the land",
"name": "llama",
"_footsies": 4
},
"stingray": {
"$type": "creachopedia.WaterCreacher, creachopedia",
"type": "creacher of the water",
"name": "stingray",
"_footsies": 0
}
} }

View file

@ -9,3 +9,5 @@
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.AssemblyInfo.cs /home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.AssemblyInfo.cs
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.dll /home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.dll
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.pdb /home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.pdb
/home/petra/Documents/Code/C#/creachopedia/bin/Debug/netcoreapp3.1/Newtonsoft.Json.dll
/home/petra/Documents/Code/C#/creachopedia/obj/Debug/netcoreapp3.1/creachopedia.csproj.CopyComplete

View file

@ -1,5 +1,5 @@
{ {
"version": 1, "version": 1,
"dgSpecHash": "viHAytpAeRg2rkbruTDcJ80nPro+N0eKDnZUSYFqFnBGsO01NYPadOgHvE4Ch/dYKOVhrBHUt+HiRD1b/WDXmQ==", "dgSpecHash": "JCtwJT93h17o7iSWXfYXu/UDvwAFtE0LJP/QdZxWN5h/fsMhZ5JJzGNmdfs2YFbkbtCv3zTB0K/E3q4+9ORe1g==",
"success": true "success": true
} }

View file

@ -35,6 +35,12 @@
}, },
"frameworks": { "frameworks": {
"netcoreapp3.1": { "netcoreapp3.1": {
"dependencies": {
"Newtonsoft.Json": {
"target": "Package",
"version": "[12.0.3, )"
}
},
"imports": [ "imports": [
"net461", "net461",
"net462", "net462",

View file

@ -1,11 +1,55 @@
{ {
"version": 3, "version": 3,
"targets": { "targets": {
".NETCoreApp,Version=v3.1": {} ".NETCoreApp,Version=v3.1": {
"Newtonsoft.Json/12.0.3": {
"type": "package",
"compile": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {}
},
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {}
}
}
}
},
"libraries": {
"Newtonsoft.Json/12.0.3": {
"sha512": "6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"type": "package",
"path": "newtonsoft.json/12.0.3",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/netstandard1.0/Newtonsoft.Json.dll",
"lib/netstandard1.0/Newtonsoft.Json.xml",
"lib/netstandard1.3/Newtonsoft.Json.dll",
"lib/netstandard1.3/Newtonsoft.Json.xml",
"lib/netstandard2.0/Newtonsoft.Json.dll",
"lib/netstandard2.0/Newtonsoft.Json.xml",
"lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll",
"lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.xml",
"lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll",
"lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.xml",
"newtonsoft.json.12.0.3.nupkg.sha512",
"newtonsoft.json.nuspec",
"packageIcon.png"
]
}
}, },
"libraries": {},
"projectFileDependencyGroups": { "projectFileDependencyGroups": {
".NETCoreApp,Version=v3.1": [] ".NETCoreApp,Version=v3.1": [
"Newtonsoft.Json >= 12.0.3"
]
}, },
"packageFolders": { "packageFolders": {
"/home/petra/.nuget/packages/": {} "/home/petra/.nuget/packages/": {}
@ -41,6 +85,12 @@
}, },
"frameworks": { "frameworks": {
"netcoreapp3.1": { "netcoreapp3.1": {
"dependencies": {
"Newtonsoft.Json": {
"target": "Package",
"version": "[12.0.3, )"
}
},
"imports": [ "imports": [
"net461", "net461",
"net462", "net462",