Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions CompleteCook.resource_order
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{"name":"Extensions","order":11,"path":"folders/Extensions.yy",},
{"name":"Gameframe","order":1,"path":"folders/Extensions/Gameframe.yy",},
{"name":"Fonts","order":4,"path":"folders/Fonts.yy",},
{"name":"InputSystem","order":16,"path":"folders/InputSystem.yy",},
{"name":"Notes","order":10,"path":"folders/Notes.yy",},
{"name":"Objects","order":6,"path":"folders/Objects.yy",},
{"name":"Boss","order":8,"path":"folders/Objects/Boss.yy",},
Expand Down Expand Up @@ -261,7 +262,6 @@
{"name":"gameframe_macros","order":1,"path":"scripts/gameframe_macros/gameframe_macros.yy",},
{"name":"generic_functions_util","order":2,"path":"scripts/generic_functions_util/generic_functions_util.yy",},
{"name":"hud_get_visible","order":20,"path":"scripts/hud_get_visible/hud_get_visible.yy",},
{"name":"input_util","order":1,"path":"scripts/input_util/input_util.yy",},
{"name":"key_util","order":14,"path":"scripts/key_util/key_util.yy",},
{"name":"particle_util","order":7,"path":"scripts/particle_util/particle_util.yy",},
{"name":"player_actor","order":13,"path":"scripts/player_actor/player_actor.yy",},
Expand Down Expand Up @@ -295,9 +295,10 @@
{"name":"player_taunt","order":11,"path":"scripts/player_taunt/player_taunt.yy",},
{"name":"player_tumble","order":4,"path":"scripts/player_tumble/player_tumble.yy",},
{"name":"player_util","order":6,"path":"scripts/player_util/player_util.yy",},
{"name":"scr_input","order":1,"path":"scripts/scr_input/scr_input.yy",},
{"name":"scr_inputdeclarations","order":2,"path":"scripts/scr_inputdeclarations/scr_inputdeclarations.yy",},
{"name":"scr_pattern_utilities","order":4,"path":"scripts/scr_pattern_utilities/scr_pattern_utilities.yy",},
{"name":"scr_retro_pal_swapper_utilities","order":1,"path":"scripts/scr_retro_pal_swapper_utilities/scr_retro_pal_swapper_utilities.yy",},
{"name":"scr_savesystem","order":16,"path":"scripts/scr_savesystem/scr_savesystem.yy",},
{"name":"shell_commands","order":11,"path":"scripts/shell_commands/shell_commands.yy",},
{"name":"sound_util","order":10,"path":"scripts/sound_util/sound_util.yy",},
{"name":"text_util","order":17,"path":"scripts/text_util/text_util.yy",},
Expand Down
6 changes: 4 additions & 2 deletions CompleteCook.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions objects/obj_bossgate/Create_0.gml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
enter_door = new Input(global.keybinds.up);

enter_door = false;

bg_surf = -1
image_speed = 0
Expand Down
2 changes: 1 addition & 1 deletion objects/obj_bossgate/Step_0.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enter_door.update(global.keybinds.up);
enter_door = obj_player.input.up; // update input

