From 076c9eae79179cd1e751ae8d132c7ffcf4edfba3 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Tue, 4 Oct 2022 03:51:00 +0700 Subject: [PATCH] Change "feature" command to support new AcediaCore features This patch does two things: 1. Makes command use new parameter type JSON instead of remainder, simplifying command's code; 2. Makes command rely on auto-resolving feature aliases. --- sources/Commands/ACommandFeature.uc | 56 ++++++++++++++--------------- sources/Tools/PendingConfigsTool.uc | 22 ++++-------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/sources/Commands/ACommandFeature.uc b/sources/Commands/ACommandFeature.uc index 16ed03c..13e63fc 100644 --- a/sources/Commands/ACommandFeature.uc +++ b/sources/Commands/ACommandFeature.uc @@ -46,44 +46,44 @@ protected function BuildData(CommandDataBuilder builder) .Summary(P("Managing features.")) .Describe(P("Command for managing features and their configs.")); builder.SubCommand(P("enable")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .OptionalParams() .ParamText(P("config")) .Describe(P("Enables specified . If isn't specified -" @ "choses the \"default\" one, making new config with default" @ "settings if it doesn't exist.")); builder.SubCommand(P("disable")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .Describe(P("Disables specified .")); builder.SubCommand(P("showconf")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .OptionalParams() .ParamText(P("config")) .Describe(P("Show given for the given .")); builder.SubCommand(P("editconf")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .ParamText(P("config")) .ParamText(P("variable_path")) - .ParamRemainder(P("value")) + .ParamJSON(P("value")) .Describe(P("Changes a value inside given of the given" @ " by setting value at JSON path to" @ "the JSON value . Changes won't be immediately applied to" @ "the game and kept as pending.")); builder.SubCommand(P("saveconf")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .ParamText(P("config")) .Describe(P("Saves pending changes for the given of the given" @ ".")); builder.SubCommand(P("newconf")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .ParamText(P("config")) .Describe(P("Creates new config for the given .")); builder.SubCommand(P("removeconf")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .ParamText(P("config")) .Describe(P("Removes specified of the specified .")); builder.SubCommand(P("autoconf")) - .ParamText(P("feature")) + .ParamText(P("feature"),, P("feature")) .OptionalParams() .ParamText(P("config")) .Describe(P("Changes current auto config config of the specified" @@ -124,7 +124,7 @@ protected function Executed(CallData arguments, EPlayer instigator) { EditFeatureConfig( arguments.parameters.GetText(P("variable_path")), - arguments.parameters.GetText(P("value")), + arguments.parameters.GetItem(P("value")), saveFlag); } else if (arguments.subCommandName.Compare(P("saveconf"))) { @@ -145,14 +145,14 @@ protected function Executed(CallData arguments, EPlayer instigator) protected function SelectFeatureAndConfig(CallData arguments) { - local Text userGivenFeatureName, userGivenConfigName; + local Text featureClassName, userGivenConfigName; - userGivenFeatureName = arguments.parameters.GetText(P("feature")); - selectedFeatureClass = LoadFeatureClass(userGivenFeatureName); + featureClassName = arguments.parameters.GetText(P("feature")); + selectedFeatureClass = LoadFeatureClass(featureClassName); if (selectedFeatureClass == none && !arguments.subCommandName.IsEmpty()) { return; } - _.memory.Free(userGivenFeatureName); + _.memory.Free(featureClassName); userGivenConfigName = arguments.parameters.GetText(P("config")); if (userGivenConfigName != none) { @@ -313,24 +313,17 @@ protected function Text PickConfigBasedOnParameter() return resolvedConfig; } -protected function class LoadFeatureClass(BaseText featureName) +protected function class LoadFeatureClass(BaseText featureClassName) { - local Text featureClassName; - local class featureClass; - if (featureName == none) { + local class featureClass; + + if (featureClassName == none) { return none; } - if (featureName.StartsWith(P("$"))) { - featureClassName = _.alias.ResolveFeature(featureName, true); - } - else { - featureClassName = featureName.Copy(); - } featureClass = class(_.memory.LoadClass(featureClassName)); if (featureClass == none) { - announcer.AnnounceFailedToLoadFeatureClass(featureName); + announcer.AnnounceFailedToLoadFeatureClass(featureClassName); } - _.memory.Free(featureClassName); return featureClass; } @@ -430,14 +423,17 @@ protected function MutableText PrettyPrintValueAt(BaseText pathToValue) } protected function EditFeatureConfig( - BaseText pathToValue, - BaseText newValue, - bool saveConfig) + BaseText pathToValue, + AcediaObject newValue, + bool saveConfig) { local MutableText printedOldValue; local MutableText printedNewValue; local PendingConfigsTool.PendingConfigToolResult error; + if (selectedFeatureClass == none) { + return; + } printedOldValue = PrettyPrintValueAt(pathToValue); error = pendingConfigs.EditConfig(pathToValue, newValue); if (error == PCTE_None) { @@ -478,6 +474,8 @@ protected function EditFeatureConfig( } _.memory.Free(printedOldValue); _.memory.Free(printedNewValue); + _.memory.Free(pathToValue); + _.memory.Free(newValue); } protected function SaveFeatureConfig() diff --git a/sources/Tools/PendingConfigsTool.uc b/sources/Tools/PendingConfigsTool.uc index b938747..d8b875d 100644 --- a/sources/Tools/PendingConfigsTool.uc +++ b/sources/Tools/PendingConfigsTool.uc @@ -185,13 +185,11 @@ public function HashTable GetPendingConfigData(optional bool createIfMissing) * Any changes are made iff result is `PCTE_None`. */ public function PendingConfigToolResult EditConfig( - BaseText pathToValue, - BaseText newValue) + BaseText pathToValue, + AcediaObject newValue) { local HashTable pendingData; local JSONPointer pointer; - local Parser parser; - local AcediaObject newValueAsJSON; local PendingConfigToolResult result; if (pathToValue == none) { @@ -201,20 +199,11 @@ public function PendingConfigToolResult EditConfig( if (pendingData == none) { return PCTE_ConfigMissing; } - // Get guaranteed not-`none` JSON value, treating it as JSON string - // if necessary - parser = _.text.Parse(newValue); - newValueAsJSON = _.json.ParseWith(parser); - parser.FreeSelf(); - if (newValueAsJSON == none && newValue != none) { - newValueAsJSON = newValue.Copy(); - } // Set new data pointer = _.json.Pointer(pathToValue); - result = SetItemByJSON(pendingData, pointer, newValueAsJSON); + result = SetItemByJSON(pendingData, pointer, newValue); pointer.FreeSelf(); pendingData.FreeSelf(); - _.memory.Free(newValueAsJSON); return result; } @@ -251,7 +240,10 @@ private function PendingConfigToolResult SetItemByJSON( container.FreeSelf(); return result; } - +/*EditFeatureConfig #1: true +SetItemByJSON: true +SetContainerItemByText: true +EditFeatureConfig #2: true */ private function PendingConfigToolResult SetContainerItemByText( AcediaObject container, BaseText containerIndex,