Last active
November 14, 2017 09:59
-
-
Save McTwist/8bdd572fe31663d4a73ea534b5e261cd to your computer and use it in GitHub Desktop.
Binds a key to a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a possible bind to a function. This will place it in respective division. | |
// If division and name is the same, it will replace the function. | |
function CreateBind(%division, %name, %cmd) | |
{ | |
if (%name $= "" || %cmd $= "") | |
return; | |
%remapid = $remapCount; | |
%new = true; | |
if (%division !$= "") | |
{ | |
// Find division | |
for (%i = 0; %i < $remapCount; %i++) | |
{ | |
// Found division | |
if ($remapDivision[%i] $= %division || (%new == false && $remapDivision[%i] $= "")) | |
{ | |
// Put it in the end | |
%remapid = %i+1; | |
%new = false; | |
// Replace function | |
if ($remapName[%i] $= %name) | |
{ | |
$remapCmd[%i] = %cmd; | |
return; | |
} | |
} | |
// End of division | |
else if (%new == false) | |
{ | |
break; | |
} | |
} | |
// Move binds | |
for (%i = $remapCount; %i > %remapid; %i--) | |
{ | |
$remapDivision[%i] = $remapDivision[%i-1]; | |
$remapName[%i] = $remapName[%i-1]; | |
$remapCmd[%i] = $remapCmd[%i-1]; | |
} | |
} | |
// Append bind | |
else | |
{ | |
%new = false; | |
} | |
// Add new one | |
if (%new) | |
$remapDivision[%remapid] = %division; | |
$remapName[%remapid] = %name; | |
$remapCmd[%remapid] = %cmd; | |
$remapCount++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment