@armoury/fivem-roleplay-gamemode-common 1.0.70 → 1.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./models"), exports);
18
+ __exportStar(require("./services"), exports);
18
19
  __exportStar(require("./stub"), exports);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /** Vehicle */
18
+ __exportStar(require("./vehicles/vehicle.service"), exports);
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Vehicles = void 0;
10
+ const injection_js_1 = require("injection-js");
11
+ // TODO: "Attached stashes" functionality should be available for any type of entity, not only vehicles
12
+ let Vehicles = class Vehicles {
13
+ static getOwningPersistableId(entityId) {
14
+ if (!Number.isSafeInteger(entityId)) {
15
+ return null;
16
+ }
17
+ const owningPersistableId = Entity(entityId).state[IDENTIFIER_PERSISTABLE_OWNINGID];
18
+ if (owningPersistableId == null || !Number.isSafeInteger(owningPersistableId)) {
19
+ return null;
20
+ }
21
+ return Number(owningPersistableId);
22
+ }
23
+ static setOwningPersistableId(entityId, owningPersistableId) {
24
+ if (!IsDuplicityVersion()) {
25
+ throw new Error('Can\'t do this inside a client script.');
26
+ }
27
+ Entity(entityId).state.set(IDENTIFIER_PERSISTABLE_OWNINGID, owningPersistableId, true);
28
+ }
29
+ static attachStash(entityId, stashId, type) {
30
+ if (!IsDuplicityVersion()) {
31
+ throw new Error('Can\'t do this inside a client script.');
32
+ }
33
+ let count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT];
34
+ if (count != null && !Number.isSafeInteger(count)) {
35
+ throw new Error('Corrupted attached stash count data.');
36
+ }
37
+ count ?? (count = 0);
38
+ const data = this.getStashData(entityId, count);
39
+ if (data) {
40
+ throw new Error('Attempted to attach stash data to existing state.');
41
+ }
42
+ Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_BYINDEX(count), stashId, true);
43
+ Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_TYPE(count), type, true);
44
+ Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASHES_COUNT, count + 1, true);
45
+ return true;
46
+ }
47
+ static getAttachedStashIdsByType(entityId, type) {
48
+ const count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT] ?? 0;
49
+ if (!count) {
50
+ return null;
51
+ }
52
+ const stashIds = [];
53
+ for (let i = 0; i < count; i++) {
54
+ const data = this.getStashData(entityId, i);
55
+ if (!data) {
56
+ continue;
57
+ }
58
+ if (data.type == type) {
59
+ stashIds.push(Number(data.stashId));
60
+ }
61
+ }
62
+ return stashIds;
63
+ }
64
+ static getStashData(entityId, index) {
65
+ const stashId = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_BYINDEX(index)];
66
+ if (stashId == null || !Number.isSafeInteger(stashId)) {
67
+ return null;
68
+ }
69
+ const type = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_TYPE(index)];
70
+ if (type == null) {
71
+ return null;
72
+ }
73
+ return { stashId: Number(stashId), type };
74
+ }
75
+ };
76
+ exports.Vehicles = Vehicles;
77
+ exports.Vehicles = Vehicles = __decorate([
78
+ (0, injection_js_1.Injectable)()
79
+ ], Vehicles);
80
+ /** Entities */
81
+ const PERSISTABLE_PREFIX = 'armoury:entity:owning-persistable';
82
+ const IDENTIFIER_PERSISTABLE_OWNINGID = PERSISTABLE_PREFIX + ':owningId';
83
+ /** Attached Stashes */
84
+ const ATTACHED_STASHES_PREFIX = 'armoury:entity:attached-stashes';
85
+ const IDENTIFIER_ATTACHED_STASHES_COUNT = ATTACHED_STASHES_PREFIX + ':count';
86
+ const IDENTIFIER_ATTACHED_STASH_BYINDEX = (index) => `${ATTACHED_STASHES_PREFIX}:[${index}]`;
87
+ const IDENTIFIER_ATTACHED_STASH_TYPE = (index) => `${IDENTIFIER_ATTACHED_STASH_BYINDEX(index)}:type`;
@@ -1,2 +1,3 @@
1
1
  export * from './models';
2
+ export * from './services';
2
3
  export * from './stub';
