Refactor debug checks to use event bus settings for consistency across game components.

This commit is contained in:
2026-03-28 23:24:09 +00:00
parent 1fbd12e6f6
commit 3dbeadf976
9 changed files with 30 additions and 13 deletions
+2 -2
View File
@@ -114,7 +114,7 @@ class Character
end
# teleport to boss room for debug purposes
if DEBUG && Gosu.button_down?(Gosu::KB_T)
if $bus.get(:settings, :debug) && Gosu.button_down?(Gosu::KB_T)
room_coords = $bus.get(:boss_room_coords)
if room_coords
@world_x, @world_y = [room_coords[0] * 60 + 5, room_coords[1] * 60 + 5]
@@ -138,7 +138,7 @@ class Character
frame_index = ((elapsed * 7).floor) % 6
@animations[@current_animation][frame_index].draw(sprite_x, sprite_y, sprite_y + 30, 1.8, 1.8)
return unless DEBUG
return unless $bus.get(:settings, :debug)
Gosu.draw_rect(cx, cy, SIZE[0], SIZE[1], Gosu::Color.new(0x8000FF00), cy)
end
+1 -1
View File
@@ -76,7 +76,7 @@ class EnemyAI
end
def draw
return unless DEBUG
return unless $bus.get(:settings, :debug)
cam_x, cam_y = $bus.get(:camera_pos) || [0, 0]
@waypoints.each do |wx, wy|
Gosu.draw_rect(wx - cam_x - 5, wy - cam_y - 5, 10, 10, Gosu::Color.new(0x88ffff00), Float::INFINITY)
+1 -1
View File
@@ -130,7 +130,7 @@ class Inventory
if id == Gosu::MS_LEFT
@inventory_selected = type
elsif id == Gosu::MS_RIGHT
if DEBUG && [:wood, :metal, :science].include?(type)
if $bus.get(:settings, :debug) && [:wood, :metal, :science].include?(type)
@grid[row_idx][col_idx][1][0] = max
else
craft(type, ctrl: Gosu.button_down?(Gosu::KB_RIGHT_CONTROL) || Gosu.button_down?(Gosu::KB_LEFT_CONTROL))
+1 -1
View File
@@ -103,7 +103,7 @@ class Maze
@spritesheet[index - 1].draw(screen_x, screen_y, screen_y, scale, scale)
next unless DEBUG
next unless $bus.get(:settings, :debug)
shapes = shapes_for(index, gx * tile_size, gy * tile_size)
shapes.each do |shape|
+1 -1
View File
@@ -100,7 +100,7 @@ class Prop
Gosu.draw_rect(bar_x, bar_y, bar_width, bar_height, Gosu::Color::RED, screen_y - 19)
end
return unless DEBUG
return unless $bus.get(:settings, :debug)
# collision box centered on same point
Gosu.draw_rect(screen_x - SIZE[0] / 2, screen_y - SIZE[1], *SIZE, Gosu::Color.new(0x88ff0000), Float::INFINITY)
+2 -2
View File
@@ -38,8 +38,8 @@ class Game < Scene
@enemies.draw
@props.draw
@hud.draw
draw_fog!
draw_debug! if DEBUG
draw_fog! if $bus.get(:settings, :fog)
draw_debug! if $bus.get(:settings, :debug)
end
def draw_debug!
+3 -3
View File
@@ -1,15 +1,15 @@
require 'gosu'
require_relative 'settings/configuration'
require_relative 'utils/bus'
$bus = EventBus.new
require_relative 'settings/configuration'
require_relative 'utils/utils'
require_relative 'utils/scene'
require_relative 'settings/scene'
require_relative 'menu/scene'
require_relative 'game/scene'
$bus = EventBus.new
# Main window
class Window < Gosu::Window
def initialize
+18 -1
View File
@@ -3,4 +3,21 @@
SCREEN_SIZE = [720, 480].freeze
N, S, W, E = 1, 2, 4, 8
DEBUG = ARGV.include?("--debug")
# Config module to hold global settings that can be toggled in the settings scene, and accessed anywhere else in the code via the event bus
module Config
@config = {
debug: ARGV.include?("--debug"),
fog: true,
torches_lightup: false
}
$bus.on(:settings) do |k|
next @config[k]
end
module_function
def toggle(key)
@config[key] = !@config[key]
end
end
+1 -1
View File
@@ -26,7 +26,7 @@ class MazeData
end
end
return unless DEBUG
return unless $bus.get(:settings, :debug)
print_debug
$bus.on(:boss_room_coords) do