From 8a1a698b8560ac08b52e9a3a97a3969414ba156a Mon Sep 17 00:00:00 2001 From: xLuxy <67131061+xLuxy@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:13:31 +0200 Subject: [PATCH 1/2] shared: Add alt.logDebug for isDebug shorthand --- shared/js/logging.js | 8 ++++++++ types/shared/index.d.ts | 1 + types/shared/package.json | 36 ++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/shared/js/logging.js b/shared/js/logging.js index 14e4b7988..ef52dda1b 100644 --- a/shared/js/logging.js +++ b/shared/js/logging.js @@ -2831,9 +2831,17 @@ function timeEnd(label) { timeLabelMap.delete(label ?? "Timer"); } +function logDebug(...args) { + if (!alt.isDebug) return; + alt.log(...args); +} + +alt.logDebug = logDebug; + if (alt.isClient) { if (!globalThis.console) globalThis.console = {}; globalThis.console.log = alt.log; + globalThis.console.debug = alt.logDebug; globalThis.console.warn = alt.logWarning; globalThis.console.error = alt.logError; globalThis.console.time = time; diff --git a/types/shared/index.d.ts b/types/shared/index.d.ts index e59d258f7..a2e37107d 100644 --- a/types/shared/index.d.ts +++ b/types/shared/index.d.ts @@ -17,6 +17,7 @@ declare module "@altv/shared" { export const syncedMeta: GlobalSyncedMeta; export function log(...args: unknown[]): void; + export function logDebug(...args: unknown[]): void; export function logWarning(...args: unknown[]): void; export function logError(...args: unknown[]): void; export function sha256(str: string): string; diff --git a/types/shared/package.json b/types/shared/package.json index dbf8b5a72..9feae57ad 100644 --- a/types/shared/package.json +++ b/types/shared/package.json @@ -1,35 +1,35 @@ { "name": "@altv/shared", - "version": "0.0.2", + "version": "0.0.3", "description": "This package contains the type definitions for the alt:V JS module v2 shared types", "types": "index.d.ts", "files": [ - "index.d.ts" + "index.d.ts" ], "scripts": { - "test": "tsc", - "preversion": "yarn run test", - "release": "yarn version --no-git-tag-version" + "test": "tsc", + "preversion": "yarn run test", + "release": "yarn version --no-git-tag-version" }, "repository": { - "type": "git", - "url": "git+https://github.com/altmp/altv-js-module-v2.git" + "type": "git", + "url": "git+https://github.com/altmp/altv-js-module-v2.git" }, "keywords": [ - "altmp", - "altv", - "node", - "v8", - "js-module", - "js-module-v2", - "gta", - "gta5", - "gtav" + "altmp", + "altv", + "node", + "v8", + "js-module", + "js-module-v2", + "gta", + "gta5", + "gtav" ], "author": "altMP Team", "license": "MIT", "bugs": { - "url": "https://github.com/altmp/altv-js-module-v2/issues" + "url": "https://github.com/altmp/altv-js-module-v2/issues" }, "homepage": "https://github.com/altmp/altv-js-module-v2/tree/dev/types/shared" - } +} From ac44a326b237fe8536eeabdd7ca448e0bdf81d4a Mon Sep 17 00:00:00 2001 From: xLuxy <67131061+xLuxy@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:26:17 +0200 Subject: [PATCH 2/2] shared: Add alt.logDebug compat --- shared/js/compatibility/core.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared/js/compatibility/core.js b/shared/js/compatibility/core.js index d58bd313c..f229b2917 100644 --- a/shared/js/compatibility/core.js +++ b/shared/js/compatibility/core.js @@ -3,6 +3,8 @@ /// // import * as alt from "@altv/shared"; +requireBinding("shared/logging.js"); + /** * * @param {string} resourceName @@ -44,7 +46,7 @@ cppBindings.registerCompatibilityExport("emitRaw", alt.Events.emitRaw); cppBindings.registerCompatibilityExport("log", alt.log); cppBindings.registerCompatibilityExport("logError", alt.logError); cppBindings.registerCompatibilityExport("logWarning", alt.logWarning); -cppBindings.registerCompatibilityExport("logDebug", () => {}); +cppBindings.registerCompatibilityExport("logDebug", alt.logDebug); cppBindings.registerCompatibilityExport("hash", alt.hash); cppBindings.registerCompatibilityExport("stringToSHA256", alt.sha256);