diff options
| author | Amir Rajan <[email protected]> | 2020-05-03 20:32:11 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-05-03 20:32:11 -0500 |
| commit | ac6a6d33c4131f649957fcbd01ad4aec2f43455f (patch) | |
| tree | 73c29d80eb2e73ba12f09ef563f409624e84a74d /dragon/keys.rb | |
| parent | a3ba88253fe6140abc8c069898b7c2762dbf79ef (diff) | |
| download | dragonruby-game-toolkit-contrib-ac6a6d33c4131f649957fcbd01ad4aec2f43455f.tar.gz dragonruby-game-toolkit-contrib-ac6a6d33c4131f649957fcbd01ad4aec2f43455f.zip | |
Synced with v1.8
Diffstat (limited to 'dragon/keys.rb')
| -rw-r--r-- | dragon/keys.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/dragon/keys.rb b/dragon/keys.rb new file mode 100644 index 0000000..9f41fa2 --- /dev/null +++ b/dragon/keys.rb @@ -0,0 +1,51 @@ +# coding: utf-8 +# Copyright 2019 DragonRuby LLC +# MIT License +# controller/keys.rb has been released under MIT (*only this file*). + +module GTK + class Controller + class Keys + include Serialize + + LABELS = [ + :up, :down, :left, :right, + :a, :b, :x, :y, + :l1, :r1, + :l2, :r2, + :l3, :r3, + :start, :select, + :directional_up, :directional_down, :directional_left, :directional_right + ].freeze + + LABELS.each do |label| + attr_reader label + end + + # Activate a key. + # + # @return [void] + def activate key + instance_variable_set("@#{key}", Kernel.tick_count + 1) + end + + # Deactivate a key. + # + # @return [void] + def deactivate key + instance_variable_set("@#{key}", nil) + end + + # Clear all key inputs. + # + # @return [void] + def clear + LABELS.each { |label| deactivate(label) } + end + + def truthy_keys + LABELS.select { |label| send(label) } + end + end + end +end |
