mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-26 02:03:49 +02:00
inventory and prop support
This commit is contained in:
55
src/classes/inventory.js
Normal file
55
src/classes/inventory.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import * as workerTimers from 'worker-timers';
|
||||
import configRepository from '../service/config.js';
|
||||
import database from '../service/database.js';
|
||||
import { baseClass, $app, API, $t, $utils } from './baseClass.js';
|
||||
import { inventoryRequest } from '../api';
|
||||
|
||||
export default class extends baseClass {
|
||||
constructor(_app, _API, _t) {
|
||||
super(_app, _API, _t);
|
||||
}
|
||||
|
||||
init() {
|
||||
API.currentUserInventory = new Map();
|
||||
API.$on('LOGIN', function () {
|
||||
API.currentUserInventory.clear();
|
||||
});
|
||||
}
|
||||
|
||||
_data = {
|
||||
inventoryTable: []
|
||||
};
|
||||
|
||||
_methods = {
|
||||
async getInventory() {
|
||||
this.inventoryTable = [];
|
||||
API.currentUserInventory.clear();
|
||||
var params = {
|
||||
n: 100,
|
||||
offset: 0,
|
||||
order: 'newest'
|
||||
};
|
||||
this.galleryDialogInventoryLoading = true;
|
||||
try {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
params.offset = i * params.n;
|
||||
const args =
|
||||
await inventoryRequest.getInventoryItems(params);
|
||||
for (const item of args.json.data) {
|
||||
API.currentUserInventory.set(item.id, item);
|
||||
if (!item.flags.includes('ugc')) {
|
||||
this.inventoryTable.push(item);
|
||||
}
|
||||
}
|
||||
if (args.json.data.length === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching inventory items:', error);
|
||||
} finally {
|
||||
this.galleryDialogInventoryLoading = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -559,6 +559,15 @@ export default class extends baseClass {
|
||||
// on avatar gallery image upload
|
||||
} else if (contentType === 'invitePhoto') {
|
||||
// on uploading invite photo
|
||||
} else if (contentType === 'inventory') {
|
||||
if (
|
||||
$app.galleryDialogVisible &&
|
||||
!$app.galleryDialogInventoryLoading
|
||||
) {
|
||||
$app.getInventory();
|
||||
}
|
||||
// on consuming a bundle
|
||||
// {contentType: 'inventory', itemId: 'inv_', itemType: 'prop', actionType: 'add'}
|
||||
} else if (!contentType) {
|
||||
console.log(
|
||||
'content-refresh without contentType',
|
||||
|
||||
Reference in New Issue
Block a user