Skip to content

Commit

Permalink
rubocop and yard
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-MV committed Jul 20, 2024
1 parent 287eabd commit 0c5806a
Show file tree
Hide file tree
Showing 48 changed files with 1,487 additions and 988 deletions.
8 changes: 8 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--title "raylib-cruby"
--readme README.md
--exclude ext
--exclude lib/rubyraylib.rb
--exclude lib/main.rb
--exclude lib/rubyraylib/raymark.rb
--exclude lib/rubyraylib/settings.rb
--exclude lib/rubyraylib/version.rb
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ group :development do
gem "rubocop-thread_safety"
gem "ruby-lsp"
gem "yard"
gem "webrick"
gem "rack"
gem "rackup"
end

group :test do
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ GEM
racc
prism (0.30.0)
racc (1.7.3)
rack (3.1.7)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rainbow (3.1.1)
rake (13.2.1)
rake-compiler (1.2.7)
Expand Down Expand Up @@ -75,6 +79,7 @@ GEM
simplecov_json_formatter (0.1.4)
sorbet-runtime (0.5.11478)
unicode-display_width (2.5.0)
webrick (1.8.1)
yard (0.9.36)

PLATFORMS
Expand All @@ -85,6 +90,8 @@ PLATFORMS

DEPENDENCIES
bundler
rack
rackup
rake
rake-compiler
rspec
Expand All @@ -99,6 +106,7 @@ DEPENDENCIES
ruby-lsp
rubyraylib!
simplecov
webrick
yard

BUNDLED WITH
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ require "fileutils"
RuboCop::RakeTask.new

task :clean_raylib do
FileUtils.rm_rf Dir.glob('third_party/raylib/src/*.o')
FileUtils.rm_rf Dir.glob("third_party/raylib/src/*.o")
end

