1.0.0 commit
This commit is contained in:
50
Common/Systems/ModPlayerOnEnterWorld.cs
Normal file
50
Common/Systems/ModPlayerOnEnterWorld.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria.ID;
|
||||
using Terraria.Localization;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using Terraria.Map;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace tTP.Common.Systems
|
||||
{
|
||||
internal class ModPlayerOnEnterWorld
|
||||
{
|
||||
public class ModPlayerOnEnterWorldPlayer : ModPlayer
|
||||
{
|
||||
public override void OnEnterWorld()
|
||||
{
|
||||
if (!Directory.Exists("tTP")) { Directory.CreateDirectory("tTP"); }
|
||||
tTP.worldName = Main.worldName;
|
||||
|
||||
if (!File.Exists($"tTP/{tTP.worldName}.json"))
|
||||
{
|
||||
string prepjson = @"{ ""tp"": " + '[' + ']' + " }";
|
||||
File.WriteAllText($"tTP/{tTP.worldName}.json", prepjson);
|
||||
}
|
||||
|
||||
string json = File.ReadAllText($"tTP/{tTP.worldName}.json");
|
||||
dynamic jo = JsonConvert.DeserializeObject(json);
|
||||
JArray jar = jo["tp"];
|
||||
if (jar.Count == 0)
|
||||
{
|
||||
tTP.table.Columns.Add("name", typeof(String));
|
||||
tTP.table.Columns.Add("x", typeof(Int64));
|
||||
tTP.table.Columns.Add("y", typeof(Int64));
|
||||
} else
|
||||
{
|
||||
DataSet ds = JsonConvert.DeserializeObject<DataSet>(File.ReadAllText($"tTP/{tTP.worldName}.json"));
|
||||
tTP.table = ds.Tables["tp"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user