Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stanncam methods to support method chaining #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions scripts/stanncam/stanncam.gml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf

/// @function __step
/// @description gets called every step
/// @returns {Struct.stanncam}
/// @ignore
static __step = function(){

Expand Down Expand Up @@ -268,6 +269,8 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf

__update_view_size();
__update_view_pos();

return self;
}
#endregion

Expand Down Expand Up @@ -303,6 +306,7 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
/// @param {Real} _x
/// @param {Real} _y
/// @param {Real} [_duration=0]
/// @returns {Struct.stanncam}
/// @ignore
static move = function(_x, _y, _duration=0){
if(_duration == 0 && !instance_exists(follow)){
Expand All @@ -320,13 +324,16 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
__yTo = _y;
__duration = _duration;
}

return self;
}

/// @function set_size
/// @description sets the camera dimensions
/// @param {Real} _width
/// @param {Real} _height
/// @param {Real} [_duration=0]
/// @returns {Struct.stanncam}
/// @ignore
static set_size = function(_width, _height, _duration=0){
if(_duration == 0){ //if duration is 0 the view is updated immediately
Expand All @@ -343,13 +350,16 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
__hTo = _height;
__dimen_duration = _duration;
}

return self;
}

/// @function offset
/// @description offsets the camera over a duration
/// @param {Real} _offset_x
/// @param {Real} _offset_y
/// @param {Real} [_duration=0]
/// @returns {Struct.stanncam}
/// @ignore
static offset = function(_offset_x, _offset_y, _duration=0){
if(_duration == 0){ //if duration is 0 the view is updated immediately
Expand All @@ -366,12 +376,15 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
__offset_yTo = _offset_y;
__offset_duration = _duration;
}

return self;
}

/// @function zoom
/// @description zooms the camera over a duration
/// @param {Real} _zoom
/// @param {Real} [_duration=0]
/// @returns {Struct.stanncam}
/// @ignore
static zoom = function(_zoom, _duration=0){
if(_duration == 0){ //if duration is 0 the view is updated immediately
Expand All @@ -393,6 +406,8 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
__zoomTo = _zoom;
__zoom_duration = _duration;
}

return self;
}

/// @function get_zoom_x
Expand All @@ -415,28 +430,34 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
/// @description makes the camera shake
/// @param {Real} _magnitude
/// @param {Real} _duration - duration in frames
/// @returns {Struct.stanncam}
/// @ignore
static shake_screen = function(_magnitude, _duration){
__shake_magnitude = _magnitude;
__shake_length = _duration;
__shake_time = 0;
return self;
}

/// @function set_speed
/// @description changes the speed of the camera
/// @param {Real} _spd - how fast the camera can move
/// @param {Real} _threshold - minimum distance for the speed to have full effect
/// @returns {Struct.stanncam}
/// @ignore
static set_speed = function(_spd, _threshold){
spd = _spd;
spd_threshold = _threshold;
return self;
}

/// @function set_paused
/// @description sets camera paused state
/// @param {Bool} _paused
/// @returns {Struct.stanncam}
static set_paused = function(_paused){
paused = _paused;
return self;
}

/// @function get_paused
Expand All @@ -448,8 +469,10 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf

/// @function toggle_paused
/// @description toggles the camera's paused state
/// @returns {Struct.stanncam}
static toggle_paused = function(){
set_paused(!get_paused());
return self;
}

/// @function get_x
Expand Down Expand Up @@ -581,16 +604,19 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf

/// @function __check_viewports
/// @description enables viewports and sets viewports size
/// @returns {Struct.stanncam}
/// @ignore
static __check_viewports = function(){
view_visible[cam_id] = true;
view_camera[cam_id] = __camera;
__check_surface();
__update_view_size(true);
return self;
}

/// @function __check_surface
/// @description checks if surface & surface_extra exists and else creates it
/// @returns {Struct.stanncam}
/// @ignore
static __check_surface = function(){
if(use_app_surface){
Expand All @@ -604,6 +630,8 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
if(surface_extra_on && !surface_exists(surface_extra)){
surface_extra = surface_create(width, height);
}

return self;
}

/// @function __predraw
Expand All @@ -624,6 +652,7 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
/// @function __update_view_size
/// @description updates the view size
/// @param {Bool} [_force=false]
/// @returns {Struct.stanncam}
/// @ignore
static __update_view_size = function(_force=false){
//if smooth_draw is off maintains pixel perfection even when zooming in and out
Expand All @@ -648,10 +677,13 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
surface_resize(surface, _new_width, _new_height);
camera_set_view_size(__camera, _new_width, _new_height);
}

return self;
}

/// @function __update_view_pos
/// @description updates the view position
/// @returns {Struct.stanncam}
/// @ignore
static __update_view_pos = function(){
//update camera view
Expand Down Expand Up @@ -753,6 +785,8 @@ function stanncam(_x=0, _y=0, _width=global.game_w, _height=global.game_h, _surf
}

camera_set_view_pos(__camera, _new_x, _new_y);

return self;
}
#endregion

Expand Down