Skip to content

Commit b210a29

Browse files
Initial commit
0 parents  commit b210a29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+134
-0
lines changed

Diff for: .gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Game Dev With Michael
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: mygame/lib/buttons.rb

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
# Gets controller button input icons
4+
class ControllerButtons
5+
attr_gtk
6+
7+
BUTTONS = {
8+
bottom_button: ->(controller, color) { "sprites/buttons/#{controller}_bottom_button#{'_color' if color}.png" },
9+
top_button: ->(controller, color) { "sprites/buttons/#{controller}_top_button#{'_color' if color}.png" },
10+
left_button: ->(controller, color) { "sprites/buttons/#{controller}_left_button#{'_color' if color}.png" },
11+
right_button: ->(controller, color) { "sprites/buttons/#{controller}_right_button#{'_color' if color}.png" },
12+
left_trigger: ->(controller, color) { "sprites/buttons/#{controller}_left_trigger#{'_color' if color}.png" },
13+
right_trigger: ->(controller, color) { "sprites/buttons/#{controller}_right_trigger#{'_color' if color}.png" },
14+
left_bumper: ->(controller, color) { "sprites/buttons/#{controller}_left_bumper#{'_color' if color}.png" },
15+
right_bumper: ->(controller, color) { "sprites/buttons/#{controller}_right_bumper#{'_color' if color}.png" },
16+
ls: ->(controller, color) { "sprites/buttons/#{controller}_ls#{'_color' if color}.png" },
17+
rs: ->(controller, color) { "sprites/buttons/#{controller}_rs#{'_color' if color}.png" },
18+
up_down: ->(controller, color) { "sprites/buttons/#{controller}_up_down#{'_color' if color}.png" },
19+
left_right: ->(controller, color) { "sprites/buttons/#{controller}_left_right#{'_color' if color}.png" }
20+
}.freeze
21+
22+
attr_accessor :controller_number, :controller_name
23+
24+
def initialize(controller_number: :one)
25+
@controller_number = controller_number
26+
@controller_name = nil
27+
end
28+
29+
# Sets the controller name dynamically based on the controller number
30+
def find_controller_name(args)
31+
method_name = "controller_#{@controller_number}"
32+
33+
raise ArgumentError, "Invalid controller number: #{@controller_number}" unless args.inputs.respond_to?(method_name)
34+
35+
raw_name = args.inputs.send(method_name).name.downcase # Normalize string to lowercase
36+
@controller_name =
37+
if raw_name.include?('xbox')
38+
'xbox'
39+
elsif raw_name.include?('playstation')
40+
'ps'
41+
elsif raw_name.include?('nintendo')
42+
'ns'
43+
elsif raw_name.include?('steam')
44+
'steamdeck'
45+
else
46+
'unknown' # Default value if no match
47+
end
48+
end
49+
50+
# Gets the button icon path for the given button and current controller
51+
def button_icon(button = :bottom_button, color: true)
52+
raise 'Controller name not set. Call `set_controller_name` first.' unless @controller_name
53+
54+
BUTTONS[button.to_sym].call(@controller_name, color)
55+
end
56+
end

Diff for: readme.md

+55

Diff for: sprites/buttons/steamdeck_button_bottom.png

1.24 KB

Diff for: sprites/buttons/steamdeck_button_bottom_color.png

982 Bytes

Diff for: sprites/buttons/steamdeck_button_left.png

1.3 KB

Diff for: sprites/buttons/steamdeck_button_left_color.png

1.01 KB

Diff for: sprites/buttons/steamdeck_button_right.png

1.17 KB

Diff for: sprites/buttons/steamdeck_button_right_color.png

900 Bytes

Diff for: sprites/buttons/steamdeck_button_top.png

1.22 KB

Diff for: sprites/buttons/steamdeck_button_top_color.png

941 Bytes

Diff for: sprites/buttons/xbox_bottom_button_color.png

982 Bytes

Diff for: sprites/buttons/xbox_button_left_color.png

1.01 KB

Diff for: sprites/buttons/xbox_button_menu.png

1.06 KB

Diff for: sprites/buttons/xbox_button_menu_color.png

774 Bytes

Diff for: sprites/buttons/xbox_button_right_color.png

900 Bytes

Diff for: sprites/buttons/xbox_button_share.png

880 Bytes

Diff for: sprites/buttons/xbox_button_share_color.png

658 Bytes

Diff for: sprites/buttons/xbox_button_top_color.png

941 Bytes

Diff for: sprites/buttons/xbox_button_view.png

1.14 KB

Diff for: sprites/buttons/xbox_button_view_color.png

846 Bytes

Diff for: sprites/buttons/xbox_dpad_down.png

416 Bytes

Diff for: sprites/buttons/xbox_dpad_horizontal.png

435 Bytes

Diff for: sprites/buttons/xbox_dpad_left.png

434 Bytes

Diff for: sprites/buttons/xbox_dpad_right.png

427 Bytes

Diff for: sprites/buttons/xbox_dpad_up.png

436 Bytes

Diff for: sprites/buttons/xbox_dpad_vertical.png

422 Bytes

Diff for: sprites/buttons/xbox_guide.png

1.56 KB

Diff for: sprites/buttons/xbox_guide_color.png

1.17 KB

Diff for: sprites/buttons/xbox_lb.png

718 Bytes

Diff for: sprites/buttons/xbox_lb_color.png

589 Bytes

Diff for: sprites/buttons/xbox_ls.png

1.25 KB

Diff for: sprites/buttons/xbox_ls_color.png

971 Bytes

Diff for: sprites/buttons/xbox_lt.png

722 Bytes

Diff for: sprites/buttons/xbox_lt_color.png

533 Bytes

Diff for: sprites/buttons/xbox_rb.png

800 Bytes

Diff for: sprites/buttons/xbox_rb_color.png

684 Bytes

Diff for: sprites/buttons/xbox_rs.png

1.32 KB

Diff for: sprites/buttons/xbox_rs_color.png

1.04 KB

Diff for: sprites/buttons/xbox_rt.png

824 Bytes

Diff for: sprites/buttons/xbox_rt_color.png

673 Bytes

Diff for: sprites/buttons/xbox_stick_l_vertical.png

1.37 KB

Diff for: sprites/buttons/xbox_stick_r_vertical.png

1.43 KB

0 commit comments

Comments
 (0)