Do0m

MOVEP Script Def

Dec 30th, 2025 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.18 KB | Source Code | 0 0
  1. // mockup of some "script definition" that generates a Source Engine CFG script
  2. // i'm too dumb to actually implement this tho
  3. // so i'm just gonna use shellscripts to automatically generate it
  4. // and just use this as pseudo-code reference.
  5.  
  6. // The implementation of conditional logic and setters in a Source Engine
  7. // CFG script uses this approach:
  8. // // SWITCH
  9. // alias print>0 "echo 0" // these are called conditionals. main logic
  10. // alias print>1 "echo 1"
  11. // alias print>2 "echo 2"
  12. // alias printwithfeeling>0 "echo 0!"
  13. // alias printwithfeeling>1 "echo 1!"
  14. // alias printwithfeeling>2 "echo 2!"
  15. // // these are setters.
  16. // // all logical aliases that depend on this variable ("a")
  17. // // are assigned to its respective conditional
  18. // alias a=0 "alias print print>0; alias printwithfeeling printwithfeeling>0"
  19. // alias a=1 "alias print print>1; alias printwithfeeling printwithfeeling>1"
  20. // alias a=2 "alias print print>2; alias printwithfeeling printwithfeeling>2"
  21. // a=1 // variable assignment
  22. // print // logical alias call
  23. // a=2
  24. // printwithfeeling
  25. //
  26. // The following are examples of what you could do with this approach:
  27. // // COPY
  28. // alias copy>0 "b=0"
  29. // alias copy>1 "b=1"
  30. // alias a=0 "alias copy copy>0"
  31. // alias a=1 "alias copy copy>1"
  32. // a=1
  33. // copy
  34. //
  35. // // NOT
  36. // alias not>0 "b=1"
  37. // alias not>1 "b=0"
  38. // alias a=0 "alias not not>0"
  39. // alias a=1 "alias not not>1"
  40. // a=1
  41. // not
  42. //
  43. // // AND
  44. // alias and>0 "c=0"
  45. // alias and>1>0 "c=0"
  46. // alias and>1>1 "c=1"
  47. // alias a=0 "alias and and>0"
  48. // alias a=1 "alias and and>1"
  49. // alias b=0 "alias and>1 and>1>0"
  50. // alias b=1 "alias and>1 and>1>1"
  51. // a=1; b=0
  52. // and
  53. //
  54. // // OR
  55. // alias or>0>0 "c=0"
  56. // alias or>0>1 "c=1"
  57. // alias or>1 "c=1"
  58. // alias a=0 "alias or or>0"
  59. // alias a=1 "alias or or>1"
  60. // alias b=0 "alias or>0 or>0>0"
  61. // alias b=1 "alias or>0 or>0>1"
  62. // a=1; b=0
  63. // or
  64.  
  65. // The following is a 2nd possible implementation. Currently unused in
  66. // final script generation.
  67. // It's slower but is more flexible.
  68. // It is originally from https://github.com/ArgosOfIthaca/scalu/wiki/Article:-From-aliases-to-arithmetic#conditional-logic
  69. // // SWITCH
  70. // alias 2 ""
  71. // alias 1 ""
  72. // alias 0 ""
  73. // alias print>0 "echo 0"
  74. // alias print>1 "echo 1"
  75. // alias print>2 "echo 2"
  76. // // logical assignment of aliases is done when alias is invoked
  77. // // instead of when the variable is assigned
  78. // // the variable is an alias itself that is executed
  79. // // Amount of alias assignments is equal to # of possible values
  80. // // instead of # of aliases that depend on the variable
  81. // alias print "alias 0 print>0; alias 1 print>1; alias 2 print>2; a"
  82. // alias printwithfeeling>0 "echo 0!"
  83. // alias printwithfeeling>1 "echo 1!"
  84. // alias printwithfeeling>2 "echo 2!"
  85. // alias printwithfeeling "alias 0 printwithfeeling>0; alias 1 printwithfeeling>1; alias 2 printwithfeeling>2; a"
  86. //
  87. // alias a "1" // variable assignment
  88. // print // logical alias call
  89. // alias a "2"
  90. // printwithfeeling
  91.  
  92. config {
  93.     // Script name must come before all its aliases, followed by a period.
  94.     // (e.g. MOVEP.alias)
  95.     name MOVEP;
  96.  
  97.     // The following are to-be automatic defaults.
  98.     alias_length_limit 31;
  99.     console_command_length_limit 510;
  100.     // required since some script alias names wouldn't fit the limit
  101.     // (e.g. "MOVEP.setDir>FALSE>FALSE>FALSE")
  102.     // note: naturally, public aliases don't use code names so they can
  103.     // be easily reassigned in-game or in other scripts. both aliases and
  104.     // variable setters can either be public or private
  105.     use_script_alias_code_names 1;
  106.     // note: alias names are case-insensitive
  107.     // note: script aliases with codenames are formatted as
  108.     // "{scriptname}.@{alias_codename}"
  109.     // code-named script aliases are similar to youtube video links in that it
  110.     // serves as a unique identifier for the alias. they're fine since we won't
  111.     // expect people to look at the cfg itself to see the logic of the
  112.     // script, and instead, we expect them to look at the script definition.
  113.     alias_code_name_charset "0123456789abcdefghijklmnopqrstuvwxyz_%$";
  114. }
  115.  
  116. // Arithmetic expressions on enums are modular
  117. enum keyState {
  118.     RELEASE;
  119.     PRESS;
  120. }
  121. enum moveDirection {
  122.     N; // no value = symbolic = can't do arithmetic and can only be used when explicitly referenced
  123.     F 0.0;
  124.     FL 0.5;
  125.     L 1.0;
  126.     BL 1.5;
  127.     B 2.0;
  128.     BR 2.5;
  129.     R 3.0;
  130.     FR 3.5;
  131. }
  132. enum cardinalDirection {
  133.     0 F;
  134.     1 L;
  135.     2 B;
  136.     3 R;
  137. }
  138. enum socdMode {
  139.     NORMAL;
  140.     NONULL;
  141.     HITBOX;
  142.     NONBOX;
  143. }
  144.  
  145. // Variables
  146. // NOTE: Should always have a predefined/default value!
  147.  
  148. // Examples of batch creating keyed variables from enum types
  149. // bool is an example of a built-in type.
  150. // Maybe i'll add more such as ints, strings and floats with specified sizes.
  151. bool pressed[cardinalDirection] = FALSE
  152. bool final[cardinalDirection] = FALSE
  153.  
  154. //keyState currentIState = RELEASE
  155. cardinalDirection currentIDirection = F
  156. moveDirection finalDir = N
  157.  
  158. public socdMode socdMode = NONULL
  159.  
  160. // Aliases
  161. // Variables that are local to methods are mostly used to implement batch direct
  162. // conditional aliases and avoid using setter aliases to implement logic, such as in
  163. // +move[cardinalDirection]
  164. // With handleInput as an example, alias conditionals of all possible values of the
  165. // local variables' enum types will be generated
  166. // (handleInput>{F,L,B,R}>{RELEASE,PRESS}), e.g. handleInput>B>PRESS
  167. // This is done because SETTERS ARE REALLY TOUGH ON SCRIPT PERFORMANCE WITH ALL
  168. // ITS ALIAS ASSIGNMENTS
  169. // As a general rule, it is better to define and use predefined aliases instead
  170. // of relying on setter aliases when it comes to conditional logic, which is why
  171. // The first method of conditional logic is preferred.
  172.  
  173. // are set to default behaviors for debugging
  174. void sendCustomCmd (finalDir) {
  175.     // Example of console command that references a variable
  176.     public >finalDir {[echo finalDir = {finalDir}]}
  177. }
  178.  
  179. void handleInput (keyState state, cardinalDirection dir) {
  180.     // This is an example of a method/alias conditional.
  181.     // Also an example of not using an enum in order to batch define conditionals
  182.     // Also an example of nesting multiple local variables into one conditional defintion
  183.     >state>dir {
  184.         //currentIState = state;
  185.         currentIDirection = dir;
  186.         sendMoveCmd>state>dir;
  187.         pressed[dir] = state; // enum type auto casting; state is evaluated as either TRUE OR FALSE; can also be manually set with (bool) state
  188.         handleSocd>state>dir;
  189.         setDir;
  190.         sendCustomCmd;
  191.     }
  192. }
  193.  
  194. // _ = no variable used, manual conditional definition
  195. // still benefits from not using global variables to conditionally set handleSocd
  196. // meaning no setters directly set hancdleSocd
  197. // meaning handleSocd can't be called directly
  198. // meaning the conditionals (handleSocd>RELEASE, etc.) must be called directly
  199. void handleSocd (keyState _) {
  200.     >RELEASE (cardinalDirection dir) {
  201.         >dir (pressed[dir+2]) { // if no enum type is specified, assume the reference of a global variable
  202.             >FALSE {
  203.                 final[dir] = FALSE;
  204.             }
  205.             >TRUE {
  206.                 final[dir] = FALSE;
  207.                 final[dir+2] = TRUE;
  208.                 // This is why setDir doesn't use a local variable
  209.                 // Makes the upcoming "setDir" process currentIDirection as the press of the opposite direction
  210.                 //currentIState = PRESS // This part is unnecessary actually
  211.                 currentIDirection = dir+2;
  212.                 sendMoveCmd>PRESS>dir+2;
  213.             }
  214.         }
  215.     }
  216.     >PRESS (cardinalDirection dir) {
  217.         >dir (pressed[dir+2]) {
  218.             >FALSE {
  219.                 final[dir] = TRUE;
  220.             }
  221.             >TRUE {
  222.                 handleSocdMode>dir;
  223.             }
  224.         }
  225.     }
  226. }
  227.  
  228. void handleSocdMode (cardinalDirection dir) {
  229.     >dir (moveMode) {
  230.         >NORMAL {
  231.             final[dir+2] = FALSE;
  232.             final[dir] = FALSE;
  233.         }
  234.         >NONULL {
  235.             final[dir+2] = FALSE;
  236.             sendMoveCmd>RELEASE>dir+2;
  237.             final[dir] = TRUE;
  238.         }
  239.         >HITBOX {
  240.             // Example of an anonymous conditional function
  241.             lambda (dir) {
  242.                 >F, >B {
  243.                     final[F] = TRUE
  244.                     final[B] = FALSE
  245.                     sendMoveCmd>PRESS>F
  246.                     sendMoveCmd>RELEASE>B
  247.                     currentIDirection = F
  248.                 }
  249.                 // First example of default case
  250.                 >... {handleSocdMode>dir>NORMAL}
  251.             }
  252.         }
  253.         >NONBOX {
  254.             // Example of an anonymous conditional function
  255.             lambda (dir) {
  256.                 >F, >B {
  257.                     final[F] = TRUE
  258.                     final[B] = FALSE
  259.                     sendMoveCmd>PRESS>F
  260.                 }
  261.                 // First example of default case
  262.                 >... {handleSocdMode>dir>NONULL}
  263.             }
  264.         }
  265.     }
  266. }
  267.  
  268. void setDir (currentIDirection) {
  269.     // Example of a global variable batch defining conditionals for
  270.     // expressions referencing it to work
  271.     >currentIDirection (final[currentIDirection]) {
  272.         >FALSE (final[currentIDirection+1], final[currentIDirection+3]) {
  273.             >FALSE>FALSE {finalDir = N}
  274.             >FALSE>TRUE  {finalDir = {currentIDirection + 3}} // auto cast
  275.             >TRUE >FALSE {finalDir = {currentIDirection + 1}} // auto cast
  276.             >TRUE >TRUE  {finalDir = N}
  277.         }
  278.         >TRUE (final[currentIDirection+1], final[currentIDirection+3]) {
  279.             >FALSE>FALSE {finalDir = currentIDirection}
  280.             // Example of the use of a function in an expression
  281.             // e.g. if currentIDirection is R, then this evaluates to BR
  282.             >FALSE>TRUE  {finalDir = diagonalDir>R>currentIDirection}
  283.             // e.g. if currentIDirection is B, then this also evaluates to BR
  284.             >TRUE >FALSE {finalDir = diagonalDir>L>currentIDirection}
  285.             >TRUE >TRUE  {finalDir = currentIDirection}
  286.         }
  287.     }
  288. }
  289.  
  290. // Script methods that return nothing are simply actual aliases. Methods that
  291. // do return a value, are a special case.
  292. // If it simply returns a value and/or interacts with variables in a read-only
  293. // manner, it acts as a function that is used by the script generator to
  294. // determine and evaluate the returned value.
  295. // If it is a similar case but it also performs actual operations on methods and
  296. // variables, then it is both an actual alias and a function. If the method is
  297. // invoked in an expression of a variable assignment, the script generator will
  298. // evaluate it as the execution of the alias and, simultaneously, the assignment
  299. // of said variable to the returned value. This means that NO SETTERS THAT
  300. // INCLUDE THE FUNCTION IN ANY WAY ARE DEFINED (e.g. MOVEP.finalDir=diagonalDir>L>F).
  301. // SETTERS ARE SIMPLE DECLARATIONS OF A VARIABLE TO EVERY POSSIBLE VALUE OF ITS
  302. // ENUM TYPE.
  303. // In this case, it is simply a function that serves readability.
  304. moveDirection diagonalDir (cardinalDirection _) {
  305.     >L (cardinalDirection dir) {return dir + 0.5} // auto cast
  306.     >R (cardinalDirection dir) {return dir - 0.5} // auto cast
  307. }
  308.  
  309. void sendMoveCmd (keyState _) {
  310.     >RELEASE (cardinalDirection _) {
  311.         // examples of direct console commands
  312.         >F {[-forward]}
  313.         >B {[-back]}
  314.         >L {[-moveleft]}
  315.         >R {[-moveright]}
  316.     }
  317.     >PRESS (cardinalDirection _) {
  318.         >F {[+forward]}
  319.         >B {[+back]}
  320.         >L {[+moveleft]}
  321.         >R {[+moveright]}
  322.     }
  323. }
  324.  
  325. // An example of a bifurcated/bind alias
  326. // In the actual CFG script, the +/- should always be the first character in
  327. // the alias, so it will start ahead of the script name in order to work in
  328. // keybindings. (i.e. "+MOVEP.move>F" instead of "MOVEP.+moveF")
  329. // NOTE: Bifurcated aliases are always public, since... you need them in order
  330. // to bind them to keys, DUH!
  331. bind move {
  332.     // Return types are defined for both press (+) and release (-)
  333.     // NOTE: For this alias, it can be referenced as "+move" or "-move"
  334.     // in other parts of this script definition (but it's not, though).
  335.     void + (cardinalDirection dir) {handleInput>PRESS>dir}
  336.     void - (cardinalDirection dir) {handleInput>RELEASE>dir}
  337. }
  338.  
  339. // Possible generation optimizations/features:
  340. // - If an alias calls another that has no dependence on a variable, like
  341. //   a conditional, then the alias can just evaluate it as the entire logic of
  342. //   the other to avoid alias calls. I could see this in sendMoveCmd, move, and
  343. //   the default case in handleSocdMode>dir>HITBOX. This would make the alias
  344. //   a function, lowering the alias count. This could also be done for setters
  345. //   setting an alias to a conditional with only one line of logic with no spaces.
  346. // - Warn for unused variables and aliases (already one in the form of
  347. //   currentIState)
  348. // - Public variable values menu with variable and value descriptions?
  349. //   (Public alias menu not possible tho)
  350. // - Logic in aliases that come before or after its conditionals will end up
  351. //   before or after all places where the alias is called. However, this cannot
  352. //   be done for variable-dependent logic.
Advertisement
Add Comment
Please, Sign In to add comment