/** * Announcer for `ACommandFeature`. * Copyright 2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * * Acedia is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License, or * (at your option) any later version. * * Acedia is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Acedia. If not, see . */ class ACommandFeature_Announcer extends CommandAnnouncer; var private AnnouncementVariations enabledFeature, disabledFeature; var private AnnouncementVariations swappedConfig; var private AnnouncementVariations failedToLoadFeatureClass; var private AnnouncementVariations failedNoConfigProvided, failedConfigMissing; var private AnnouncementVariations failedCannotEnableFeature; var private AnnouncementVariations failedNoConfigClass; var private AnnouncementVariations failedAlreadyEnabled, failedAlreadyDisabled; protected function Finalizer() { FreeVariations(enabledFeature); FreeVariations(disabledFeature); FreeVariations(swappedConfig); FreeVariations(failedToLoadFeatureClass); FreeVariations(failedNoConfigProvided); FreeVariations(failedConfigMissing); FreeVariations(failedCannotEnableFeature); FreeVariations(failedNoConfigClass); FreeVariations(failedAlreadyEnabled); FreeVariations(failedAlreadyDisabled); super.Finalizer(); } public final function AnnounceEnabledFeature( class featureClass, BaseText configName) { local int i; local array templates; if (!enabledFeature.initialized) { enabledFeature.initialized = true; enabledFeature.toSelfReport = _.text.MakeTemplate_S( "Feature {$TextEmphasis `%1`} {$TextPositive enabled} with config" @ "\"%2\""); enabledFeature.toSelfPublic = _.text.MakeTemplate_S( "%%instigator%% {$TextPositive enabled} feature" @ "{$TextEmphasis `%1`} with config \"%2\""); } templates = MakeArray(enabledFeature); for (i = 0; i < templates.length; i += 1) { templates[i].Reset().ArgClass(featureClass).Arg(configName); } MakeAnnouncement(enabledFeature); } public final function AnnounceDisabledFeature(class featureClass) { local int i; local array templates; if (!disabledFeature.initialized) { disabledFeature.initialized = true; disabledFeature.toSelfReport = _.text.MakeTemplate_S( "Feature {$TextEmphasis `%1`} {$TextNegative disabled}"); disabledFeature.toSelfPublic = _.text.MakeTemplate_S( "%%instigator%% {$TextNegative disabled} feature" @ "{$TextEmphasis `%1`}"); } templates = MakeArray(disabledFeature); for (i = 0; i < templates.length; i += 1) { templates[i].Reset().ArgClass(featureClass); } MakeAnnouncement(disabledFeature); } public final function AnnounceSwappedConfig( class featureClass, BaseText oldConfig, BaseText newConfig) { local int i; local array templates; if (!swappedConfig.initialized) { swappedConfig.initialized = true; swappedConfig.toSelfReport = _.text.MakeTemplate_S( "Config for feature {$TextEmphasis `%1`} {$TextNeutral swapped}" @ "from \"%2\" to \"%3\""); swappedConfig.toSelfPublic = _.text.MakeTemplate_S( "%%instigator%% {$TextNeutral swapped} config for feature" @ "{$TextEmphasis `%1`} from \"%2\" to \"%3\""); } templates = MakeArray(swappedConfig); for (i = 0; i < templates.length; i += 1) { templates[i] .Reset() .ArgClass(featureClass) .Arg(oldConfig) .Arg(newConfig); } MakeAnnouncement(swappedConfig); } public final function AnnounceFailedToLoadFeatureClass(BaseText failedClassName) { if (!failedToLoadFeatureClass.initialized) { failedToLoadFeatureClass.initialized = true; failedToLoadFeatureClass.toSelfReport = _.text.MakeTemplate_S( "{$TextFailure Failed} to load feature class {$TextEmphasis `%1`}"); } failedToLoadFeatureClass.toSelfReport.Reset().Arg(failedClassName); MakeAnnouncement(failedToLoadFeatureClass); } public final function AnnounceFailedNoConfigProvided( class featureClass) { if (!failedNoConfigProvided.initialized) { failedNoConfigProvided.initialized = true; failedNoConfigProvided.toSelfReport = _.text.MakeTemplate_S( "{$TextFailue No config specified} and {$TextFailure no" @ "auto-enabled config} exists for feature {$TextEmphasis `%1`}"); } failedNoConfigProvided.toSelfReport.Reset().ArgClass(featureClass); MakeAnnouncement(failedNoConfigProvided); } public final function AnnounceFailedConfigMissing(BaseText config) { if (!failedConfigMissing.initialized) { failedConfigMissing.initialized = true; failedConfigMissing.toSelfReport = _.text.MakeTemplate_S( "Specified config \"%1\" {$TextFailue doesn't exist}"); } failedConfigMissing.toSelfReport.Reset().Arg(config); MakeAnnouncement(failedConfigMissing); } public final function AnnounceFailedCannotEnableFeature( class featureClass, BaseText config) { if (!failedCannotEnableFeature.initialized) { failedCannotEnableFeature.initialized = true; failedCannotEnableFeature.toSelfReport = _.text.MakeTemplate_S( "Something went {$TextFailure wrong}, {$TextFailure failed} to" @ "enable feature {$TextEmphasis `%1`} with config \"%2\""); } failedCannotEnableFeature.toSelfReport .Reset() .ArgClass(featureClass) .Arg(config); MakeAnnouncement(failedCannotEnableFeature); } public final function AnnounceFailedNoConfigClass( class featureClass) { if (!failedNoConfigClass.initialized) { failedNoConfigClass.initialized = true; failedNoConfigClass.toSelfReport = _.text.MakeTemplate_S( "Feature {$TextEmphasis `%1`} {$TextFailure does not have config" @ "class}! This is most likely caused by its faulty" @ "implementation"); } failedNoConfigClass.toSelfReport.Reset().ArgClass(featureClass); MakeAnnouncement(failedNoConfigClass); } public final function AnnounceFailedAlreadyDisabled( class featureClass) { if (!failedAlreadyDisabled.initialized) { failedAlreadyDisabled.initialized = true; failedAlreadyDisabled.toSelfReport = _.text.MakeTemplate_S( "Feature {$TextEmphasis `%1`} is already {$TextNegative disabled}"); } failedAlreadyDisabled.toSelfReport.Reset().ArgClass(featureClass); MakeAnnouncement(failedAlreadyDisabled); } public final function AnnounceFailedAlreadyEnabled( class featureClass, BaseText config) { if (!failedAlreadyEnabled.initialized) { failedAlreadyEnabled.initialized = true; failedAlreadyEnabled.toSelfReport = _.text.MakeTemplate_S( "Feature {$TextEmphasis `%1`} is already {$TextNegative enabled}" @ "with specified config \"%2\""); } failedAlreadyEnabled.toSelfReport .Reset() .ArgClass(featureClass) .Arg(config); MakeAnnouncement(failedAlreadyEnabled); } defaultproperties { }