Skip to content

Commit e218450

Browse files
committed
Allow for multiple ActionEvent functions, prepare for 1.0
1 parent 2e4ca9b commit e218450

File tree

8 files changed

+301
-9
lines changed

8 files changed

+301
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
COPY ALL .bat AND .sh FILES TO YOUR PROJECT ROOT
2+
OR /extensions/Par/ IF YOU ARE ON 2022+ OR NEWER!!!
3+
THIS IS REQUIRED!!

datafiles/post_build_step.bat

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
@echo off
2+
3+
:: Useful for printing all variables
4+
:: set
5+
6+
:: ########################################### EDIT VARIABLES ###########################################
7+
8+
:: Replace with your steamworks sdk path (download from here: https://partner.steamgames.com/doc/sdk)
9+
set STEAM_SDK_PATH=%~dp0..\steamworks_sdk
10+
if "%USERNAME%" == "user" (
11+
set STEAM_SDK_PATH=D:\SDK\SteamworksLatest
12+
)
13+
14+
:: ######################################################################################################
15+
16+
:: Ensure the path ends with a backslash
17+
if not %STEAM_SDK_PATH:~-1% == \ (
18+
set SDK_PATH=%STEAM_SDK_PATH%\
19+
) else (
20+
set SDK_PATH=%STEAM_SDK_PATH%
21+
)
22+
23+
:: Ensure the directory exists
24+
if not exist "%SDK_PATH%" goto error_incorrect_STEAMWORKS_path
25+
26+
:: Ensure we are on the output path
27+
pushd "%YYoutputFolder%"
28+
29+
:: Call setup method depending on the platform
30+
:: NOTE: the setup method can be (:Windows_copy_dependencies, :MacOS_copy_dependencies or :Ubuntu_copy_dependencies)
31+
call :%YYPLATFORM_name%_copy_dependencies
32+
if ERRORLEVEL 1 (
33+
echo ""
34+
echo "#################################### INFORMATION #####################################"
35+
echo "Steam Extension is not available in this target: %YYPLATFORM_name% (no setup required)"
36+
echo "######################################################################################"
37+
echo ""
38+
)
39+
popd
40+
41+
:exit
42+
exit /b 0
43+
44+
:: ----------------------------------------------------------------------------------------------------
45+
:Windows_copy_dependencies
46+
if "%YYPLATFORM_option_windows_use_x64%" == "True" (
47+
echo "Copying Windows (64 bit) dependencies"
48+
if not exist "steam_api64.dll" copy "%SDK_PATH%redistributable_bin\win64\steam_api64.dll" "steam_api64.dll"
49+
) else (
50+
echo "Copying Windows (32 bit) dependencies"
51+
if not exist "steam_api.dll" copy "%SDK_PATH%redistributable_bin\steam_api.dll" "steam_api.dll"
52+
)
53+
if ERRORLEVEL 1 call :exitError
54+
goto :eof
55+
56+
:: ----------------------------------------------------------------------------------------------------
57+
:macOS_copy_dependencies
58+
echo "Copying macOS (64 bit) dependencies"
59+
if "%YYTARGET_runtime%" == "VM" (
60+
61+
:: This is used for VM
62+
powershell Expand-Archive '%YYprojectName%.zip' _temp\
63+
copy /y "%SDK_PATH%redistributable_bin\osx\libsteam_api.dylib" "_temp\assets\libsteam_api.dylib"
64+
powershell Compress-Archive -Force _temp\* '%YYprojectName%.zip'
65+
rmdir /s /q _temp
66+
67+
) else (
68+
69+
:: This is used from YYC compilation
70+
copy "%SDK_PATH%redistributable_bin\osx\libsteam_api.dylib" "%YYprojectName%\%YYprojectName%\Supporting Files\libsteam_api.dylib"
71+
)
72+
if ERRORLEVEL 1 call :exitError
73+
goto :eof
74+
75+
:: ----------------------------------------------------------------------------------------------------
76+
:Linux_copy_dependencies
77+
echo "Copying Linux (64 bit) dependencies"
78+
powershell Expand-Archive '%YYprojectName%.zip' _temp\
79+
80+
if not exist "assets/libsteam_api.so" (
81+
copy "%SDK_PATH%redistributable_bin\linux64\libsteam_api.so" "_temp\assets\libsteam_api.so"
82+
powershell Compress-Archive -Force _temp\* '%YYprojectName%.zip'
83+
)
84+
rmdir /s /q _temp
85+
if ERRORLEVEL 1 call :exitError
86+
goto :eof
87+
88+
:: ----------------------------------------------------------------------------------------------------
89+
:exitError
90+
echo ""
91+
echo "######################################################## ERROR #########################################################"
92+
echo "The setup script was unable to copy dependencies"
93+
echo "########################################################################################################################"
94+
echo ""
95+
exit 1
96+
97+
:: ----------------------------------------------------------------------------------------------------
98+
:: If the steamworks SDK path doesn't exit ask the user to edit this file
99+
:error_incorrect_STEAMWORKS_path
100+
echo ""
101+
echo "######################################################## ERROR #########################################################"
102+
echo "The specified steamworks SDK path doesn't exist please edit the file 'post_build_step.bat' in your project's root folder"
103+
echo "########################################################################################################################"
104+
echo ""
105+
exit 1

datafiles/post_build_step.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
set echo off
3+
4+
# Useful for printing all variables
5+
# ( set -o posix ; set ) | less
6+
7+
# ########################################### EDIT VARIABLES ###########################################
8+
9+
# Replace with your steamworks sdk path (download from here: https://partner.steamgames.com/doc/sdk)
10+
STEAM_SDK_PATH=$HOME/steamworks_sdk
11+
12+
# ######################################################################################################
13+
14+
function error_incorrect_STEAMWORKS_path () {
15+
echo ""
16+
echo "######################################################## ERROR ########################################################"
17+
echo "The specified steamworks SDK path doesn't exist please edit the file 'post_build_step.sh' in your project's root folder"
18+
echo "#######################################################################################################################"
19+
echo ""
20+
exit 1
21+
}
22+
23+
function macOS_copy_dependencies () {
24+
25+
echo "Copying macOS (64 bit) dependencies"
26+
if [[ "$YYTARGET_runtime" == "VM" ]]; then
27+
cp "${STEAM_SDK_PATH}redistributable_bin/osx/libsteam_api.dylib" "libsteam_api.dylib"
28+
else
29+
cp "${STEAM_SDK_PATH}redistributable_bin/osx/libsteam_api.dylib" "${YYprojectName}/${YYprojectName}/Supporting Files/libsteam_api.dylib"
30+
fi
31+
}
32+
33+
function Linux_copy_dependencies () {
34+
35+
echo "Copying Linux (64 bit) dependencies"
36+
unzip "./${YYprojectName}.zip" -d ./_temp
37+
38+
if [[ ! -f "_temp/assets/libsteam_api.so" ]]; then
39+
cp "${STEAM_SDK_PATH}redistributable_bin/linux64/libsteam_api.so" "_temp/assets/libsteam_api.so"
40+
cd _temp; zip -FS -r "../${YYprojectName}.zip" *
41+
cd ..
42+
fi
43+
rm -r _temp
44+
}
45+
46+
# Ensure the provided path ends with a slash
47+
if [[ "$STEAM_SDK_PATH" != */ ]]; then
48+
STEAM_SDK_PATH=${STEAM_SDK_PATH}/
49+
fi
50+
51+
# Ensure the path exists
52+
if [[ ! -d "$STEAM_SDK_PATH" ]]; then
53+
error_incorrect_STEAMWORKS_path
54+
fi
55+
56+
# Ensure we are on the output path
57+
pushd "$YYoutputFolder" 1>/dev/null
58+
59+
# Call setup method depending on the platform
60+
# NOTE: the setup method can be (:MacOS_copy_dependencies or :Linux_copy_dependencies)
61+
{ # try
62+
${YYPLATFORM_name}_copy_dependencies 2>/dev/null
63+
} || { # catch
64+
echo ""
65+
echo "#################################### INFORMATION ####################################"
66+
echo "Steam Extension is not available in this target: $YYPLATFORM_name (no setup required)"
67+
echo "#####################################################################################"
68+
echo ""
69+
}
70+
71+
popd 1>/dev/null
72+
73+
# exit
74+
exit 0

datafiles/post_package_step.bat

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@echo off
2+
3+
:: Useful for printing all variables
4+
:: set
5+
6+
:: Check if we are exporting to linux (else exit)
7+
if not "%YYPLATFORM_name%" == "Linux" exit 0
8+
9+
:: Change current working directory
10+
pushd "%YYoutputFolder%"
11+
12+
:: Start patching the package
13+
echo "Patching Linux (64 bit) package"
14+
15+
powershell Expand-Archive '%YYprojectName%.zip' _temp\
16+
17+
:: Write the patch file to the temp directory
18+
echo #!/bin/bash >> _temp\run.sh
19+
echo # unset LD_LIBRARY_PATH # breaks on new runtimes >> _temp\run.sh
20+
echo ./%YYprojectName% "$@" >> _temp\run.sh
21+
22+
:: Ensure the EOL format is converted to LF
23+
powershell -noninteractive -NoProfile -ExecutionPolicy Bypass -Command "& {[IO.File]::WriteAllText('_temp\run.sh', ([IO.File]::ReadAllText('_temp\run.sh') -replace \"`r`n\", \"`n\"))};"
24+
25+
:: Recompress the patched project into a zip file
26+
powershell Compress-Archive -Force _temp\* '%YYprojectName%.zip'
27+
28+
rmdir /s /q _temp
29+
30+
:: Return to the previous directory
31+
popd
32+
33+
echo ""
34+
echo "############################################ INFORMATION ############################################"
35+
echo "The package was successfully patched!"
36+
echo " - You should set your game's entry point on the steam dashboard to be: run.sh"
37+
echo "#####################################################################################################"
38+
echo ""
39+
40+
exit /b 0
41+
42+
:: ----------------------------------------------------------------------------------------------------
43+
:exitError
44+
echo "ERROR : Unable to complete"
45+
exit /b 1
46+

datafiles/post_package_step.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set echo off
3+
4+
# Useful for printing all variables
5+
# ( set -o posix ; set ) | less
6+
7+
# Check if we are exporting to linux (else exit)
8+
if [[ "$YYPLATFORM_name" != "Linux" ]]; then exit 0; fi
9+
10+
# Change current working directory
11+
pushd "$YYoutputFolder" 1>/dev/null
12+
13+
# Start patching the package
14+
echo "Patching Linux (64 bit) package"
15+
16+
unzip "./${YYprojectName}.zip" -d ./_temp
17+
18+
# Write the patch file to the temp directory
19+
echo "#!/bin/bash" >> _temp/run.sh
20+
echo "# unset LD_LIBRARY_PATH # breaks on new runtimes" >> _temp/run.sh
21+
echo "./${YYprojectName} \"\$@\"" >> _temp/run.sh
22+
23+
# Add execute permissions
24+
chmod +x _temp/run.sh
25+
26+
cd _temp; zip -FS -r "../${YYprojectName}.zip" *
27+
28+
cd ..
29+
rm -r _temp
30+
31+
rmdir /s /q _temp
32+
33+
# Return to the previous directory
34+
popd 1>/dev/null
35+
36+
echo ""
37+
echo "############################################ INFORMATION ############################################"
38+
echo "The package was successfully patched!"
39+
echo " - You should set your game's entry point on the steam dashboard to: run.sh"
40+
echo "#####################################################################################################"
41+
echo ""
42+
43+
exit 0
44+

objects/Obj_Steam_controller/Step_0.gml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ if (_num > 0) {
1717
if (!justthisonce) {
1818
justthisonce = true;
1919
ParInput_EnableActionEventCallbacks(onActionEventCallback);
20+
ParInput_EnableActionEventCallbacks(function(pParam, test) {
21+
show_debug_message("and an another callback: " + test);
22+
}, "hello userdata test");
2023

2124
var _path = ParInput_GetGlyphPNGForActionOrigin(
2225
EInputActionOrigin.k_PS4_Circle,

par.yyp

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/ParCallbacks/ParCallbacks.gml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,37 @@ function Par_OnSteamShutdown(pParam) {
108108

109109

110110

111-
global._Par_EnableActionEventCallbacksThing = undefined;
111+
global._Par_EnableActionEventCallbacksArray = []; // array of _Par_PerformCallbacks
112112

113113
function _Par_ThingCalledByEnableActionEventCallbacks(pParam) {
114-
if (!is_undefined(global._Par_EnableActionEventCallbacksThing)) {
115-
global._Par_EnableActionEventCallbacksThing(pParam);
114+
var _i;
115+
116+
for (_i = 0; _i < array_length(global._Par_EnableActionEventCallbacksArray); ++_i) {
117+
var _cb = global._Par_EnableActionEventCallbacksArray[@ _i];
118+
119+
if (!is_undefined(_cb)) {
120+
_cb._PerformCallback(pParam);
121+
}
116122
}
123+
124+
return _i;
117125
}
118126

119127
/// @desc An ugly hack around Script_Execute in the runner...
120-
function ParInput_EnableActionEventCallbacks(pCallback) {
128+
function ParInput_EnableActionEventCallbacks(pCallback, userData = undefined) {
121129
if (is_undefined(pCallback)) {
122130
// this will silence action event callbacks...
131+
array_resize(global._Par_EnableActionEventCallbacksArray, 0);
123132
_ParInput_EnableActionEventCallbacks(-1);
133+
return undefined;
124134
}
125135
else {
126-
global._Par_EnableActionEventCallbacksThing = pCallback;
136+
var _cb = new _Par_CallbackObject(pCallback, userData);
137+
var _cblen = array_length(global._Par_EnableActionEventCallbacksArray);
138+
global._Par_EnableActionEventCallbacksArray[@ _cblen] = _cb;
127139
// global scripts do work, methods do not, I want to allow methods
128140
_ParInput_EnableActionEventCallbacks(_Par_ThingCalledByEnableActionEventCallbacks);
141+
return _cb;
129142
}
130143
}
131144

@@ -143,6 +156,7 @@ function _Par_CallbackObject(argcallFunction, arguserData) constructor {
143156
// private:
144157

145158
m_callFunction = argcallFunction;
159+
146160
m_userData = arguserData;
147161

148162
_PerformCallback = function(pParam) {
@@ -189,11 +203,9 @@ for (var _i = EParCallbackFunction.k_First; _i != EParCallbackFunction.k_Max; ++
189203

190204
function _Par_PerformCallbacks(eCallbackType, pParam) {
191205
var _i;
192-
var _cbsarr = global._Par_Callbacks[@ eCallbackType];
193-
var _cbslen = array_length(_cbsarr);
194206

195-
for (_i = 0; _i < _cbslen; ++_i) {
196-
var _thiscb = _cbsarr[@ _i];
207+
for (_i = 0; _i < array_length(global._Par_Callbacks[@ eCallbackType]); ++_i) {
208+
var _thiscb = global._Par_Callbacks[@ eCallbackType][@ _i];
197209

198210
if (!is_undefined(_thiscb)) {
199211
_thiscb._PerformCallback(pParam);

0 commit comments

Comments
 (0)