Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.76 KB | None | 0 0
  1. // DroneController.hx
  2. if(mause.started()){
  3. x = pickClosest(mause)
  4. if(x.distanceIsOk && x.hasTrait("Pickable")){ // not to far
  5.     x.getTrait(Pickable).pick();
  6. }
  7. }
  8.  
  9. // Pickable.hx - add to all buttons, set values - 1,2,3.. clear, back
  10. class Pickable {
  11.   @prop
  12.   public var value: string / dynamic? = null;
  13.   public var callback: Void->Void = null; // Or use events, but they suck?
  14.  
  15.   fn pick(){
  16.    if(value && callback) callback(value);
  17.   }
  18. }
  19.  
  20. // DoorController.hx
  21.  
  22. ....
  23.  
  24. onInit(){
  25.   for(x in allButtons){
  26.    y = x.getTrait(Pickable);
  27.    // can also set value here y.value = 'xxxx';
  28.    y.callback = function(value: string){
  29.       this.registerButtonPress(value);
  30.    }
  31.   }
  32. }
  33.  
  34. registerButtonPress(value){
  35.   switch value {
  36.     // Do shit
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement