Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. public class SceneLoader : Node
  2. {
  3.     static SceneLoader _instance;
  4.     WeakRef currentScene;
  5.     ResourceInteractiveLoader loader;
  6.     float waitFrames;
  7.     int timeMax = 100;
  8.     float progress = 0;
  9.     bool artificialSlowDown = false;
  10.     int artificialSlowDownFrames = 60;
  11.     int artificialSlowDownCurrent = 60;
  12.     bool done = false;
  13.  
  14.     // This is quite a long Enum if I do say so myself.
  15.     enum error
  16.     {
  17.     OK = 0,
  18.     FAILED,
  19.     ERR_UNAVAILABLE,
  20.     ERR_UNCONFIGURED,
  21.     ERR_UNAUTHORIZED,
  22.     ERR_PARAMETER_RANGE_ERROR,
  23.     ERR_OUT_OF_MEMORY,
  24.     ERR_FILE_NOT_FOUND,
  25.     ERR_FILE_BAD_DRIVE,
  26.     ERR_FILE_BAD_PATH,
  27.     ERR_FILE_NO_PERMISSION,
  28.     ERR_FILE_ALREADY_IN_USE,
  29.     ERR_FILE_CANT_OPEN,
  30.     ERR_FILE_CANT_WRITE,
  31.     ERR_FILE_CANT_READ,
  32.     ERR_FILE_UNRECOGNIZED,
  33.     ERR_FILE_CORRUPT,
  34.     ERR_FILE_MISSING_DEPENDENCIES,
  35.     ERR_FILE_EOF,
  36.     ERR_CANT_OPEN,
  37.     ERR_CANT_CREATE,
  38.     ERR_PARSE_ERROR = 43,
  39.     ERROR_QUERY_FAILED = 21,
  40.     ERR_ALREADY_IN_USE,
  41.     ERR_LOCKED,
  42.     ERR_TIMEOUT,
  43.     ERR_CANT_AQUIRE_RESOURCE = 28,
  44.     ERR_INVALID_DATA = 30,
  45.     ERR_INVALID_PARAMETER,
  46.     ERR_ALREADY_EXISTS,
  47.     ERR_DOES_NOT_EXIST,
  48.     ERR_DATABASE_CANT_READ,
  49.     ERR_DATABASE_CANT_WRITE,
  50.     ERR_COMPILATION_FAILED,
  51.     ERR_METHOD_NOT_FOUND,
  52.     ERR_LINK_FAILED,
  53.     ERR_SCRIPT_FAILED,
  54.     ERR_CYCLIC_LINK,
  55.     ERR_BUSY = 44,
  56.     ERR_HELP = 46,
  57.     ERR_BUG,
  58.     ERR_WTF = 49
  59.     }
  60.  
  61.     public static SceneLoader Instance
  62.     {
  63.         get
  64.         {
  65.             return _instance;
  66.         }
  67.     }
  68.  
  69.     public WeakRef CurrentScene { get => currentScene; set => currentScene = value; }
  70.  
  71.     public override void _Init()
  72.     {
  73.         AddUserSignal("DONE");
  74.         AddUserSignal("ERROR");
  75.         AddUserSignal("PROGRESS");
  76.         AddUserSignal("START");
  77.         AddUserSignal("TRANSITION");
  78.     }
  79.  
  80.     public override void _EnterTree()
  81.     {
  82.         _instance = this;
  83.         // Godot.GD.Print("You should be able to use this SceneLoader now.");
  84.     }
  85.  
  86.     public override void _ExitTree()
  87.     {
  88.         _instance = null;
  89.     }
  90.  
  91.     // public void DummyMethod()
  92.     // {
  93.     //     Godot.GD.Print("I am a dummy method");
  94.     //     Console.WriteLine("I am supposed to be under the other dummy.");
  95.     // }
  96.  
  97.     public override void _Process(float delta)
  98.     {
  99.         /* Called every frame. Delta is time since last frame.
  100.            Update game logic here. */
  101.  
  102.     }
  103.  
  104.     public void SlowDown(int frames = 60)
  105.     {
  106.         artificialSlowDown = true;
  107.         artificialSlowDownCurrent = frames;
  108.         artificialSlowDownFrames = 60;
  109.     }
  110.  
  111.     public void FreeCurrentScene()
  112.     {
  113.  
  114.     }
  115.  
  116.     public void LoadScene(string path, bool withTransition = true)
  117.     {
  118.  
  119.     }
  120.  
  121.     public void UpdateProgress()
  122.     {
  123.  
  124.     }
  125.  
  126.     public float GetProgress()
  127.     {
  128.         return progress;
  129.     }
  130.  
  131.     public int GetStage()
  132.     {
  133.         return loader.GetStageCount();
  134.     }
  135.  
  136.     public int GetStageCount()
  137.     {
  138.         return loader.GetStageCount();
  139.     }
  140.  
  141.     public void SetNewScene(PackedScene sceneResource)
  142.     {
  143.         Node sceneInstance = sceneResource.Instance();
  144.  
  145.         currentScene = Godot.GD.Weakref(sceneInstance);
  146.         done = true;
  147.         UpdateProgress();
  148.         EmitSignal("DONE", sceneInstance);
  149.         EmitSignal("TRANSITION", 0);
  150.     }
  151.  
  152.     public bool Poll()
  153.     {
  154.         return false;
  155.     }
  156.  
  157.     public void OnTransitionDone()
  158.     {
  159.  
  160.     }
  161.  
  162.     public void ShowError(int err)
  163.     {
  164.  
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement