/// <summary> /// Creates a PropKeys struct from the given keyframes /// </summary> static StructValue MakeAnimProps(string drivenProp, List <Tuple <float, string> > frames) { var propkeys = DTX.FromDtaString( "(keys ()) " + "(interpolation 0) " + $"(driven_prop (0 0 RBVenueAuthoring 0 1 {drivenProp}))"); var keyframes = propkeys.Array("keys").Array(1); foreach (var(frame, key) in frames) { var keyframe = new DataArray(); keyframe.AddNode(new DataAtom(frame)); keyframe.AddNode(DataSymbol.Symbol(key)); keyframes.AddNode(keyframe); } return(StructValue.FromData(propKeysType, propkeys)); }
public static Value FromData(Type t, DataNode d) { var atom = d as DataAtom; var arr = d as DataArray; switch (t.InternalType) { case DataType.Float: return(new FloatValue(atom.Float)); case DataType.Int32: return(new IntValue(atom.Int)); case DataType.Uint8: return(new ByteValue((byte)atom.Int)); case DataType.Uint32: return(new UIntValue((uint)atom.Int)); case DataType.Uint64: return(new LongValue(atom.Int)); case DataType.Bool: return(new BoolValue(atom.Int != 0)); case DataType.Symbol: return(new SymbolValue(d.ToString())); case DataType.ResourcePath: return(new ResourcePathValue(d.ToString())); case DataType.Struct: return(StructValue.FromData(t as StructType, arr)); case DataType.DrivenProp: return(DrivenProp.FromData(arr)); default: if (t is ArrayType at) { return(ArrayValue.FromData(at, arr)); } throw new Exception("Unhandled case (TODO)"); } }
static GameObject[] ExtractVenuePropAnimsFromMidi(MidiFile mf) { var objs = new List <GameObject>(); short index = 1; var editorCom = new Component { Rev = 3, Name1 = "Editor", Name2 = "Editor", Unknown2 = 2, Props = new[] { new Property("capabilities", new UIntValue(62)) } }; objs.Add(new GameObject { Id = new GameObjectId { Index = 0, Layer = 0 }, Rev = 2, Name = "root", Components = new[] { editorComponent, entityHeaderComponent, new Component { Rev = 3, Name1 = "PropAnim", Name2 = "PropAnim", Unknown2 = 0, Props = StructValue.FromData( StructType.FromData(DTX.FromDtaString( @"(props (frame_range_start float) (frame_range_end float) (time_units int) (is_looping bool))")), DTX.FromDtaString( @"(frame_range_start 3.402823E+38) (frame_range_end -3.402823E+38) (time_units 0) (is_looping 0)")).Props } } }); var tracks = new Midi.MidiHelper().ProcessTracks(mf); var partMap = new Dictionary <string, string> { { "PART BASS", "bass_intensity" }, { "PART GUITAR", "guitar_intensity" }, { "PART DRUMS", "drum_intensity" }, { "PART VOCALS", "mic_intensity" }, #if DEBUG { "PART KEYS", "keyboard_intensity" }, #endif }; var intensityMap = new Dictionary <string, string> { // All { "[idle_realtime]", "idle_realtime" }, { "[idle]", "idle" }, { "[idle_intense]", "idle_intense" }, { "[play]", "play" }, { "[mellow]", "mellow" }, { "[intense]", "intense" }, // Guitar/bass only { "[play_solo]", "play_solo" }, // Vocal only { "[tambourine_start]", "tambourine_start" }, { "[tambourine_end]", "tambourine_end" }, { "[cowbell_start]", "cowbell_start" }, { "[cowbell_end]", "cowbell_end" }, { "[clap_start]", "clap_start" }, { "[clap_end]", "clap_end" }, // Drum only { "[ride_side_true]", "ride_side_true" }, { "[ride_side_false]", "ride_side_false" }, }; void AddAnimTrack(StructValue props) { objs.Add(new GameObject { Id = new GameObjectId { Index = index, Layer = index++ }, Rev = 2, Name = "Keys type 11", Components = new[] { editorCom, new Component { Rev = 3, Name1 = "PropKeysSymCom", Name2 = "PropKeys", Unknown2 = 0, Props = props.Props } } }); } StructValue MakeAnimProps(string drivenProp, List <Tuple <float, string> > frames) { var propkeys = DTX.FromDtaString( "(keys ()) " + "(interpolation 0) " + $"(driven_prop (0 0 RBVenueAuthoring 0 1 {drivenProp}))"); var keyframes = propkeys.Array("keys").Array(1); foreach (var(frame, key) in frames) { var keyframe = new DataArray(); keyframe.AddNode(new DataAtom(frame)); keyframe.AddNode(DataSymbol.Symbol(key)); keyframes.AddNode(keyframe); } return(StructValue.FromData(propKeysType, propkeys)); } foreach (var track in tracks) { if (!partMap.ContainsKey(track.Name)) { continue; } var frames = new List <Tuple <float, string> >(); foreach (var n in track.Items) { if (n is Midi.MidiText t) { if (intensityMap.ContainsKey(t.Text)) { frames.Add(Tuple.Create((float)n.StartTicks / mf.TicksPerQN, intensityMap[t.Text])); } } } AddAnimTrack(MakeAnimProps(partMap[track.Name], frames)); } AddAnimTrack(MakeAnimProps("shot_bg", new List <Tuple <float, string> > { Tuple.Create(0f, "coop_all_far") })); AddAnimTrack(MakeAnimProps("shot_bk", new List <Tuple <float, string> > { Tuple.Create(0f, "coop_all_far") })); AddAnimTrack(MakeAnimProps("shot_gk", new List <Tuple <float, string> > { Tuple.Create(0f, "coop_all_far") })); AddAnimTrack(MakeAnimProps("crowd", new List <Tuple <float, string> > { Tuple.Create(0f, "crowd_realtime") })); AddAnimTrack(MakeAnimProps("world_event", new List <Tuple <float, string> > { Tuple.Create(0f, "none") })); //AddAnimTrack(MakeAnimProps("part2_sing", new List<Tuple<float, string>> {Tuple.Create(0f, "singalong_off") })); //AddAnimTrack(MakeAnimProps("part3_sing", new List<Tuple<float, string>> {Tuple.Create(0f, "singalong_off") })); //AddAnimTrack(MakeAnimProps("part4_sing", new List<Tuple<float, string>> {Tuple.Create(0f, "singalong_off") })); AddAnimTrack(MakeAnimProps("lightpreset", new List <Tuple <float, string> > { Tuple.Create(0f, "silhouettes") })); AddAnimTrack(MakeAnimProps("postproc", new List <Tuple <float, string> > { Tuple.Create(0f, "profilm_a") })); AddAnimTrack(MakeAnimProps("lightpreset_keyframe", new List <Tuple <float, string> > { Tuple.Create(0f, "next") })); AddAnimTrack(MakeAnimProps("spot_bass", new List <Tuple <float, string> > { Tuple.Create(0f, "off") })); AddAnimTrack(MakeAnimProps("spot_guitar", new List <Tuple <float, string> > { Tuple.Create(0f, "off") })); AddAnimTrack(MakeAnimProps("spot_drums", new List <Tuple <float, string> > { Tuple.Create(0f, "off") })); //AddAnimTrack(MakeAnimProps("spot_keyboard", new List<Tuple<float, string>> {Tuple.Create(0f, "off") })); AddAnimTrack(MakeAnimProps("spot_vocal", new List <Tuple <float, string> > { Tuple.Create(0f, "off") })); //AddAnimTrack(MakeAnimProps("shot_5", new List<Tuple<float, string>> {Tuple.Create(0f, "coop_all_far") })); AddAnimTrack(MakeAnimProps("stagekit_fog", new List <Tuple <float, string> > { Tuple.Create(0f, "off") })); return(objs.ToArray()); }
static GameObject[] ExtractVenuePropAnimsFromMidi(MidiFile mf) { var objs = new List <GameObject>(); short index = 1; var editorCom = new Component { Rev = 3, Name1 = "Editor", Name2 = "Editor", Unknown2 = 2, Props = new[] { new Property("capabilities", new UIntValue(62)) } }; objs.Add(new GameObject { Id = new GameObjectId { Index = 0, Layer = 0 }, Rev = 2, Name = "root", Components = new[] { editorComponent, entityHeaderComponent, new Component { Rev = 3, Name1 = "PropAnim", Name2 = "PropAnim", Unknown2 = 0, Props = StructValue.FromData( StructType.FromData(DTX.FromDtaString( @"(props (frame_range_start float) (frame_range_end float) (time_units int) (is_looping bool))")), DTX.FromDtaString( @"(frame_range_start 3.402823E+38) (frame_range_end -3.402823E+38) (time_units 0) (is_looping 0)")).Props } } }); void AddAnimTrack(StructValue props) { objs.Add(new GameObject { Id = new GameObjectId { Index = index, Layer = index++ }, Rev = 2, Name = "Keys type 11", Components = new[] { editorCom, new Component { Rev = 3, Name1 = "PropKeysSymCom", Name2 = "PropKeys", Unknown2 = 0, Props = props.Props } } }); } foreach (var kv in ExtractPlayerIntensities(mf)) { AddAnimTrack(MakeAnimProps(kv.Key, kv.Value)); } foreach (var kv in ExtractVenueAnims(mf)) { AddAnimTrack(MakeAnimProps(kv.Key, kv.Value)); } return(objs.ToArray()); }