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.
107 lines
3.6 KiB
107 lines
3.6 KiB
2 years ago
|
/**
|
||
|
* Class for an object that will provide an access to a Acedia's
|
||
|
* client-specific functionality by giving a reference to this object to all
|
||
|
* Acedia's objects and actors, emulating a global API namespace.
|
||
|
* 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 <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
2 years ago
|
class ClientGlobal extends CoreGlobal;
|
||
2 years ago
|
|
||
|
// `Global` is expected to behave like a singleton and will store it's
|
||
|
// main instance in this variable's default value.
|
||
|
var protected ClientGlobal myself;
|
||
|
|
||
2 years ago
|
var public ClientUnrealAPI unreal;
|
||
2 years ago
|
|
||
2 years ago
|
var private LoggerAPI.Definition fatBadAdapterClass, errNoInteraction;
|
||
2 years ago
|
|
||
2 years ago
|
public function UnrealAPI unreal_api()
|
||
|
{
|
||
|
return unreal;
|
||
|
}
|
||
|
|
||
2 years ago
|
public final static function ClientGlobal GetInstance()
|
||
|
{
|
||
|
if (default.myself == none)
|
||
|
{
|
||
|
// `...Global`s are special and exist outside main Acedia's
|
||
|
// object infrastructure, so we allocate it without using API methods.
|
||
|
default.myself = new class'ClientGlobal';
|
||
|
}
|
||
|
return default.myself;
|
||
|
}
|
||
|
|
||
|
protected function Initialize()
|
||
|
{
|
||
2 years ago
|
local Global _;
|
||
2 years ago
|
local PlayerController localPlayer;
|
||
|
local AcediaInteraction newInteraction;
|
||
2 years ago
|
local class<ClientAcediaAdapter> clientAdapterClass;
|
||
|
|
||
2 years ago
|
if (initialized) {
|
||
|
return;
|
||
|
}
|
||
|
super.Initialize();
|
||
|
initialized = true;
|
||
2 years ago
|
clientAdapterClass = class<ClientAcediaAdapter>(adapterClass);
|
||
|
if (adapterClass != none && clientAdapterClass == none)
|
||
|
{
|
||
|
class'Global'.static.GetInstance().logger
|
||
|
.Auto(fatBadAdapterClass)
|
||
|
.ArgClass(self.class);
|
||
|
return;
|
||
|
}
|
||
|
if (clientAdapterClass == none) {
|
||
|
return;
|
||
|
}
|
||
2 years ago
|
// Create APIs
|
||
2 years ago
|
_ = class'Global'.static.GetInstance();
|
||
2 years ago
|
unreal = ClientUnrealAPI(
|
||
2 years ago
|
_.memory.Allocate(clientAdapterClass.default.clientUnrealAPIClass));
|
||
2 years ago
|
unreal.Initialize(clientAdapterClass);
|
||
2 years ago
|
time.Initialize(unreal);
|
||
2 years ago
|
// Create `AcediaInteraction`
|
||
|
localPlayer = unreal.GetLocalPlayer();
|
||
|
if (localPlayer != none)
|
||
|
{
|
||
|
newInteraction = AcediaInteraction(unreal
|
||
|
.interaction
|
||
|
.AddInteraction_S("AcediaCore.AcediaInteraction"));
|
||
|
if (newInteraction != none) {
|
||
|
newInteraction.InitializeInteraction();
|
||
|
}
|
||
|
else {
|
||
|
_.logger.Auto(errNoInteraction);
|
||
|
}
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
public final function bool ConnectClientLevelCore()
|
||
|
{
|
||
|
if (class'ClientLevelCore'.static.GetInstance() == none) {
|
||
|
return false;
|
||
|
}
|
||
|
Initialize();
|
||
|
return true;
|
||
2 years ago
|
}
|
||
|
|
||
|
defaultproperties
|
||
|
{
|
||
2 years ago
|
adapterClass = class'ClientAcediaAdapter'
|
||
2 years ago
|
fatBadAdapterClass = (l=LOG_Fatal,m="Non-`ClientAcediaAdapter` class was specified as an adapter for `%1` level core class. This should not have happened. AcediaCore cannot properly function.")
|
||
|
errNoInteraction = (l=LOG_Error,m="Failed to create interaction \"AcediaCore.AcediaInteraction\". AcediaCore won't support most of its client-side functionality.")
|
||
2 years ago
|
}
|