Browse Source

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.
develop
Anton Tarasenko 2 years ago
parent
commit
076c9eae79
  1. 56
      sources/Commands/ACommandFeature.uc
  2. 22
      sources/Tools/PendingConfigsTool.uc

56
sources/Commands/ACommandFeature.uc

@ -46,44 +46,44 @@ protected function BuildData(CommandDataBuilder builder)
.Summary(P("Managing features.")) .Summary(P("Managing features."))
.Describe(P("Command for managing features and their configs.")); .Describe(P("Command for managing features and their configs."));
builder.SubCommand(P("enable")) builder.SubCommand(P("enable"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.OptionalParams() .OptionalParams()
.ParamText(P("config")) .ParamText(P("config"))
.Describe(P("Enables specified <feature>. If <config> isn't specified -" .Describe(P("Enables specified <feature>. If <config> isn't specified -"
@ "choses the \"default\" one, making new config with default" @ "choses the \"default\" one, making new config with default"
@ "settings if it doesn't exist.")); @ "settings if it doesn't exist."));
builder.SubCommand(P("disable")) builder.SubCommand(P("disable"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.Describe(P("Disables specified <feature>.")); .Describe(P("Disables specified <feature>."));
builder.SubCommand(P("showconf")) builder.SubCommand(P("showconf"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.OptionalParams() .OptionalParams()
.ParamText(P("config")) .ParamText(P("config"))
.Describe(P("Show given <config> for the given <feature>.")); .Describe(P("Show given <config> for the given <feature>."));
builder.SubCommand(P("editconf")) builder.SubCommand(P("editconf"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.ParamText(P("config")) .ParamText(P("config"))
.ParamText(P("variable_path")) .ParamText(P("variable_path"))
.ParamRemainder(P("value")) .ParamJSON(P("value"))
.Describe(P("Changes a value inside given <config> of the given" .Describe(P("Changes a value inside given <config> of the given"
@ "<feature> by setting value at JSON path <variable_path> to" @ "<feature> by setting value at JSON path <variable_path> to"
@ "the JSON value <value>. Changes won't be immediately applied to" @ "the JSON value <value>. Changes won't be immediately applied to"
@ "the game and kept as pending.")); @ "the game and kept as pending."));
builder.SubCommand(P("saveconf")) builder.SubCommand(P("saveconf"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.ParamText(P("config")) .ParamText(P("config"))
.Describe(P("Saves pending changes for the given <config> of the given" .Describe(P("Saves pending changes for the given <config> of the given"
@ "<feature>.")); @ "<feature>."));
builder.SubCommand(P("newconf")) builder.SubCommand(P("newconf"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.ParamText(P("config")) .ParamText(P("config"))
.Describe(P("Creates new config for the given <feature>.")); .Describe(P("Creates new config for the given <feature>."));
builder.SubCommand(P("removeconf")) builder.SubCommand(P("removeconf"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.ParamText(P("config")) .ParamText(P("config"))
.Describe(P("Removes specified <config> of the specified <feature>.")); .Describe(P("Removes specified <config> of the specified <feature>."));
builder.SubCommand(P("autoconf")) builder.SubCommand(P("autoconf"))
.ParamText(P("feature")) .ParamText(P("feature"),, P("feature"))
.OptionalParams() .OptionalParams()
.ParamText(P("config")) .ParamText(P("config"))
.Describe(P("Changes current auto config config of the specified" .Describe(P("Changes current auto config config of the specified"
@ -124,7 +124,7 @@ protected function Executed(CallData arguments, EPlayer instigator)
{ {
EditFeatureConfig( EditFeatureConfig(
arguments.parameters.GetText(P("variable_path")), arguments.parameters.GetText(P("variable_path")),
arguments.parameters.GetText(P("value")), arguments.parameters.GetItem(P("value")),
saveFlag); saveFlag);
} }
else if (arguments.subCommandName.Compare(P("saveconf"))) { else if (arguments.subCommandName.Compare(P("saveconf"))) {
@ -145,14 +145,14 @@ protected function Executed(CallData arguments, EPlayer instigator)
protected function SelectFeatureAndConfig(CallData arguments) protected function SelectFeatureAndConfig(CallData arguments)
{ {
local Text userGivenFeatureName, userGivenConfigName; local Text featureClassName, userGivenConfigName;
userGivenFeatureName = arguments.parameters.GetText(P("feature")); featureClassName = arguments.parameters.GetText(P("feature"));
selectedFeatureClass = LoadFeatureClass(userGivenFeatureName); selectedFeatureClass = LoadFeatureClass(featureClassName);
if (selectedFeatureClass == none && !arguments.subCommandName.IsEmpty()) { if (selectedFeatureClass == none && !arguments.subCommandName.IsEmpty()) {
return; return;
} }
_.memory.Free(userGivenFeatureName); _.memory.Free(featureClassName);
userGivenConfigName = arguments.parameters.GetText(P("config")); userGivenConfigName = arguments.parameters.GetText(P("config"));
if (userGivenConfigName != none) if (userGivenConfigName != none)
{ {
@ -313,24 +313,17 @@ protected function Text PickConfigBasedOnParameter()
return resolvedConfig; return resolvedConfig;
} }
protected function class<Feature> LoadFeatureClass(BaseText featureName) protected function class<Feature> LoadFeatureClass(BaseText featureClassName)
{ {
local Text featureClassName; local class<Feature> featureClass;
local class<Feature> featureClass;
if (featureName == none) { if (featureClassName == none) {
return none; return none;
} }
if (featureName.StartsWith(P("$"))) {
featureClassName = _.alias.ResolveFeature(featureName, true);
}
else {
featureClassName = featureName.Copy();
}
featureClass = class<Feature>(_.memory.LoadClass(featureClassName)); featureClass = class<Feature>(_.memory.LoadClass(featureClassName));
if (featureClass == none) { if (featureClass == none) {
announcer.AnnounceFailedToLoadFeatureClass(featureName); announcer.AnnounceFailedToLoadFeatureClass(featureClassName);
} }
_.memory.Free(featureClassName);
return featureClass; return featureClass;
} }
@ -430,14 +423,17 @@ protected function MutableText PrettyPrintValueAt(BaseText pathToValue)
} }
protected function EditFeatureConfig( protected function EditFeatureConfig(
BaseText pathToValue, BaseText pathToValue,
BaseText newValue, AcediaObject newValue,
bool saveConfig) bool saveConfig)
{ {
local MutableText printedOldValue; local MutableText printedOldValue;
local MutableText printedNewValue; local MutableText printedNewValue;
local PendingConfigsTool.PendingConfigToolResult error; local PendingConfigsTool.PendingConfigToolResult error;
if (selectedFeatureClass == none) {
return;
}
printedOldValue = PrettyPrintValueAt(pathToValue); printedOldValue = PrettyPrintValueAt(pathToValue);
error = pendingConfigs.EditConfig(pathToValue, newValue); error = pendingConfigs.EditConfig(pathToValue, newValue);
if (error == PCTE_None) { if (error == PCTE_None) {
@ -478,6 +474,8 @@ protected function EditFeatureConfig(
} }
_.memory.Free(printedOldValue); _.memory.Free(printedOldValue);
_.memory.Free(printedNewValue); _.memory.Free(printedNewValue);
_.memory.Free(pathToValue);
_.memory.Free(newValue);
} }
protected function SaveFeatureConfig() protected function SaveFeatureConfig()

22
sources/Tools/PendingConfigsTool.uc

@ -185,13 +185,11 @@ public function HashTable GetPendingConfigData(optional bool createIfMissing)
* Any changes are made iff result is `PCTE_None`. * Any changes are made iff result is `PCTE_None`.
*/ */
public function PendingConfigToolResult EditConfig( public function PendingConfigToolResult EditConfig(
BaseText pathToValue, BaseText pathToValue,
BaseText newValue) AcediaObject newValue)
{ {
local HashTable pendingData; local HashTable pendingData;
local JSONPointer pointer; local JSONPointer pointer;
local Parser parser;
local AcediaObject newValueAsJSON;
local PendingConfigToolResult result; local PendingConfigToolResult result;
if (pathToValue == none) { if (pathToValue == none) {
@ -201,20 +199,11 @@ public function PendingConfigToolResult EditConfig(
if (pendingData == none) { if (pendingData == none) {
return PCTE_ConfigMissing; 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 // Set new data
pointer = _.json.Pointer(pathToValue); pointer = _.json.Pointer(pathToValue);
result = SetItemByJSON(pendingData, pointer, newValueAsJSON); result = SetItemByJSON(pendingData, pointer, newValue);
pointer.FreeSelf(); pointer.FreeSelf();
pendingData.FreeSelf(); pendingData.FreeSelf();
_.memory.Free(newValueAsJSON);
return result; return result;
} }
@ -251,7 +240,10 @@ private function PendingConfigToolResult SetItemByJSON(
container.FreeSelf(); container.FreeSelf();
return result; return result;
} }
/*EditFeatureConfig #1: true
SetItemByJSON: true
SetContainerItemByText: true
EditFeatureConfig #2: true */
private function PendingConfigToolResult SetContainerItemByText( private function PendingConfigToolResult SetContainerItemByText(
AcediaObject container, AcediaObject container,
BaseText containerIndex, BaseText containerIndex,

Loading…
Cancel
Save