/*
READ ME!
========
PS4 Touchpad Swiping Framework (BETA).
Description:
------------
Uses three checkpoints on the touchpad to determine a swipe.
*Check the functions below and there comments for a fun simplified explanation
of the checkpoints.
PROS:
This script is feature complete, you can swipe up, down, left, right and have
it do combos or any logic you please.
CONS:
HOWEVER! The script contains bugs and/or unintended behaviors.
***Read the "Known Issues" section down below***
My goal is to eventually have the swipes be as close as possible to the behavior
of games that use swipes for in-game actions (free from the erros stated below).
*Like Warframe where you can swipe to use powers and other things without any
logical errors on the swipe itself.
Known Issues
------------
1. Script is not aware of when you are touching the touchpad or not.
It only knows the coordinates of the last touch.
2. Since the script is not aware of when you are touching the touchpad,
you could tap (touch and release) each of the checkpoints and the script
will think you did a whole swipe.
The intended behavior is if you touch the touchpad and let go
(without a complete swipe), the swipe should be cancelled.
3. Diagonal swipes may trigger two different swipes.
Ex: Swiping from bottom right corner to the top left corner can trigger a
left-swipe and up-swipe.
Possible fixes:
a. Set a variable to keep track of TOUCH_X or TOUCH_Y depending on location
of touch and then create an area (bounds) where if the touch goes out of
bounds, the swipe won't trigger/return true.
Ex: If TOUCH_Y > 80 (bottom of touchpad), we can assume the person is
going to swipe up. Once the swipe reaches checkpoint 2, we set a
variable to the current value of TOUCH_X and then we create the
area around that TOUCH_X value.
Going beyond this area could be interpreted as a diagonal swipe.
b. ???
*/
int pt_y_up = 0;
int pt_y_down = 0;
int pt_x_left = 0;
int pt_x_right = 0;
//__________________________________SETTINGS__________________________________//
// size of swipe
int pt_y_area = 70; // The larger the number, the bigger of a swipe you need.
// second checkpoint deadzone (middle of touchpad)
int cp2_deadzone = 20;
//____________________________________________________________________________//
main
{
// Example Usage
if(swipe_up())
{
combo_run(test4) // You can delete this combo_run and use your own stuff
}
if(swipe_down())
{
combo_run(test) // You can delete this combo_run and use your own stuff
}
if(swipe_left())
{
combo_run(test2) // You can delete this combo_run and use your own stuff
}
if(swipe_right())
{
combo_run(test3) // You can delete this combo_run and use your own stuff
}
// debug (you can delete or ignore this)
set_val(TRACE_1, pt_y_up);
set_val(TRACE_2, pt_y_down);
set_val(TRACE_3, pt_x_left);
set_val(TRACE_4, pt_x_right);
}
combo test // You can delete this combo. (Used for the example in the main.)
{
set_val(PS4_CROSS, 100)
wait(1000)
}
combo test2 // You can delete this combo. (Used for the example in the main.)
{
set_val(PS4_SQUARE, 100)
wait(1000)
}
combo test3 // You can delete this combo. (Used for the example in the main.)
{
set_val(PS4_CIRCLE, 100)
wait(1000)
}
combo test4 // You can delete this combo. (Used for the example in the main.)
{
set_val(PS4_TRIANGLE, 100)
wait(1000)
}
function swipe_up() // Returns TRUE if the user swiped up
{
// Checkpoint 1: ("Looks like there is going to be a swipe up based on the touch location (bottom of touchpad)! :o ")
if(get_val(PS4_TOUCHY) > pt_y_area)
{
pt_y_up = 1
}
// Checkpoint 2: ("Person is halfway through the swipe (middle of touchpad)! :3 ")
if(pt_y_up == 1 && (get_val(PS4_TOUCHY) < 0 && get_val(PS4_TOUCHY) > cp2_deadzone *-1) )
{
pt_y_up = 2
}
// Checkpoint 3 ("We got a complete swipe (top of touchpad)! :D ")
if(pt_y_up == 2 && get_val(PS4_TOUCHY) < pt_y_area * -1)
{
pt_y_up = 0
return TRUE
}
}
function swipe_down() // Returns TRUE if the user swiped down
{
if(get_val(PS4_TOUCHY) < pt_y_area * -1)
{
pt_y_down = -1
}
if(pt_y_down == -1 && (get_val(PS4_TOUCHY) > 0 && get_val(PS4_TOUCHY) < cp2_deadzone) )
{
pt_y_down = -2
}
if(pt_y_down == -2 && get_val(PS4_TOUCHY) > pt_y_area)
{
pt_y_down = 0
return TRUE
}
}
function swipe_left() // Returns TRUE if the user swiped left
{
if(get_val(PS4_TOUCHX) > pt_y_area)
{
pt_x_left = 1
}
if(pt_x_left == 1 && (get_val(PS4_TOUCHX) < 0 && get_val(PS4_TOUCHX) > cp2_deadzone *-1) )
{
pt_x_left = 2
}
if(pt_x_left == 2 && get_val(PS4_TOUCHX) < pt_y_area * -1)
{
pt_x_left = 0
return TRUE
}
}
function swipe_right() // Returns TRUE if the user swiped down
{
if(get_val(PS4_TOUCHX) < pt_y_area * -1)
{
pt_x_right = -1
}
if(pt_x_right == -1 && (get_val(PS4_TOUCHX) > 0 && get_val(PS4_TOUCHX) < cp2_deadzone) )
{
pt_x_right = -2
}
if(pt_x_right == -2 && get_val(PS4_TOUCHX) > pt_y_area)
{
pt_x_right = 0
return TRUE
}
}