From 98c6d47d73abfad32eb32520531c887d34bb31ed Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 27 Sep 2022 23:04:34 -0700 Subject: big code dump Summary: added generator for animations and FX layer. * add generate_animations.sh * generates an animation for every cell (14*6=72) and every letter (60); 72*60 = 4212 total animations * add generate_fx.py * seems to work in-game * drives every parameter needed * add {group,cell}_names.txt * name of every group & cell parameter * the STT has 72 individual character slots called cells. They are grouped into 4-character groups to save on parameter bandwidth. Thus each slot may be indexed with 8 bits. * add SetLetters.cs * this thingy looks at each group parameter and uses it to set each cell parameter. The generated fx layer hooks the script in. * check in SDK-generated assets as references until code generators are complete --- SetLetters.cs | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 SetLetters.cs (limited to 'SetLetters.cs') diff --git a/SetLetters.cs b/SetLetters.cs new file mode 100644 index 0000000..c14fe31 --- /dev/null +++ b/SetLetters.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// Expands a list of 4-byte parameters into a longer list of (effectively) +// 1-byte parameters. The 1-byte parameters are easier to use in an animation +// layer, since we can write conditions for them. +[SharedBetweenAnimators] +public class SetLetters : StateMachineBehaviour +{ + Dictionary letters_; + List cell_parameters_; + List group_parameters_; + + int GetLetterFromGroup(int g, int which) + { + return (((g & (0x000000FF << (which * 8))) >> (which * 8)) & 0x000000FF); + } + + // This function is called in 2 contexts: + // 1. animator.parameters contains everything we need. Updating params is not + // reflected in emulator. + // 2. animator.parameters contains nothing we need. Updating params is + // reflected in emulator. + override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) + { + if (letters_ == null) { + letters_ = new Dictionary(); + } + + // I don't know why or how but Unity fucking refuses to save this variable, + // so reinitialize it every time, YOLO. + cell_parameters_ = new List { + "_Letter_Row00_Col00", + "_Letter_Row00_Col01", + "_Letter_Row00_Col02", + "_Letter_Row00_Col03", + "_Letter_Row00_Col04", + "_Letter_Row00_Col05", + "_Letter_Row00_Col06", + "_Letter_Row00_Col07", + "_Letter_Row00_Col08", + "_Letter_Row00_Col09", + "_Letter_Row00_Col10", + "_Letter_Row00_Col11", + "_Letter_Row00_Col12", + "_Letter_Row00_Col13", + "_Letter_Row01_Col00", + "_Letter_Row01_Col01", + "_Letter_Row01_Col02", + "_Letter_Row01_Col03", + "_Letter_Row01_Col04", + "_Letter_Row01_Col05", + "_Letter_Row01_Col06", + "_Letter_Row01_Col07", + "_Letter_Row01_Col08", + "_Letter_Row01_Col09", + "_Letter_Row01_Col10", + "_Letter_Row01_Col11", + "_Letter_Row01_Col12", + "_Letter_Row01_Col13", + "_Letter_Row02_Col00", + "_Letter_Row02_Col01", + "_Letter_Row02_Col02", + "_Letter_Row02_Col03", + "_Letter_Row02_Col04", + "_Letter_Row02_Col05", + "_Letter_Row02_Col06", + "_Letter_Row02_Col07", + "_Letter_Row02_Col08", + "_Letter_Row02_Col09", + "_Letter_Row02_Col10", + "_Letter_Row02_Col11", + "_Letter_Row02_Col12", + "_Letter_Row02_Col13", + }; + group_parameters_ = new List { + "_Letter_Row00_Col00_03", + "_Letter_Row00_Col04_07", + "_Letter_Row00_Col08_11", + "_Letter_Row00_Col12_13", + "_Letter_Row01_Col00_03", + "_Letter_Row01_Col04_07", + "_Letter_Row01_Col08_11", + "_Letter_Row01_Col12_13", + "_Letter_Row02_Col00_03", + "_Letter_Row02_Col04_07", + "_Letter_Row02_Col08_11", + "_Letter_Row02_Col12_13", + }; + + bool got_match = false; + foreach (var param in animator.parameters) { + if (param.name == "_Letter_Row00_Col00_03") { + got_match = true; + break; + } + } + if (!got_match) { + if (!letters_.ContainsKey(cell_parameters_[0])) { + return; + } + foreach (var param in cell_parameters_) { + animator.SetInteger(param, letters_[param]); + } + + return; + } + + int cell_idx = 0; + for (int i = 0; i < group_parameters_.Count; i++) { + string group_param = group_parameters_[i]; + int g = animator.GetInteger(group_param); + + string cell_param = cell_parameters_[cell_idx]; + letters_[cell_param] = GetLetterFromGroup(g, 0); + cell_idx += 1; + + cell_param = cell_parameters_[cell_idx]; + letters_[cell_param] = GetLetterFromGroup(g, 1); + cell_idx += 1; + + // If we're on the last group of 4 in a row, we do not look at the cells, + // since there are only 14 cells in each row. + if (i % 4 != 3) { + cell_param = cell_parameters_[cell_idx]; + letters_[cell_param] = GetLetterFromGroup(g, 2); + cell_idx += 1; + + cell_param = cell_parameters_[cell_idx]; + letters_[cell_param] = GetLetterFromGroup(g, 3); + cell_idx += 1; + } + } + } +} -- cgit v1.2.3