-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYNC] Adding dynamic extensions feature. (#10)
- Loading branch information
Showing
74 changed files
with
1,623 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# [XRF](../../../) / SRC / ENGINE / INI | ||
# [XRF](../../../) / SRC / ENGINE / CONFIGS | ||
|
||
## LTX configurations TS variant | ||
## LTX configurations | ||
|
||
- Used to configure game parameters and overwrite existing ones | ||
|
||
## LTX vs TS | ||
|
||
There is no major differences what to use for configuration files, both sides have pros/cons. <br/> | ||
With `typescript` variant you can generate different variations on build time, check types and share parts. <br/> | ||
With `ini` variant it is less verbose and standard across modding community. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { beforeEach, describe, expect, it } from "@jest/globals"; | ||
|
||
import { haveExtensions, registerExtension } from "@/engine/core/database/extensions"; | ||
import { registry } from "@/engine/core/database/registry"; | ||
import { IExtensionsDescriptor } from "@/engine/core/utils/extensions"; | ||
|
||
describe("'extensions' module of the database", () => { | ||
beforeEach(() => { | ||
registry.extensions = new LuaTable(); | ||
}); | ||
|
||
it("should correctly register extensions", () => { | ||
expect(() => registerExtension(null as unknown as IExtensionsDescriptor)).toThrow(); | ||
expect(() => registerExtension({} as IExtensionsDescriptor)).toThrow(); | ||
|
||
const first: IExtensionsDescriptor = { name: "first", module: {} } as IExtensionsDescriptor; | ||
const second: IExtensionsDescriptor = { name: "second", module: {} } as IExtensionsDescriptor; | ||
|
||
expect(registry.extensions.length()).toBe(0); | ||
|
||
expect(registerExtension(first)).toBe(first); | ||
expect(registry.extensions.length()).toBe(1); | ||
|
||
expect(registerExtension(second)).toBe(second); | ||
expect(registry.extensions.length()).toBe(2); | ||
|
||
expect(registry.extensions.has("first")).toBe(true); | ||
expect(registry.extensions.has("second")).toBe(true); | ||
}); | ||
|
||
it("should correctly check if have extensions", () => { | ||
const first: IExtensionsDescriptor = { name: "first", module: {} } as IExtensionsDescriptor; | ||
|
||
expect(haveExtensions()).toBe(false); | ||
|
||
expect(registerExtension(first)).toBe(first); | ||
expect(haveExtensions()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { registry } from "@/engine/core/database/registry"; | ||
import { assert } from "@/engine/core/utils/assertion"; | ||
import { IExtensionsDescriptor } from "@/engine/core/utils/extensions"; | ||
import { LuaLogger } from "@/engine/core/utils/logging"; | ||
|
||
const logger: LuaLogger = new LuaLogger($filename); | ||
|
||
/** | ||
* Register game mod extension in the registry. | ||
* | ||
* @param extension - extension descriptor to register in the database | ||
* @returns registered extension descriptor | ||
*/ | ||
export function registerExtension(extension: IExtensionsDescriptor): IExtensionsDescriptor { | ||
assert(extension.name, "Expected extension to have name when registering."); | ||
assert(extension.module, "Expected extension to have valid lua module object when registering."); | ||
assert(!registry.extensions.has(extension.name), "Declaring duplicated extension: '%s'.", extension.name); | ||
|
||
logger.info("Register extension:", extension.name); | ||
|
||
registry.extensions.set(extension.name, extension); | ||
|
||
return extension; | ||
} | ||
|
||
/** | ||
* Check whether game have any extensions activated. | ||
* | ||
* @returns if have at least one extension active | ||
*/ | ||
export function haveExtensions(): boolean { | ||
return registry.extensions.length() > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.