Browse Source

Fix `LocalDatabase` not supporting database API changes

core_refactor
Anton Tarasenko 2 years ago
parent
commit
845a6a944a
  1. 19
      sources/Data/Database/Local/DBRecord.uc
  2. 10
      sources/Data/Database/Local/LocalDatabaseInstance.uc

19
sources/Data/Database/Local/DBRecord.uc

@ -7,7 +7,7 @@
* Auxiliary data object that can store either a JSON array or an object in * Auxiliary data object that can store either a JSON array or an object in
* the local Acedia database. It is supposed to be saved and loaded * the local Acedia database. It is supposed to be saved and loaded
* to / from packages. * to / from packages.
* Copyright 2021-2022 Anton Tarasenko * Copyright 2021-2023 Anton Tarasenko
*------------------------------------------------------------------------------ *------------------------------------------------------------------------------
* This file is part of Acedia. * This file is part of Acedia.
* *
@ -184,6 +184,7 @@ private final function DBRecordPointer MakeRecordPointer(
return pointer; return pointer;
} }
// Converts `JSONPointer` into our internal representation.
private final function DBRecordPointer ConvertPointer(JSONPointer jsonPointer) private final function DBRecordPointer ConvertPointer(JSONPointer jsonPointer)
{ {
if (jsonPointer == none) { if (jsonPointer == none) {
@ -192,6 +193,8 @@ private final function DBRecordPointer ConvertPointer(JSONPointer jsonPointer)
return ConvertPointerPath(jsonPointer, 0, jsonPointer.GetLength()); return ConvertPointerPath(jsonPointer, 0, jsonPointer.GetLength());
} }
// Produced out internal pointer representation `DBRecordPointer` to
// the container that stores object, referred to by a given `JSONPointer`.
private final function DBRecordPointer ConvertContainerPointer( private final function DBRecordPointer ConvertContainerPointer(
JSONPointer jsonPointer) JSONPointer jsonPointer)
{ {
@ -264,9 +267,9 @@ public static final function Global __()
return class'Global'.static.GetInstance(); return class'Global'.static.GetInstance();
} }
public static final function ServerGlobal __server() public static final function CoreGlobal __core()
{ {
return class'ServerGlobal'.static.GetInstance(); return class'CoreGlobal'.static.GetGenericInstance();
} }
/** /**
@ -304,7 +307,7 @@ private final static function DBRecord NewRecordFor(string dbPackageName)
if (recordCandidate != none) { if (recordCandidate != none) {
continue; continue;
} }
recordCandidate = __server().unreal.GetGameType() recordCandidate = __core().unreal_api().GetGameType()
.CreateDataObject(class'DBRecord', nextName, dbPackageName); .CreateDataObject(class'DBRecord', nextName, dbPackageName);
recordCandidate.package = dbPackageName; recordCandidate.package = dbPackageName;
return recordCandidate; return recordCandidate;
@ -330,7 +333,7 @@ private final static function DBRecord LoadRecordFor(
string name, string name,
string package) string package)
{ {
return __server().unreal.GetGameType() return __core().unreal_api().GetGameType()
.LoadDataObject(class'DBRecord', name, package); .LoadDataObject(class'DBRecord', name, package);
} }
@ -689,7 +692,7 @@ private final function SetItem(
if (oldRecord != none) { if (oldRecord != none) {
oldRecord.EmptySelf(); oldRecord.EmptySelf();
} }
__server().unreal.GetGameType() __core().unreal_api().GetGameType()
.DeleteDataObject(class'DBRecord', oldItem.s, package); .DeleteDataObject(class'DBRecord', oldItem.s, package);
} }
} }
@ -723,7 +726,7 @@ private final function RemoveItem(int index)
if (oldRecord != none) { if (oldRecord != none) {
oldRecord.EmptySelf(); oldRecord.EmptySelf();
} }
__server().unreal.GetGameType() __core().unreal_api().GetGameType()
.DeleteDataObject(class'DBRecord', oldItem.s, package); .DeleteDataObject(class'DBRecord', oldItem.s, package);
} }
storage.Remove(index, 1); storage.Remove(index, 1);
@ -872,7 +875,7 @@ public final function EmptySelf()
return; return;
} }
lockEraseSelf = true; lockEraseSelf = true;
game = __server().unreal.GetGameType(); game = __core().unreal_api().GetGameType();
for (i = 0; i < storage.length; i += 1) for (i = 0; i < storage.length; i += 1)
{ {
if (storage[i].t != DBAT_Reference) continue; if (storage[i].t != DBAT_Reference) continue;

10
sources/Data/Database/Local/LocalDatabaseInstance.uc

@ -4,7 +4,7 @@
* This class SHOULD NOT be deallocated manually. * This class SHOULD NOT be deallocated manually.
* This name was chosen so that more readable `LocalDatabase` could be * This name was chosen so that more readable `LocalDatabase` could be
* used in config for defining local databases through per-object-config. * used in config for defining local databases through per-object-config.
* Copyright 2021-2022 Anton Tarasenko * Copyright 2021-2023 Anton Tarasenko
*------------------------------------------------------------------------------ *------------------------------------------------------------------------------
* This file is part of Acedia. * This file is part of Acedia.
* *
@ -83,7 +83,7 @@ var private int lastTaskLifeVersion;
protected function Constructor() protected function Constructor()
{ {
_server.unreal.OnTick(self).connect = CompleteAllTasks; __core().unreal_api().OnTick(self).connect = CompleteAllTasks;
} }
protected function Finalizer() protected function Finalizer()
@ -93,7 +93,7 @@ protected function Finalizer()
CompleteAllTasks(); CompleteAllTasks();
WriteToDisk(); WriteToDisk();
rootRecord = none; rootRecord = none;
_server.unreal.OnTick(self).Disconnect(); __core().unreal_api().OnTick(self).Disconnect();
configEntry = none; configEntry = none;
} }
@ -103,7 +103,7 @@ private final function CompleteAllTasks(
optional float dilationCoefficient) optional float dilationCoefficient)
{ {
if (lastTask != none && lastTask.GetLifeVersion() == lastTaskLifeVersion) { if (lastTask != none && lastTask.GetLifeVersion() == lastTaskLifeVersion) {
lastTask.TryCompleting(); lastTask.TryCompleting(self);
} }
lastTask = none; lastTask = none;
lastTaskLifeVersion = -1; lastTaskLifeVersion = -1;
@ -130,7 +130,7 @@ public final function WriteToDisk()
packageName = _.text.IntoString(configEntry.GetPackageName()); packageName = _.text.IntoString(configEntry.GetPackageName());
} }
if (packageName != "") { if (packageName != "") {
_server.unreal.GetGameType().SavePackage(packageName); __core().unreal_api().GetGameType().SavePackage(packageName);
} }
} }

Loading…
Cancel
Save