private void LoadBodyPreset(BodyPreset preset) { _presetName = preset.Name; foreach (var slotName in Template.Slots.Keys) { // For each slot in our BodyManagerComponent's template, // try and grab what the ID of what the preset says should be inside it. if (!preset.PartIDs.TryGetValue(slotName, out var partId)) { // If the preset doesn't define anything for it, continue. continue; } // Get the BodyPartPrototype corresponding to the BodyPart ID we grabbed. if (!_prototypeManager.TryIndex(partId, out BodyPartPrototype newPartData)) { throw new InvalidOperationException($"No {nameof(BodyPartPrototype)} prototype found with ID {partId}"); } // Try and remove an existing limb if that exists. RemoveBodyPart(slotName, false); // Add a new BodyPart with the BodyPartPrototype as a baseline to our // BodyComponent. var addedPart = new BodyPart(newPartData); TryAddPart(slotName, addedPart); } OnBodyChanged(); // TODO: Duplicate code }
public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); serializer.DataReadWriteFunction( "baseTemplate", "bodyTemplate.Humanoid", template => { if (!_prototypeManager.TryIndex(template, out BodyTemplatePrototype prototype)) { // Invalid prototype throw new InvalidOperationException( $"No {nameof(BodyTemplatePrototype)} found with name {template}"); } Template = new BodyTemplate(); Template.Initialize(prototype); }, () => Template.Name); serializer.DataReadWriteFunction( "basePreset", "bodyPreset.BasicHuman", preset => { if (!_prototypeManager.TryIndex(preset, out BodyPresetPrototype prototype)) { // Invalid prototype throw new InvalidOperationException( $"No {nameof(BodyPresetPrototype)} found with name {preset}"); } Preset = new BodyPreset(); Preset.Initialize(prototype); }, () => _presetName); }