@@ -0,0 +1,2 @@
1
+ /** Vehicle */
2
+ export * from './vehicles/vehicle.service';
@@ -0,0 +1,84 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Injectable } from 'injection-js';
8
+ // TODO: "Attached stashes" functionality should be available for any type of entity, not only vehicles
9
+ let Vehicles = class Vehicles {
10
+ static getOwningPersistableId(entityId) {
11
+ if (!Number.isSafeInteger(entityId)) {
12
+ return null;
13
+ }
14
+ const owningPersistableId = Entity(entityId).state[IDENTIFIER_PERSISTABLE_OWNINGID];
15
+ if (owningPersistableId == null || !Number.isSafeInteger(owningPersistableId)) {
16
+ return null;
17
+ }
18
+ return Number(owningPersistableId);
19
+ }
20
+ static setOwningPersistableId(entityId, owningPersistableId) {
21
+ if (!IsDuplicityVersion()) {
22
+ throw new Error('Can\'t do this inside a client script.');
23
+ }
24
+ Entity(entityId).state.set(IDENTIFIER_PERSISTABLE_OWNINGID, owningPersistableId, true);
25
+ }
26
+ static attachStash(entityId, stashId, type) {
27
+ if (!IsDuplicityVersion()) {
28
+ throw new Error('Can\'t do this inside a client script.');
29
+ }
30
+ let count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT];
31
+ if (count != null && !Number.isSafeInteger(count)) {
32
+ throw new Error('Corrupted attached stash count data.');
33
+ }
34
+ count ?? (count = 0);
35
+ const data = this.getStashData(entityId, count);
36
+ if (data) {
37
+ throw new Error('Attempted to attach stash data to existing state.');
38
+ }
39
+ Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_BYINDEX(count), stashId, true);
40
+ Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASH_TYPE(count), type, true);
41
+ Entity(entityId).state.set(IDENTIFIER_ATTACHED_STASHES_COUNT, count + 1, true);
42
+ return true;
43
+ }
44
+ static getAttachedStashIdsByType(entityId, type) {
45
+ const count = Entity(entityId).state[IDENTIFIER_ATTACHED_STASHES_COUNT] ?? 0;
46
+ if (!count) {
47
+ return null;
48
+ }
49
+ const stashIds = [];
50
+ for (let i = 0; i < count; i++) {
51
+ const data = this.getStashData(entityId, i);
52
+ if (!data) {
53
+ continue;
54
+ }
55
+ if (data.type == type) {
56
+ stashIds.push(Number(data.stashId));
57
+ }
58
+ }
59
+ return stashIds;
60
+ }
61
+ static getStashData(entityId, index) {
62
+ const stashId = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_BYINDEX(index)];
63
+ if (stashId == null || !Number.isSafeInteger(stashId)) {
64
+ return null;
65
+ }
66
+ const type = Entity(entityId).state[IDENTIFIER_ATTACHED_STASH_TYPE(index)];
67
+ if (type == null) {
68
+ return null;
69
+ }
70
+ return { stashId: Number(stashId), type };
71
+ }
72
+ };
73
+ Vehicles = __decorate([
74
+ Injectable()
75
+ ], Vehicles);
76
+ export { Vehicles };
77
+ /** Entities */
78
+ const PERSISTABLE_PREFIX = 'armoury:entity:owning-persistable';
79
+ const IDENTIFIER_PERSISTABLE_OWNINGID = PERSISTABLE_PREFIX + ':owningId';
80
+ /** Attached Stashes */
81
+ const ATTACHED_STASHES_PREFIX = 'armoury:entity:attached-stashes';
82
+ const IDENTIFIER_ATTACHED_STASHES_COUNT = ATTACHED_STASHES_PREFIX + ':count';
83
+ const IDENTIFIER_ATTACHED_STASH_BYINDEX = (index) => `${ATTACHED_STASHES_PREFIX}:[${index}]`;
84
+ const IDENTIFIER_ATTACHED_STASH_TYPE = (index) => `${IDENTIFIER_ATTACHED_STASH_BYINDEX(index)}:type`;
@@ -1,2 +1,3 @@
1
1
  export * from './models';
2
+ export * from './services';
2
3
  export * from './stub';
@@ -0,0 +1,2 @@
1
+ /** Vehicle */
2
+ export * from './vehicles/vehicle.service';
@@ -0,0 +1,7 @@
1
+ export declare class Vehicles {
2
+ static getOwningPersistableId(entityId: number): number | null;
3
+ static setOwningPersistableId(entityId: number, owningPersistableId: number): void;
4
+ static attachStash(entityId: number, stashId: number, type: string): boolean;
5
+ static getAttachedStashIdsByType(entityId: number, type: string): number[] | null;
6
+ private static getStashData;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armoury/fivem-roleplay-gamemode-common",
3
- "version": "1.0.70",
3
+ "version": "1.0.72",
4
4
  "description": "Shared APIs for the Armoury FiveM roleplay gamemode",
5
5
  "main": "dist/cjs/shared/index.js",
6
6
  "module": "dist/esm/shared/index.js",
@@ -14,12 +14,12 @@
14
14
  },
15
15
  "files": ["dist"],
16
16
  "peerDependencies": {
17
- "@armoury/fivem-framework-common": "1.0.70"
17
+ "@armoury/fivem-framework-common": "1.0.71"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "npm run build:cjs && npm run build:esm && npm run build:types",
21
- "build:cjs": "tsc -p tsconfig.cjs.json",
22
- "build:esm": "tsc -p tsconfig.esm.json",
21
+ "build:cjs": "node ../../tools/build.js tsconfig.cjs.json",
22
+ "build:esm": "node ../../tools/build.js tsconfig.esm.json",
23
23
  "build:types": "tsc -p tsconfig.types.json"
24
24
  },
25
25
  "publishConfig": {