You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

196 lines
6.3 KiB

5 years ago
/**
* Main and only Acedia mutator used for loading Acedia packages
5 years ago
* and providing access to mutator events' calls.
* Name is chosen to make config files more readable.
5 years ago
* Copyright 2020 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 <https://www.gnu.org/licenses/>.
*/
class Packages extends Mutator
5 years ago
config(Acedia);
// Default value of this variable will be used to store
// reference to the active Acedia mutator,
// as well as to ensure there's only one copy of it.
// We can't use 'Singleton' class for that,
// as we have to derive from 'Mutator'.
var private Packages selfReference;
5 years ago
// Acedia's reference to a `Global` object.
var private Global _;
// Package's manifest is supposed to always have a name of
// "<package_name>.Manifest", this variable stores the ".Manifest" part
var private const string manifestSuffix;
5 years ago
// Array of predefined services that must be started along with Acedia mutator.
var private config array<string> package;
// AcediaCore package that this launcher is build for
var private config const string corePackage;
static public final function Packages GetInstance()
5 years ago
{
return default.selfReference;
}
event PreBeginPlay()
{
// Enforce one copy rule and remember a reference to that copy
if (default.selfReference != none)
{
Destroy();
return;
}
default.selfReference = self;
BootUp();
if (class'TestingService'.default.runTestsOnStartUp) {
RunStartUpTests();
}
}
private final function BootUp()
{
local int i;
local class<_manifest> nextManifest;
_ = Spawn(class'Global');
// Load core
nextManifest = LoadManifestClass(corePackage);
if (nextManifest == none)
{
_.logger.Fatal("Cannot load required AcediaCore package \""
$ corePackage $ "\". Acedia will shut down.");
Destroy();
return;
}
LoadManifest(nextManifest);
// Load packages
for (i = 0; i < package.length; i += 1)
{
nextManifest = LoadManifestClass(package[i]);
if (nextManifest == none)
{
_.logger.Failure("Cannot load `Manifest` for package \""
$ package[i] $ "\". Check if it's missing or"
@ "if it's name is spelled incorrectly.");
continue;
}
LoadManifest(nextManifest);
}
// Inject broadcast handler
5 years ago
InjectBroadcastHandler(); // TODO: move this to 'SideEffect' mechanic
}
private final function RunStartUpTests()
{
local TestingService testService;
testService = TestingService(class'TestingService'.static.Require());
testService.PrepareTests();
if (testService.filterTestsByName) {
testService.FilterByName(testService.requiredName);
}
if (testService.filterTestsByGroup) {
testService.FilterByName(testService.requiredGroup);
}
if (testService.Run())
{
// This listener will output test results into server's console
class'TestingListener_AcediaLauncher'.static.SetActive(true);
}
else
{
_.logger.Failure("Could not launch Acedia's start up testing process.");
}
}
private final function class<_manifest> LoadManifestClass(string packageName)
{
return class<_manifest>(DynamicLoadObject( packageName $ manifestSuffix,
class'Class', true));
}
private final function LoadManifest(class<_manifest> manifestClass)
5 years ago
{
local int i;
// Load alias sources
for (i = 0; i < manifestClass.default.aliasSources.length; i += 1)
5 years ago
{
if (manifestClass.default.aliasSources[i] == none) continue;
Spawn(manifestClass.default.aliasSources[i]);
5 years ago
}
// Enable features
for (i = 0; i < manifestClass.default.features.length; i += 1)
{
if (manifestClass.default.features[i] == none) continue;
if (manifestClass.default.features[i].static.IsAutoEnabled()) {
5 years ago
manifestClass.default.features[i].static.EnableMe();
}
}
// Load tests cases
for (i = 0; i < manifestClass.default.testCases.length; i += 1)
{
class'TestingService'.static
.RegisterTestCase(manifestClass.default.testCases[i]);
5 years ago
}
}
private final function InjectBroadcastHandler()
{
local BroadcastHandler ourBroadcastHandler;
if (level == none || level.game == none) return;
ourBroadcastHandler = Spawn(class'BroadcastHandler');
// Swap out level's first handler with ours
// (needs to be done for both actor reference and it's class)
ourBroadcastHandler.nextBroadcastHandler = level.game.broadcastHandler;
ourBroadcastHandler.nextBroadcastHandlerClass = level.game.broadcastClass;
level.game.broadcastHandler = ourBroadcastHandler;
level.game.broadcastClass = class'BroadcastHandler';
}
// Acedia is only able to run in a server mode right now,
// so this function is just a stub.
public final function bool IsServerOnly()
{
return true;
}
// Provide a way to handle CheckReplacement event
function bool CheckReplacement(Actor other, out byte isSuperRelevant)
{
return class'MutatorEvents'.static.
CallCheckReplacement(other, isSuperRelevant);
}
function Mutate(string command, PlayerController sendingController)
5 years ago
{
if (class'MutatorEvents'.static.CallMutate(command, sendingController)) {
super.Mutate(command, sendingController);
5 years ago
}
}
defaultproperties
{
corePackage = "AcediaCore_0_2"
manifestSuffix = ".Manifest"
5 years ago
// This is a server-only mutator
remoteRole = ROLE_None
bAlwaysRelevant = true
// Mutator description
GroupName = "Package loader"
FriendlyName = "Acedia loader"
Description = "Launcher for Acedia packages"
5 years ago
}