Skip to content

Commit

Permalink
feat: adds two debug text methods
Browse files Browse the repository at this point in the history
Added debug_text_world and debug_text_screen. Api::Point[,,] syntax was fixed along the way.
In debugging object, elevated drawn boxes by an additional 0.01 to prevent clipping.

fix: debug_draw_box elevation even higher to prevent floor clipping
fix: Api::Point[x,y,z] new shorthand fixed.
  • Loading branch information
dysonreturns committed Mar 6, 2024
1 parent 9de02d6 commit 9285534
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
50 changes: 48 additions & 2 deletions lib/sc2ai/player/debug.rb
Expand Up @@ -37,6 +37,52 @@ def debug_print(text, size: 14)
)
end

# Prints text on screen from top and left
# @param text [String] will respect newlines
# @param left_percent [Numeric] range 0..100. percent from left of screen
# @param top_percent [Numeric] range 0..100. percent from top of screen
# @param color [Api::Color] default white
# @param size [Size] of font, default 14px
# @return [void]
def debug_text_screen(text, left_percent: 1.0, top_percent: 1.0, color: nil, size: 14)
queue_debug_command Api::DebugCommand.new(
draw: Api::DebugDraw.new(
text: [
Api::DebugText.new(
text:,
virtual_pos: Api::Point.new(
x: left_percent.to_f / 100,
y: top_percent.to_f / 100
),
color:,
size:
)
]
)
)
end

# Prints text on screen at 3d world position
# @param text [String] will respect newlines
# @param point [Api::Point] point in the world, i.e. unit.pos
# @param color [Api::Color] default white
# @param size [Size] of font, default 14px
# @return [void]
def debug_text_world(text, point:, color: nil, size: 14)
queue_debug_command Api::DebugCommand.new(
draw: Api::DebugDraw.new(
text: [
Api::DebugText.new(
text:,
world_pos: point,
color:,
size:
)
]
)
)
end

# Draws a line between two Api::Point's for color
# @param p0 [Api::Point] the first point
# @param p1 [Api::Point] the second point
Expand Down Expand Up @@ -74,8 +120,8 @@ def debug_draw_box(point:, radius: 0.5, color: nil)
draw: Api::DebugDraw.new(
boxes: [
Api::DebugBox.new(
min: Api::Point.new(x: point.x - radius, y: point.y - radius, z: point.z + 0.01),
max: Api::Point.new(x: point.x + radius, y: point.y + radius, z: point.z + (radius * 2) + 0.01),
min: Api::Point.new(x: point.x - radius, y: point.y - radius, z: point.z + 0.02),
max: Api::Point.new(x: point.x + radius, y: point.y + radius, z: point.z + (radius * 2) + 0.02),
color:
)
]
Expand Down
2 changes: 1 addition & 1 deletion lib/sc2ai/protocol/extensions/point.rb
Expand Up @@ -23,4 +23,4 @@ def [](x, y, z)
end
end
Api::Point.include Api::PointExtension
Api::Point.include Api::PointExtension::ClassMethods
Api::Point.extend Api::PointExtension::ClassMethods
22 changes: 12 additions & 10 deletions sig/sc2ai.rbs
Expand Up @@ -613,22 +613,23 @@ module Sc2
def debug_print: (String text, ?size: Size) -> void

# sord warn - Size wasn't able to be resolved to a constant in this project
# sord omit - no YARD type given for "color:", using untyped
# Prints text on screen from top and left
#
# _@param_ `text` — will respect newlines
#
# _@param_ `size` — of font, default 14px
#
# _@param_ `left_percent` — range 0..100. percent from left of screen
#
# _@param_ `top_percent` — range 0..100. percent from top of screen
#
# _@param_ `color` — default white
#
# _@param_ `size` — of font, default 14px
def debug_text_screen: (
String text,
?left_percent: Numeric,
?top_percent: Numeric,
?size: Size,
?color: untyped
?color: Api::Color?,
?size: Size
) -> void

# sord warn - Size wasn't able to be resolved to a constant in this project
Expand Down Expand Up @@ -1204,22 +1205,23 @@ module Sc2
def debug_print: (String text, ?size: Size) -> void

# sord warn - Size wasn't able to be resolved to a constant in this project
# sord omit - no YARD type given for "color:", using untyped
# Prints text on screen from top and left
#
# _@param_ `text` — will respect newlines
#
# _@param_ `size` — of font, default 14px
#
# _@param_ `left_percent` — range 0..100. percent from left of screen
#
# _@param_ `top_percent` — range 0..100. percent from top of screen
#
# _@param_ `color` — default white
#
# _@param_ `size` — of font, default 14px
def debug_text_screen: (
String text,
?left_percent: Numeric,
?top_percent: Numeric,
?size: Size,
?color: untyped
?color: Api::Color?,
?size: Size
) -> void

# sord warn - Size wasn't able to be resolved to a constant in this project
Expand Down

0 comments on commit 9285534

Please sign in to comment.