1 /** 2 Singleton that manages $(D InputEventAction). 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.inputmap; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.inputevent; 23 /** 24 Singleton that manages $(D InputEventAction). 25 26 Manages all $(D InputEventAction) which can be created/modified from the project settings menu `Project > Project Settings > Input Map` or in code with $(D addAction) and $(D actionAddEvent). See $(D Node._input). 27 */ 28 @GodotBaseClass struct InputMapSingleton 29 { 30 enum string _GODOT_internal_name = "InputMap"; 31 public: 32 @nogc nothrow: 33 union { godot_object _godot_object; GodotObject _GODOT_base; } 34 alias _GODOT_base this; 35 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 36 package(godot) __gshared bool _classBindingInitialized = false; 37 package(godot) static struct _classBinding 38 { 39 __gshared: 40 godot_object _singleton; 41 immutable char* _singletonName = "InputMap"; 42 @GodotName("has_action") GodotMethod!(bool, String) hasAction; 43 @GodotName("get_actions") GodotMethod!(Array) getActions; 44 @GodotName("add_action") GodotMethod!(void, String, double) addAction; 45 @GodotName("erase_action") GodotMethod!(void, String) eraseAction; 46 @GodotName("action_set_deadzone") GodotMethod!(void, String, double) actionSetDeadzone; 47 @GodotName("action_add_event") GodotMethod!(void, String, InputEvent) actionAddEvent; 48 @GodotName("action_has_event") GodotMethod!(bool, String, InputEvent) actionHasEvent; 49 @GodotName("action_erase_event") GodotMethod!(void, String, InputEvent) actionEraseEvent; 50 @GodotName("action_erase_events") GodotMethod!(void, String) actionEraseEvents; 51 @GodotName("get_action_list") GodotMethod!(Array, String) getActionList; 52 @GodotName("event_is_action") GodotMethod!(bool, InputEvent, String) eventIsAction; 53 @GodotName("load_from_globals") GodotMethod!(void) loadFromGlobals; 54 } 55 bool opEquals(in InputMapSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; } 56 InputMapSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 57 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 58 mixin baseCasts; 59 static InputMapSingleton _new() 60 { 61 static godot_class_constructor constructor; 62 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InputMap"); 63 if(constructor is null) return typeof(this).init; 64 return cast(InputMapSingleton)(constructor()); 65 } 66 @disable new(size_t s); 67 /** 68 Returns `true` if the `InputMap` has a registered action with the given name. 69 */ 70 bool hasAction(StringArg0)(in StringArg0 action) const 71 { 72 checkClassBinding!(typeof(this))(); 73 return ptrcall!(bool)(_classBinding.hasAction, _godot_object, action); 74 } 75 /** 76 Returns an array of all actions in the `InputMap`. 77 */ 78 Array getActions() 79 { 80 checkClassBinding!(typeof(this))(); 81 return ptrcall!(Array)(_classBinding.getActions, _godot_object); 82 } 83 /** 84 Adds an empty action to the `InputMap` with a configurable `deadzone`. 85 An $(D InputEvent) can then be added to this action with $(D actionAddEvent). 86 */ 87 void addAction(StringArg0)(in StringArg0 action, in double deadzone = 0.5) 88 { 89 checkClassBinding!(typeof(this))(); 90 ptrcall!(void)(_classBinding.addAction, _godot_object, action, deadzone); 91 } 92 /** 93 Removes an action from the `InputMap`. 94 */ 95 void eraseAction(StringArg0)(in StringArg0 action) 96 { 97 checkClassBinding!(typeof(this))(); 98 ptrcall!(void)(_classBinding.eraseAction, _godot_object, action); 99 } 100 /** 101 102 */ 103 void actionSetDeadzone(StringArg0)(in StringArg0 action, in double deadzone) 104 { 105 checkClassBinding!(typeof(this))(); 106 ptrcall!(void)(_classBinding.actionSetDeadzone, _godot_object, action, deadzone); 107 } 108 /** 109 Adds an $(D InputEvent) to an action. This $(D InputEvent) will trigger the action. 110 */ 111 void actionAddEvent(StringArg0)(in StringArg0 action, InputEvent event) 112 { 113 checkClassBinding!(typeof(this))(); 114 ptrcall!(void)(_classBinding.actionAddEvent, _godot_object, action, event); 115 } 116 /** 117 Returns `true` if the action has the given $(D InputEvent) associated with it. 118 */ 119 bool actionHasEvent(StringArg0)(in StringArg0 action, InputEvent event) 120 { 121 checkClassBinding!(typeof(this))(); 122 return ptrcall!(bool)(_classBinding.actionHasEvent, _godot_object, action, event); 123 } 124 /** 125 Removes an $(D InputEvent) from an action. 126 */ 127 void actionEraseEvent(StringArg0)(in StringArg0 action, InputEvent event) 128 { 129 checkClassBinding!(typeof(this))(); 130 ptrcall!(void)(_classBinding.actionEraseEvent, _godot_object, action, event); 131 } 132 /** 133 Removes all events from an action. 134 */ 135 void actionEraseEvents(StringArg0)(in StringArg0 action) 136 { 137 checkClassBinding!(typeof(this))(); 138 ptrcall!(void)(_classBinding.actionEraseEvents, _godot_object, action); 139 } 140 /** 141 Returns an array of $(D InputEvent)s associated with a given action. 142 */ 143 Array getActionList(StringArg0)(in StringArg0 action) 144 { 145 checkClassBinding!(typeof(this))(); 146 return ptrcall!(Array)(_classBinding.getActionList, _godot_object, action); 147 } 148 /** 149 Returns $(D true) if the given event is part of an existing action. This method ignores keyboard modifiers if the given $(D InputEvent) is not pressed (for proper release detection). See $(D actionHasEvent) if you don't want this behavior. 150 */ 151 bool eventIsAction(StringArg1)(InputEvent event, in StringArg1 action) const 152 { 153 checkClassBinding!(typeof(this))(); 154 return ptrcall!(bool)(_classBinding.eventIsAction, _godot_object, event, action); 155 } 156 /** 157 Clears all $(D InputEventAction) in the `InputMap` and load it anew from $(D ProjectSettings). 158 */ 159 void loadFromGlobals() 160 { 161 checkClassBinding!(typeof(this))(); 162 ptrcall!(void)(_classBinding.loadFromGlobals, _godot_object); 163 } 164 } 165 /// Returns: the InputMapSingleton 166 @property @nogc nothrow pragma(inline, true) 167 InputMapSingleton InputMap() 168 { 169 checkClassBinding!InputMapSingleton(); 170 return InputMapSingleton(InputMapSingleton._classBinding._singleton); 171 }