# Task to compile Raylib
# PLATFORM=PLATFORM_DESKTOP_SDL
# PLATFORM=PLATFORM_DESKTOP_RGFW
# USE_WAYLAND_DISPLAY=TRUE
task :compile_raylib do
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
sh "mingw32-make PLATFORM=PLATFORM_DESKTOP -C third_party/raylib/src"
else
sh "make PLATFORM=PLATFORM_DESKTOP -C third_party/raylib/src"
Expand Down
10 changes: 5 additions & 5 deletions ext/rubyraylib/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ RB_COLOR_SETTER(rb_color_set_blue, b)
// Color/pixel related functions
// RLAPI bool ColorIsEqual(Color col1, Color col2); // Check if two colors are equal
// RLAPI Color Fade(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f
static VALUE rb_color_fade(VALUE self, VALUE alpha_val) {
static VALUE rb_color_fade(VALUE self, VALUE alpha) {
Color *color = get_color(self);
float alpha = NUM2DBL(alpha_val);
float alpha_val = NUM2DBL(alpha);

*color = Fade(*color, alpha);
*color = Fade(*color, alpha_val);

return self;
}
Expand All @@ -37,7 +37,7 @@ static VALUE rb_color_normalize(VALUE self) {

return Data_Wrap_Struct(rb_cVec4, NULL, NULL, &result);
}
// RLAPI Color ColorFromHSV(float hue, float saturation, float value); // Get a Color from HSV values, hue [0..360], saturation/value [0..1]
// RLAPI Vector3 ColorToHSV(Color color); // Get HSV values for a Color, hue [0..360], saturation/value [0..1]
static VALUE rb_color_to_hsv(VALUE self) {
Color *color = get_color(self);

Expand Down Expand Up @@ -130,7 +130,7 @@ static VALUE rb_color_initialize(int argc, VALUE *argv, VALUE self) {
// RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes for certain format

extern "C" void initializeColor() {
rb_cColor = rb_define_class_under(rb_mRl, "Color", rb_cObject);
rb_cColor = rb_define_class_under(rb_mRL, "Color", rb_cObject);
rb_define_alloc_func(rb_cColor, rb_object_alloc<Color>);

rb_define_method(rb_cColor, "initialize", rb_color_initialize, -1);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static VALUE rb_begin_drawing(VALUE self) {

// Initializes the Draw module and defines its functions
extern "C" void initializeDraw(void) {
VALUE rb_cDraw = rb_define_module_under(rb_mRl, "Draw");
VALUE rb_cDraw = rb_define_module_under(rb_mRL, "Draw");

rb_define_module_function(rb_cDraw, "begin", rb_begin_drawing, 0);
rb_define_module_function(rb_cDraw, "clear", rb_clear_background, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/ease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RB_EASE(rb_ease_elastic, EaseElastic)

// Initializes the Ease module and defines its functions
extern "C" void initializeEase() {
VALUE rb_cEase = rb_define_module_under(rb_mRl, "Ease");
VALUE rb_cEase = rb_define_module_under(rb_mRL, "Ease");

rb_define_module_function(rb_cEase, "linear", rb_ease_linear, 5);
rb_define_module_function(rb_cEase, "sine", rb_ease_sine, 5);
Expand Down
20 changes: 10 additions & 10 deletions ext/rubyraylib/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require "mkmf"

# Define directories for raylib, raygui, and reasings
raylib_dir = File.expand_path(File.dirname(__FILE__) + "/../../third_party/raylib/src")
raygui_dir = File.expand_path(File.dirname(__FILE__) + "/../../third_party/raygui/src")
reasings_dir = File.expand_path(File.dirname(__FILE__) + "/../../third_party/reasings/src")
raylib_dir = File.expand_path("#{File.dirname(__FILE__)}/../../third_party/raylib/src")
raygui_dir = File.expand_path("#{File.dirname(__FILE__)}/../../third_party/raygui/src")
reasings_dir = File.expand_path("#{File.dirname(__FILE__)}/../../third_party/reasings/src")

# Add include and library directories
$INCFLAGS << " -I#{raylib_dir} -I#{raygui_dir} -I#{reasings_dir}"
Expand All @@ -18,13 +18,13 @@

$LDFLAGS << " #{raylib_lib} #{raygui_lib} #{reasings_lib}"

if /linux/i =~ RUBY_PLATFORM
$LDFLAGS << " -lGL -lm -lpthread -ldl -lrt -lX11 -lXrandr"
elsif /darwin/i =~ RUBY_PLATFORM
$LDFLAGS << " -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL"
else
$LDFLAGS << " -lgdi32 -lwinmm"
end
$LDFLAGS << if /linux/i =~ RUBY_PLATFORM
" -lGL -lm -lpthread -ldl -lrt -lX11 -lXrandr"
elsif /darwin/i =~ RUBY_PLATFORM
" -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL"
else
" -lgdi32 -lwinmm"
end

# Debugging information
puts "Include flags: #{$INCFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RB_METHOD_INT_ARG_STR(rb_set_gamepad_mappings, SetGamepadMappings)
RB_METHOD_ARG_INT_FLOAT_2(rb_set_gamepad_vibration, SetGamepadVibration)

extern "C" void initializeGamepad() {
VALUE rb_mGamepad = rb_define_module_under(rb_mRl, "Gamepad");
VALUE rb_mGamepad = rb_define_module_under(rb_mRL, "Gamepad");

rb_define_module_function(rb_mGamepad, "available?", rb_gamepad_available, 1);
rb_define_module_function(rb_mGamepad, "name", rb_gamepad_name, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/gestures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RB_METHOD_VEC2(rb_get_gesture_pinch_vector, GetGesturePinchVector)
RB_METHOD_FLOAT(rb_get_gesture_pinch_angle, GetGesturePinchAngle)

extern "C" void initializeGestures() {
VALUE rb_mGestures = rb_define_module_under(rb_mRl, "Gestures");
VALUE rb_mGestures = rb_define_module_under(rb_mRL, "Gestures");

rb_define_module_function(rb_mGestures, "enabled=", rb_set_gestures_enabled, 1);
rb_define_module_function(rb_mGestures, "detected?", rb_gesture_detected, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static VALUE rb_gui_label_button(VALUE self, VALUE bounds, VALUE text) {

// Initializes the GUI module and defines its functions
extern "C" void initializeGui() {
VALUE rb_cGui = rb_define_module_under(rb_mRl, "GUI");
VALUE rb_cGui = rb_define_module_under(rb_mRL, "GUI");

rb_define_module_function(rb_cGui, "label", rb_gui_label, 2);
rb_define_module_function(rb_cGui, "label_button", rb_gui_label_button, 2);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static VALUE rb_unload_image(VALUE self) {
// } TextureWrap;

extern "C" void initializeImage() {
rb_cImage = rb_define_class_under(rb_mRl, "Image", rb_cObject);
rb_cImage = rb_define_class_under(rb_mRL, "Image", rb_cObject);
rb_define_alloc_func(rb_cImage, rb_image_alloc<Image>);

rb_define_method(rb_cImage, "initialize", rb_image_initialize, 1);
Expand Down
10 changes: 4 additions & 6 deletions ext/rubyraylib/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ float GetRandomFloat(float min, float max)

return value;
}
RB_METHOD_ARG_FLOAT_2(rb_get_random_float, GetRandomFloat)

static int fibonacci(int n) {
if (n <= 1)
return n;
static int fibonacci(int number) {
if (number <= 1)
return number;

return fibonacci(n - 1) + fibonacci(n - 2);
return fibonacci(number - 1) + fibonacci(number - 2);
}
RB_METHOD_INT_ARG(rb_fibonacci, fibonacci)

extern "C" void initializeKernel() {
rb_define_module_function(rb_mKernel, "random", rb_get_random_value, 2);

rb_define_module_function(rb_mKernel, "random_f", rb_get_random_float, 2);
rb_define_module_function(rb_mKernel, "fib", rb_fibonacci, 1);
}
5 changes: 1 addition & 4 deletions ext/rubyraylib/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ RB_METHOD_BOOL_ARG_INT(rb_key_up, IsKeyUp)
RB_METHOD_INT(rb_get_key_pressed, GetKeyPressed)
// RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
RB_METHOD_INT(rb_get_char_pressed, GetCharPressed)
// RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
RB_METHOD_ARG_INT(rb_set_exit_key, SetExitKey)

extern "C" void initializeKeyboard() {
VALUE rb_mKeyboard = rb_define_module_under(rb_mRl, "Keyboard");
VALUE rb_mKeyboard = rb_define_module_under(rb_mRL, "Keyboard");

rb_define_module_function(rb_mKeyboard, "pressed?", rb_key_pressed, 1);
rb_define_module_function(rb_mKeyboard, "repeat?", rb_key_pressed_repeat, 1);
Expand All @@ -32,7 +30,6 @@ extern "C" void initializeKeyboard() {
rb_define_module_function(rb_mKeyboard, "up?", rb_key_up, 1);
rb_define_module_function(rb_mKeyboard, "pressed", rb_get_key_pressed, 0);
rb_define_module_function(rb_mKeyboard, "char_pressed", rb_get_char_pressed, 0);
rb_define_module_function(rb_mKeyboard, "exit_key=", rb_set_exit_key, 1);

// Alphanumeric keys
rb_define_const(rb_mKeyboard, "NULL", INT2NUM(0));
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RB_METHOD_VEC2(rb_get_mouse_wheel_move_v, GetMouseWheelMoveV)
RB_METHOD_ARG_INT(rb_set_mouse_cursor, SetMouseCursor)

extern "C" void initializeMouse() {
VALUE rb_mMouse = rb_define_module_under(rb_mRl, "Mouse");
VALUE rb_mMouse = rb_define_module_under(rb_mRL, "Mouse");

rb_define_module_function(rb_mMouse, "button_pressed?", rb_mouse_button_pressed, 1);
rb_define_module_function(rb_mMouse, "button_down?", rb_mouse_button_down, 1);
Expand Down
4 changes: 2 additions & 2 deletions ext/rubyraylib/raylib_values.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "raylib_values.hpp"

VALUE rb_mRl;
VALUE rb_mRL;

extern "C" void initializeRaylib() { rb_mRl = rb_define_module("Rl"); }
extern "C" void initializeRaylib() { rb_mRL = rb_define_module("RL"); }
2 changes: 1 addition & 1 deletion ext/rubyraylib/raylib_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#include "ruby_values.hpp"

extern "C" void initializeRaylib();
extern VALUE rb_mRl;
extern VALUE rb_mRL;

#endif // RAYLIB_VALUES_H
2 changes: 1 addition & 1 deletion ext/rubyraylib/rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static VALUE rb_draw_rectangle_rec(VALUE self, VALUE color) {
}

extern "C" void initializeRect() {
rb_cRect = rb_define_class_under(rb_mRl, "Rect", rb_cObject);
rb_cRect = rb_define_class_under(rb_mRL, "Rect", rb_cObject);
rb_define_alloc_func(rb_cRect, rb_object_alloc<RayRectangle>);

rb_define_method(rb_cRect, "initialize", rb_rect_initialize, 4);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static VALUE rb_draw_rectangle_v(VALUE self, VALUE position, VALUE size, VALUE c
// RLAPI RayRectangle GetCollisionRec(RayRectangle rec1, RayRectangle rec2); // Get collision rectangle for two rectangles collision

extern "C" void initializeShapes(void) {
VALUE rb_mShapes = rb_define_module_under(rb_mRl, "Shapes");
VALUE rb_mShapes = rb_define_module_under(rb_mRL, "Shapes");

rb_define_module_function(rb_mShapes, "rect", rb_draw_rectangle, 5);
rb_define_module_function(rb_mShapes, "rect_v", rb_draw_rectangle_v, 3);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static VALUE rb_draw_text(VALUE self, VALUE text, VALUE posX, VALUE posY,
// } FontType;

extern "C" void initializeText(void) {
VALUE rb_mText = rb_define_module_under(rb_mRl, "Text");
VALUE rb_mText = rb_define_module_under(rb_mRL, "Text");

rb_define_module_function(rb_mText, "draw", rb_draw_text, 5);
}
2 changes: 1 addition & 1 deletion ext/rubyraylib/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static VALUE rb_set_texture_scale(VALUE self, VALUE value) {
}

extern "C" void initializeTexture() {
rb_cTexture = rb_define_class_under(rb_mRl, "Texture", rb_cObject);
rb_cTexture = rb_define_class_under(rb_mRL, "Texture", rb_cObject);
rb_define_alloc_func(rb_cTexture, rb_texture_alloc<Texture>);

rb_define_method(rb_cTexture, "initialize", rb_texture_initialize, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/texture_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ VALUE rb_texture_atlas_draw_batch(VALUE self, VALUE positions) {
}

extern "C" void initializeTextureAtlas() {
rb_cTextureAtlas = rb_define_class_under(rb_mRl, "TextureAtlas", rb_cObject);
rb_cTextureAtlas = rb_define_class_under(rb_mRL, "TextureAtlas", rb_cObject);
rb_define_alloc_func(rb_cTextureAtlas, texture_atlas_alloc);
rb_define_method(rb_cTextureAtlas, "initialize", texture_atlas_initialize, 2);
rb_define_method(rb_cTextureAtlas, "add", texture_atlas_add_texture, 2);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RB_METHOD_INT_ARG(rb_get_touch_point_id, GetTouchPointId)
RB_METHOD_INT(rb_get_touch_point_count, GetTouchPointCount)

extern "C" void initializeTouch() {
VALUE rb_mTouch = rb_define_module_under(rb_mRl, "Touch");
VALUE rb_mTouch = rb_define_module_under(rb_mRL, "Touch");

rb_define_module_function(rb_mTouch, "x", rb_get_touch_x, 0);
rb_define_module_function(rb_mTouch, "y", rb_get_touch_y, 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/vec2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static VALUE rb_vec2_to_s(VALUE self) {
}

extern "C" void initializeVec2() {
rb_cVec2 = rb_define_class_under(rb_mRl, "Vec2", rb_cObject);
rb_cVec2 = rb_define_class_under(rb_mRL, "Vec2", rb_cObject);
rb_define_alloc_func(rb_cVec2, rb_object_alloc<Vector2>);

rb_define_method(rb_cVec2, "initialize", rb_vec2_initialize, 2);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/vec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static VALUE rb_color_from_hsv(VALUE self) {
}

extern "C" void initializeVec3() {
rb_cVec3 = rb_define_class_under(rb_mRl, "Vec3", rb_cObject);
rb_cVec3 = rb_define_class_under(rb_mRL, "Vec3", rb_cObject);
rb_define_alloc_func(rb_cVec3, rb_object_alloc<Vector3>);

rb_define_method(rb_cVec3, "from_hsv", rb_color_from_hsv, 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/rubyraylib/vec4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static VALUE rb_color_from_normalized(VALUE self) {
}

extern "C" void initializeVec4() {
rb_cVec4 = rb_define_class_under(rb_mRl, "Vec4", rb_cObject);
rb_cVec4 = rb_define_class_under(rb_mRL, "Vec4", rb_cObject);
rb_define_alloc_func(rb_cVec4, rb_object_alloc<Vector4>);

rb_define_method(rb_cVec4, "from_normalize", rb_color_from_normalized, 0);
Expand Down
6 changes: 5 additions & 1 deletion ext/rubyraylib/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ RB_METHOD(rb_enable_event_waiting, EnableEventWaiting)
// RLAPI void DisableEventWaiting(void); // Disable waiting for events on EndDrawing(), automatic events polling
RB_METHOD(rb_disable_event_waiting, DisableEventWaiting)

// RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
RB_METHOD_ARG_INT(rb_set_exit_key, SetExitKey)

// Cursor-related functions
// RLAPI void RayShowCursor(void); // Shows cursor
RB_METHOD(rb_show_cursor, RayShowCursor)
Expand Down Expand Up @@ -152,7 +155,7 @@ RB_METHOD_ARG_INT_2(rb_draw_fps, DrawFPS)
// RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available)

extern "C" void initializeWindow() {
VALUE rb_mWindow = rb_define_module_under(rb_mRl, "Window");
VALUE rb_mWindow = rb_define_module_under(rb_mRL, "Window");

rb_define_module_function(rb_mWindow, "init", rb_init_window, 3);
rb_define_module_function(rb_mWindow, "close", rb_close_window, 0);
Expand Down Expand Up @@ -220,6 +223,7 @@ extern "C" void initializeWindow() {
rb_enable_event_waiting, 0);
rb_define_module_function(rb_mWindow, "disable_event_waiting",
rb_disable_event_waiting, 0);
rb_define_module_function(rb_mWindow, "exit_key=", rb_set_exit_key, 1);

rb_define_module_function(rb_mWindow, "show_cursor", rb_show_cursor, 0);
rb_define_module_function(rb_mWindow, "hide_cursor", rb_hide_cursor, 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyraylib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "rubyraylib/version"
require_relative "rubyraylib/rubyraylib"
require_relative "rubyraylib/settings"
include Rl
include RL
require_relative "rubyraylib/raymark"

class Game
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyraylib/raymark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def generate_random_positions
end
end

def update(delta)
def update(_delta)
return unless MOVE_ELEMENTS

MAX_ELEMENTS.times { |i| @positions[i].random_movement(@direction, @speed) }
Expand Down
Loading

0 comments on commit 0c5806a

Please sign in to comment.