Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Timers;
  3. using UnityEngine;
  4.  
  5. namespace Pluton
  6. {
  7.     public class BlockData
  8.     {
  9.         private static Pluton.BlockData blockData;
  10.         public DataStore blockDataStore;
  11.         public static Timer saveStoreTimer;
  12.  
  13.         public BlockData()
  14.         {
  15.             saveStoreTimer = new Timer(60000);
  16.             saveStoreTimer.Start();
  17.         }
  18.  
  19.         private void saveStoreTimer_Elapsed(object sender, ElapsedEventArgs e)
  20.         {
  21.             try {
  22.                 blockDataStore.Save();
  23.                 Logger.LogDebug("[BlockData] Block DataStore saved successfully!");
  24.             } catch (Exception ex) {
  25.                 Logger.LogDebug("[BlockData] Failed to save the Block DataStore!");
  26.                 Logger.LogException(ex);
  27.             }
  28.         }
  29.  
  30.         public static Pluton.BlockData GetBlockData()
  31.         {
  32.             if (blockData == null) {
  33.                 blockData = new Pluton.BlockData();
  34.                 blockData.blockDataStore = new DataStore("BlockData.ds");
  35.                 blockData.blockDataStore.Load();
  36.             }
  37.             return blockData;
  38.         }
  39.  
  40.         public void AddBlock(BuildingPart bp, Player player)
  41.         {
  42.             blockDataStore.Add("blocks", this.GetPosRotKey(bp), player.GameID);
  43.         }
  44.  
  45.         public void RemoveBlock(BuildingPart bp)
  46.         {
  47.             blockDataStore.Remove("blocks", this.GetPosRotKey(bp));
  48.         }
  49.  
  50.         public ulong GetBlockOwnerID(BuildingPart bp)
  51.         {
  52.             if (blockDataStore.ContainsKey("blocks", this.GetPosRotKey(bp)))
  53.                 return (ulong)blockDataStore.Get("blocks", this.GetPosRotKey(bp));
  54.             return 0;
  55.         }
  56.  
  57.         public String GetPosRotKey(BuildingPart bp)
  58.         {
  59.             // our key to easily find blocks by location:rotation "x:y:z|w:x:y:z"
  60.             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;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement