Guest User

Untitled

a guest
Oct 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function SyncProperty(syncPath, syncValue) {
  2. hier=syncPath.Split("/"[0]);
  3. level=hier.Length;
  4. if (level==0) return;
  5. prop=hier[level-1];
  6. curPath=stateView;
  7. for (nest=0;(nest+1)<level;++nest) {
  8. dir=hier[nest];
  9. if (!curPath.Contains(dir)) {
  10. curPath[dir]=new Hashtable();
  11. }
  12. //print("dir="+dir);
  13. newPath=curPath[dir];
  14. t=""+typeof(newPath);
  15. //print("type(dir)="+t);
  16. if (t != "System.Collections.Hashtable") {
  17. var msg : String;
  18. msg="The path '"+syncPath+"' descends thru non-descendable data key '"+dir+"' (contains data: "+newPath+").";
  19. throw(msg);
  20. } else {
  21. curPath=newPath;
  22. }
  23. }
  24. if (syncValue!=null) {
  25. curPath[prop]=syncValue;
  26. } else {
  27. if (curPath.Contains(prop)) curPath.Remove(prop);
  28. }
  29. }
  30.  
  31. // Dump state view in JSON format
  32. function StateToString(rootPath : Hashtable) : String {
  33. str="{";
  34. dir=rootPath;
  35. cur=0;
  36. count=dir.Keys.Count;
  37. for (key in dir.Keys) {
  38. delim=",";
  39. if (cur+1>=count) delim="";
  40. obj=dir[key];
  41. objType=""+typeof(obj);
  42. if (objType=="System.Collections.Hashtable") {
  43. str+=key+StateToString(obj)+delim;
  44. } else {
  45. str+=(key+":"+obj+delim);
  46. }
  47. ++cur;
  48. }
  49. str+="}";
  50. return str;
  51. }
  52.  
  53. function StateToString() : String {
  54. return StateToString(stateView);
  55. }
Add Comment
Please, Sign In to add comment