Skip to content

Commit

Permalink
[SYNC] Adding save/load of dynamic data, extending linting options (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloreck authored Jul 9, 2023
2 parents 8417797 + bf9eb63 commit 2710cf2
Show file tree
Hide file tree
Showing 343 changed files with 2,720 additions and 841 deletions.
426 changes: 182 additions & 244 deletions .eslintrc.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ Optimizations, quality and logics updates are welcome.
- [parse](cli/parse/README.md) - parsing utils to collect documentation or JSON summaries
- `help` - print list of commands and information about them

## 💿 Build

Script engine can be packaged and built into custom game package.<br/>
Detailed description: [link](doc/BUILDING_CUSTOM_GAME_PACKAGE.md)

---

## 🧰 Docs
Expand All @@ -104,7 +109,11 @@ Optimizations, quality and logics updates are welcome.

## 🏗️ Assets

Additional assets repository can be cloned manually or with shortcut command: <br/>
`npm run cli clone *name*` (`extended`, `locale-eng`, `locale-ukr`, `locale-rus`)

- Extended assets: [https://gitlab.com/xray-forge/stalker-xrf-resources-extended](https://gitlab.com/xray-forge/stalker-xrf-resources-extended)
- EN locale assets: [https://gitlab.com/xray-forge/stalker-xrf-resources-locale-eng](https://gitlab.com/xray-forge/stalker-xrf-resources-locale-eng)
- UA locale assets: [https://gitlab.com/xray-forge/stalker-xrf-resources-locale-ukr](https://gitlab.com/xray-forge/stalker-xrf-resources-locale-ukr)
- RU locale assets: [https://gitlab.com/xray-forge/stalker-xrf-resources-locale-rus](https://gitlab.com/xray-forge/stalker-xrf-resources-locale-rus)

3 changes: 3 additions & 0 deletions cli/build/steps/configs_dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export async function buildDynamicConfigs(parameters: IBuildCommandParameters):
* Get list of LTX transformable descriptors.
*/
async function getLtxConfigs(filters: Array<string> = []): Promise<Array<TFolderReplicationDescriptor>> {
/**
* todo;
*/
function collectLtxConfigs(
acc: Array<TFolderReplicationDescriptor>,
it: TFolderFiles
Expand Down
3 changes: 3 additions & 0 deletions cli/build/steps/configs_statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export async function buildStaticConfigs(parameters: IBuildCommandParameters): P
* Get list of static configs.
*/
async function getStaticConfigs(filters: Array<string> = []): Promise<Array<TFolderReplicationDescriptor>> {
/**
* todo;
*/
function collectConfigs(
acc: Array<TFolderReplicationDescriptor>,
it: TFolderFiles
Expand Down
3 changes: 0 additions & 3 deletions cli/build/steps/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ interface IBuildMetaParams {

/**
* Step to collect metadata in a single file with timing metrics.
*
* @param meta - build meta information to save
* @param timeTracker - build time tracker with performance metrics
*/
export async function buildMeta({ meta, timeTracker }: IBuildMetaParams): Promise<void> {
log.info(blueBright("Build metadata"));
Expand Down
3 changes: 3 additions & 0 deletions cli/build/steps/translations_dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export async function buildDynamicTranslations(): Promise<void> {
return log.warn("No languages to translate found in config.json file, skip");
}

/**
* todo;
*/
function collectTranslations(
acc: Array<TFolderReplicationDescriptor>,
it: TFolderFiles
Expand Down
3 changes: 3 additions & 0 deletions cli/build/steps/ui_dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export async function buildDynamicUi(parameters: IBuildCommandParameters): Promi
* Get list of UI config files in engine source files.
*/
async function getUiConfigs(filters: Array<string> = []): Promise<Array<TFolderReplicationDescriptor>> {
/**
* todo;
*/
function collectXmlConfigs(
acc: Array<TFolderReplicationDescriptor>,
it: TFolderFiles
Expand Down
3 changes: 3 additions & 0 deletions cli/build/steps/ui_statics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export async function buildStaticUi(parameters: IBuildCommandParameters): Promis
* Get UI configuration files list.
*/
async function getUiConfigs(filters: Array<string> = []): Promise<Array<TFolderReplicationDescriptor>> {
/**
* todo;
*/
function collectXmlConfigs(
acc: Array<TFolderReplicationDescriptor>,
it: Array<string> | string
Expand Down
3 changes: 3 additions & 0 deletions cli/format/format_ltx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ async function formatLtxFile(file: string): Promise<void> {
* Get list of static configs.
*/
async function getLtxConfigs(filters: Array<string> = []): Promise<Array<string>> {
/**
* todo;
*/
function collectConfigs(acc: Array<string>, it: TFolderFiles): Array<string> {
if (Array.isArray(it)) {
it.forEach((nested) => collectConfigs(acc, nested));
Expand Down
3 changes: 3 additions & 0 deletions cli/parse/parse_externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export async function parseExternals(): Promise<void> {
* Get list of LTX transformable descriptors.
*/
async function getSourcesList(source: string): Promise<Array<string>> {
/**
* todo;
*/
function collectList(acc: Array<string>, it: TFolderFiles): Array<string> {
if (Array.isArray(it)) {
it.forEach((nested) => collectList(acc, nested));
Expand Down
6 changes: 6 additions & 0 deletions cli/parse/utils/__test__/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ interface IAbstractInterface {
b: string;
}

/**
* todo;
*/
function extern(name: string, cb: (...args: Array<unknown>) => void): void {}

/**
* todo;
*/
function another(name: string, cb: (...args: Array<unknown>) => void): void {}

extern("module.callback_name_one", (a: number, b: string, c: boolean, d: SomeAlias): boolean => true);
Expand Down
6 changes: 6 additions & 0 deletions cli/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ function createFoldersForConfigs(xmlConfigs: Array<TFolderReplicationDescriptor>
});
}

/**
* todo;
*/
async function getUiConfigs(filters: Array<string> = []): Promise<Array<TFolderReplicationDescriptor>> {
/**
* todo;
*/
function collectXmlConfigs(
acc: Array<TFolderReplicationDescriptor>,
it: TFolderFiles
Expand Down
24 changes: 24 additions & 0 deletions cli/preview/utils/generate_preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { default as jsdom } from "jsdom";

const { style, STATIC_ASSET, GRADIENT_BG_, GENERIC } = generateDomClasses();

/**
*
*/
export function generateHTMLPreviewFromXMLString(content: string): string {
const dom = new jsdom.JSDOM(content);

Expand Down Expand Up @@ -58,10 +61,16 @@ export function generateHTMLPreviewFromXMLString(content: string): string {
return dom.serialize();
}

/**
*
*/
function prepareOther(node: HTMLElement): void {
node.style.border = "solid black 1px";
}

/**
*
*/
function prepareText(node: HTMLElement): void {
node.style.overflow = "hidden";
node.style.width = "100%";
Expand All @@ -74,6 +83,9 @@ function prepareText(node: HTMLElement): void {
}
}

/**
*
*/
function prepareTexture(node: HTMLElement): void {
node.setAttribute("texture_resource", node.textContent);

Expand All @@ -84,15 +96,24 @@ function prepareTexture(node: HTMLElement): void {
node.style.height = "100%";
}

/**
*
*/
function prepareWindow(node: HTMLElement): void {
node.style.position = "absolute";
node.style.background = "rgba(50, 50, 50, 0.05)";
}

/**
*
*/
function prepareStaticAsset(node: HTMLElement): void {
node.className = STATIC_ASSET + " " + GRADIENT_BG_ + Math.floor(Math.random() * 10);
}

/**
*
*/
function generateDomClasses() {
const GENERIC: string = "generic";
const STATIC_ASSET: string = "static-asset";
Expand Down Expand Up @@ -144,6 +165,9 @@ function generateDomClasses() {
};
}

/**
* todo;
*/
function getRandomColor(): string {
return "#" + (((1 << 24) * Math.random()) | 0).toString(16).padStart(6, "0");
}
17 changes: 17 additions & 0 deletions cli/utils/fs/get_diffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ export interface IDiffs {
deletions: IDiff;
}

/**
* todo;
*/
function getTime(dateOrDateStr: Date | string): number {
return typeof dateOrDateStr === "string" ? Date.parse(dateOrDateStr) : dateOrDateStr.getTime();
}

/**
* todo;
*/
async function ensureDirAccess(directory: string): Promise<void> {
try {
await fsp.access(directory);
Expand All @@ -43,6 +49,11 @@ async function ensureDirAccess(directory: string): Promise<void> {
}
}

/**
* todo;
*
* @yields - files from directory in a recursive way
*/
async function* getFiles(directory: string): AsyncGenerator<string> {
const dirents = await fsp.readdir(directory, { withFileTypes: true });

Expand All @@ -54,6 +65,9 @@ async function* getFiles(directory: string): AsyncGenerator<string> {
}
}

/**
* todo;
*/
async function getFileStats(directory: string, options): Promise<FileStats> {
const dir = path.resolve(directory);

Expand Down Expand Up @@ -85,6 +99,9 @@ async function getFileStats(directory: string, options): Promise<FileStats> {
return fileStats;
}

/**
* todo;
*/
export async function getDiffs(base: FilePathMap, target: FilePathMap, options?: DiffOptions): Promise<IDiffs> {
const { exclusions = [], compareSizes = true } = options || {};
const statsOptions = { exclusions };
Expand Down
3 changes: 3 additions & 0 deletions cli/utils/fs/open_folder_in_explorer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as cp from "child_process";
import * as os from "os";

/**
* todo;
*/
export function openFolderInExplorer(path: string): Promise<void> {
return new Promise((resolve, reject) => {
const osType: string = os.type();
Expand Down
4 changes: 1 addition & 3 deletions cli/utils/fs/read_dir_content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { TDirectoryFilesTree } from "#/utils/fs/types";
*/
export async function readDirContent(dirPath: string): Promise<TDirectoryFilesTree> {
return (await Promise.all(
(
await fs.readdir(dirPath, { withFileTypes: true })
).map(async (dirent) => {
(await fs.readdir(dirPath, { withFileTypes: true })).map(async (dirent) => {
const it = path.join(dirPath, dirent.name);

return dirent.isDirectory() ? await readDirContent(it) : it;
Expand Down
4 changes: 1 addition & 3 deletions cli/utils/fs/read_dir_content_flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import * as path from "path";
*/
export async function readDirContentFlat(dirPath: string, container: Array<string> = []): Promise<Array<string>> {
await Promise.all(
(
await fs.readdir(dirPath, { withFileTypes: true })
).map(async (dirent) => {
(await fs.readdir(dirPath, { withFileTypes: true })).map(async (dirent) => {
const it = path.join(dirPath, dirent.name);

if (dirent.isDirectory()) {
Expand Down
10 changes: 8 additions & 2 deletions cli/utils/fs/read_dir_content_flat_gen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import fsp from "fs/promises";
import path from "path";
import * as fsp from "fs/promises";
import * as path from "path";

/**
* Read folder content with generator.
*
* @param directory - target folder to traverse
* @yields next item in directory
*/
export async function* readFolderGen(directory: string) {
const dirents = await fsp.readdir(directory, { withFileTypes: true });

Expand Down
3 changes: 3 additions & 0 deletions cli/utils/fs/read_last_lines_of_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Optional } from "#/utils/types";

const NEW_LINE_CHARACTERS: Array<string> = ["\n"];

/**
* todo;
*/
export async function readLastLinesOfFile(
filePath: string,
maxLineCount: number,
Expand Down
6 changes: 3 additions & 3 deletions doc/BUILDING_CUSTOM_GAME_PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and bundled together with custom engine.

Comparing to normal gamedata builds the only needed thing is full assets list. <br/>
To build package you will need [extended](https://gitlab.com/xray-forge/stalker-xrf-resources-extended) assets
and one of locales packs, for example [en](https://gitlab.com/xray-forge/stalker-xrf-resources-locale-en). <br/>
and one of locales packs, for example [eng](https://gitlab.com/xray-forge/stalker-xrf-resources-locale-eng). <br/>

After cloning suggested repositories or providing custom assets, you should list them in 'config.json' if paths are different from already suggested.

Expand All @@ -19,10 +19,10 @@ After cloning suggested repositories or providing custom assets, you should list
If assets are downloaded and configured correctly, the only needed thing is:

```
npm run cli pack game -- --clean --build --optimize
npm run cli pack game -- --clean --optimize
# or
npm run cli pack game -- -c -b -o
npm run cli pack game -- -c -o
# or
npm run pack:game
Expand Down
1 change: 1 addition & 0 deletions doc/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

## 🧰 Requests to open x-ray

- Add callback notifying about game save to get filename
- With lua bindings generation include all call overrides when output TXT
- Export actor menu and actor menu item classes for overriding with lua
- Fix numerous calls to disk with menu, implement caching for character menu and fix lags when opening inventory
Expand Down
Loading

0 comments on commit 2710cf2

Please sign in to comment.