if (place_meeting(x, y, obj_player) && scr_can_enter_door(obj_player.state) && enter_door.check && obj_player.grounded)
{
Expand Down
2 changes: 1 addition & 1 deletion objects/obj_door/Collision_obj_player.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enter_door.update(global.keybinds.up);
enter_door = obj_player.input.up; // update input

if (other.bbox_bottom <= bbox_bottom + 1 && other.bbox_bottom >= bbox_bottom - 1 && enter_door.check && scr_can_enter_door(other.state))
{
Expand Down
3 changes: 2 additions & 1 deletion objects/obj_door/Create_0.gml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
depth = 50
enter_door = new Input(global.keybinds.up);

enter_door = false;
54 changes: 54 additions & 0 deletions objects/obj_inputcontroller/Create_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*

Put me in the init room!

*/

// ensure only one of me exists
if (instance_number(obj_inputcontroller) > 1)
{
instance_destroy();
exit;
}

devices = []; // the devices that are used for input, this can be controllers, keyboard input, etc.
handler_instances = []; // the instances of InputHandlers that will be updated at begin step.

// jsdoc inside of the anonymous functions because of event naming issues

device_add = function(_input_device)
{
///@description Add a device
///@param {Struct.InputDevice} _input_device The InputDevice to push to the devices.
array_push(devices, _input_device);
}

device_remove = function(_index)
{
///@description Remove a device
///@param {Real} _index The index of the array to delete.
array_delete(devices, _index, 1);
}

gamepad_find = function(_gamepad_id)
{
///@description Finds the position of a gamepad in the devices
///@param {Real} _gamepad_id The gamepad index to look for.
for (var i = 0; i < array_length(devices); i++)
{
var _device = devices[i];
if (_device.index == _gamepad_id && _device.input_type == INPUT_TYPE.CONTROLLER)
return i;
}
return -1;
}

// add a device for the main keyboard input
keyboard_device = new InputDevice(); // always at index 0
device_add(keyboard_device);

// always add main gamepad so it can be referenced immediately in other parts
main_gamepad = new InputDevice(INPUT_TYPE.CONTROLLER, 0);
device_add(main_gamepad);


26 changes: 26 additions & 0 deletions objects/obj_inputcontroller/Other_75.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var _type = async_load[? "event_type"];
var _index;

if (_type == "gamepad discovered")
{
_index = async_load[? "pad_index"];

// if theres no gamepad connected yet, we use the one created earlier
// handles cases where the gamepad is at a weird index
if (!gamepad_is_connected(main_gamepad.index))
{
main_gamepad.index = _index;
gamepad_set_axis_deadzone(_index, DEADZONE);
}
else
{
// if the main gamepad is occupied add this as a new device
if (gamepad_find(_index) == -1)
device_add(new InputDevice(INPUT_TYPE.CONTROLLER, _index));
}
}
else if (_type == "gamepad lost")
{
_index = async_load[? "pad_index"];
device_remove(gamepad_find(_index));
}
11 changes: 11 additions & 0 deletions objects/obj_inputcontroller/Step_1.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
for (var i = 0; i < array_length(handler_instances); i++)
{
var _handler = handler_instances[i];
if (_handler.to_cleanup)
{
array_delete(handler_instances, i--, 1);
continue;
}
_handler.update();
}

37 changes: 37 additions & 0 deletions objects/obj_inputcontroller/obj_inputcontroller.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion objects/obj_keyconfig/CleanUp_0.gml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//resave the keybind struct, more info at the bottom of function set_globals
var keybindBuf = write_struct_to_buffer(global.keybinds)
var keybindBuf = buffer_create(1, buffer_grow, 1);
buffer_write(keybindBuf, buffer_text, json_stringify(global.keybinds));

buffer_save(keybindBuf, global.keybinds_filename)

buffer_delete(keybindBuf)

input_handler.Cleanup();
35 changes: 24 additions & 11 deletions objects/obj_keyconfig/Create_0.gml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
// declare input
ui_input =
input_handler = new InputHandler(obj_inputcontroller.main_gamepad).AddInput(["ui_up", "ui_down", "ui_accept", "ui_deny", "addbind", "clearbind", "resetallbinds"]).Finalize();

ui_input =
{
up: false,
down: false,
accept: false,
deny: false,
addbind: false,
clearbind: false,
resetallbinds: false
}

update_input = function()
{
up: new Input(global.keybinds.ui_up),
down: new Input(global.keybinds.ui_down),
accept: new Input(global.keybinds.ui_accept),
deny: new Input(global.keybinds.ui_deny),
addbind: new Input("Z"),
clearbind: new Input("C"),
resetallbinds: new Input(vk_f1)
};
ui_input.up = input_handler.get_input("ui_up");
ui_input.down = input_handler.get_input("ui_down");
ui_input.accept = input_handler.get_input("ui_accept");
ui_input.deny = input_handler.get_input("ui_deny");
ui_input.addbind = input_handler.get_input("addbind");
ui_input.clearbind = input_handler.get_input("clearbind");
ui_input.resetallbinds = input_handler.get_input("resetallbinds");
}

depth = -3000
binds = [
Expand All @@ -26,8 +39,8 @@ binds = [
{input: global.keybinds.ui_right, image_index: 2, name: "Menu Right", globalname: "ui_right", defaultbind: vk_right},
{input: global.keybinds.ui_up, image_index: 0, name: "Menu Up", globalname: "ui_up", defaultbind: vk_up},
{input: global.keybinds.ui_down, image_index: 1, name: "Menu Down", globalname: "ui_down", defaultbind: vk_down},
{input: global.keybinds.ui_accept, image_index: 7, name: "Accept", globalname: "ui_accept", defaultbind: [vk_enter, vk_space, "Z"]},
{input: global.keybinds.ui_deny, image_index: 8, name: "Deny", globalname: "ui_deny", defaultbind: [vk_escape, vk_backspace, "X"]}
{input: global.keybinds.ui_accept, image_index: 7, name: "Accept", globalname: "ui_accept", defaultbind: "Z"},
{input: global.keybinds.ui_deny, image_index: 8, name: "Deny", globalname: "ui_deny", defaultbind: "X"}
] //dont mind these warnings

c_x = 0
Expand Down
37 changes: 16 additions & 21 deletions objects/obj_keyconfig/Step_0.gml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
// update input
ui_input.up.update(global.keybinds.ui_up);
ui_input.down.update(global.keybinds.ui_down);
ui_input.accept.update(global.keybinds.ui_accept);
ui_input.deny.update(global.keybinds.ui_deny);
ui_input.addbind.update("Z");
ui_input.clearbind.update("C");
ui_input.resetallbinds.update(vk_f1);
update_input();

if !binding
selected = clamp(selected + (-ui_input.up.pressed + ui_input.down.pressed), -1, array_length(binds) - 1)
Expand All @@ -28,33 +21,35 @@ if binding
else
{
if is_real(global.keybinds[$ bindname])
global.keybinds[$ bindname] = [global.keybinds[$ bindname]] //convert it to array
global.keybinds[$ bindname] = global.keybinds[$ bindname];
else if is_string(global.keybinds[$ bindname])
global.keybinds[$ bindname] = [ord(global.keybinds[$ bindname])]
global.keybinds[$ bindname] = ord(global.keybinds[$ bindname]);

if !array_contains(global.keybinds[$ bindname], keyboard_key) //check if the key isnt set already
array_push(global.keybinds[$ bindname], keyboard_key) //then add the key
}

binds[selected].input = global.keybinds[$ bindname]
binding = false
binds[selected].input = global.keybinds[$ bindname];
binding = false;

update_binds();
}
}
else
{
if ui_input.addbind.pressed
binding = true
binding = true;
else if ui_input.clearbind.pressed
{
global.keybinds[$ bindname] = vk_nokey
binds[selected].input = global.keybinds[$ bindname]
global.keybinds[$ bindname] = vk_nokey;
binds[selected].input = global.keybinds[$ bindname];
}
else if ui_input.resetallbinds.pressed
{
array_foreach(binds, function(_element) {
_element.input = _element.defaultbind
global.keybinds[$ _element.globalname] = _element.defaultbind
})
array_foreach(binds, function(_element)
{
_element.input = _element.defaultbind;
global.keybinds[$ _element.globalname] = _element.defaultbind;
});
update_binds();
}
if ui_input.deny.pressed
instance_destroy()
Expand Down
1 change: 1 addition & 0 deletions objects/obj_menuhandler/CleanUp_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input_handler.Cleanup();
32 changes: 15 additions & 17 deletions objects/obj_menuhandler/Create_0.gml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
// declare input
special_keybind_deny = variable_clone(global.keybinds.ui_deny) //special conflicting input removal

if is_array(special_keybind_deny)
{
var _d_ix = array_get_index(special_keybind_deny, ord("X"))

if _d_ix != -1
array_delete(special_keybind_deny, _d_ix, 1)
}

show_debug_message(special_keybind_deny)
input_handler = new InputHandler(obj_inputcontroller.main_gamepad).AddInput(["ui_left", "ui_right", "grab", "ui_accept", "menuhandler_deny"]).Finalize();

input =
{
left: new Input(global.keybinds.ui_left),
right: new Input(global.keybinds.ui_right),
grab: new Input(global.keybinds.grab),
accept: new Input(global.keybinds.ui_accept),
deny: new Input(special_keybind_deny)
left: false,
right: false,
grab: false,
accept: false,
deny: false
};

update_input = function()
{
input.left = input_handler.get_input("ui_left");
input.right = input_handler.get_input("ui_right");
input.grab = input_handler.get_input("grab");
input.accept = input_handler.get_input("ui_accept");
input.deny = input_handler.get_input("menuhandler_deny");
}

tvs = [new ini_menu_tv_inst(103, 0,
spr_menutv1_off,
spr_menutv1_whitenoise,
Expand Down
Loading