Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Timers;
- using UnityEngine;
- namespace Pluton
- {
- public class BlockData
- {
- private static Pluton.BlockData blockData;
- public DataStore blockDataStore;
- public static Timer saveStoreTimer;
- public BlockData()
- {
- saveStoreTimer = new Timer(60000);
- saveStoreTimer.Start();
- }
- private void saveStoreTimer_Elapsed(object sender, ElapsedEventArgs e)
- {
- try {
- blockDataStore.Save();
- Logger.LogDebug("[BlockData] Block DataStore saved successfully!");
- } catch (Exception ex) {
- Logger.LogDebug("[BlockData] Failed to save the Block DataStore!");
- Logger.LogException(ex);
- }
- }
- public static Pluton.BlockData GetBlockData()
- {
- if (blockData == null) {
- blockData = new Pluton.BlockData();
- blockData.blockDataStore = new DataStore("BlockData.ds");
- blockData.blockDataStore.Load();
- }
- return blockData;
- }
- public void AddBlock(BuildingPart bp, Player player)
- {
- blockDataStore.Add("blocks", this.GetPosRotKey(bp), player.GameID);
- }
- public void RemoveBlock(BuildingPart bp)
- {
- blockDataStore.Remove("blocks", this.GetPosRotKey(bp));
- }
- public ulong GetBlockOwnerID(BuildingPart bp)
- {
- if (blockDataStore.ContainsKey("blocks", this.GetPosRotKey(bp)))
- return (ulong)blockDataStore.Get("blocks", this.GetPosRotKey(bp));
- return 0;
- }
- public String GetPosRotKey(BuildingPart bp)
- {
- // our key to easily find blocks by location:rotation "x:y:z|w:x:y:z"
- return bp.X.ToString() + ":" + bp.Y.ToString() + ":" + bp.Z.ToString() + "|" + bp.buildingBlock.transform.rotation.w + ":" + bp.buildingBlock.transform.rotation.x + ":" + bp.buildingBlock.transform.rotation.y + ":" + bp.buildingBlock.transform.rotation.z;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement