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. 50
      sources/Commands/ACommandFeature.uc
  2. 20
      sources/Tools/PendingConfigsTool.uc

50
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 <feature>. If <config> 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 <feature>."));
builder.SubCommand(P("showconf"))
.ParamText(P("feature"))
.ParamText(P("feature"),, P("feature"))
.OptionalParams()
.ParamText(P("config"))
.Describe(P("Show given <config> for the given <feature>."));
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 <config> of the given"
@ "<feature> by setting value at JSON path <variable_path> to"
@ "the JSON value <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 <config> of the given"
@ "<feature>."));
builder.SubCommand(P("newconf"))
.ParamText(P("feature"))
.ParamText(P("feature"),, P("feature"))
.ParamText(P("config"))
.Describe(P("Creates new config for the given <feature>."));
builder.SubCommand(P("removeconf"))
.ParamText(P("feature"))
.ParamText(P("feature"),, P("feature"))
.ParamText(P("config"))
.Describe(P("Removes specified <config> of the specified <feature>."));
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<Feature> LoadFeatureClass(BaseText featureName)
protected function class<Feature> LoadFeatureClass(BaseText featureClassName)
{
local Text featureClassName;
local class<Feature> featureClass;
if (featureName == none) {
if (featureClassName == none) {
return none;
}
if (featureName.StartsWith(P("$"))) {
featureClassName = _.alias.ResolveFeature(featureName, true);
}
else {
featureClassName = featureName.Copy();
}
featureClass = class<Feature>(_.memory.LoadClass(featureClassName));
if (featureClass == none) {
announcer.AnnounceFailedToLoadFeatureClass(featureName);
announcer.AnnounceFailedToLoadFeatureClass(featureClassName);
}
_.memory.Free(featureClassName);
return featureClass;
}
@ -431,13 +424,16 @@ protected function MutableText PrettyPrintValueAt(BaseText pathToValue)
protected function EditFeatureConfig(
BaseText pathToValue,
BaseText newValue,
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()

20
sources/Tools/PendingConfigsTool.uc

@ -186,12 +186,10 @@ public function HashTable GetPendingConfigData(optional bool createIfMissing)
*/
public function PendingConfigToolResult EditConfig(
BaseText pathToValue,
BaseText newValue)
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,

Loading…
Cancel
Save