feat: Introduce dynamic JSON-based configuration for game settings and command toggling via a new admin command.

This commit is contained in:
syntaxbullet
2025-12-15 21:59:28 +01:00
parent 1eace32aa1
commit ac6283e60c
12 changed files with 257 additions and 48 deletions

View File

@@ -3,7 +3,7 @@ import { inventory, items, users } from "@/db/schema";
import { eq, and, sql, count } from "drizzle-orm";
import { DrizzleClient } from "@/lib/DrizzleClient";
import { economyService } from "@/modules/economy/economy.service";
import { GameConfig } from "@/config/game";
import { config } from "@/lib/config";
export const inventoryService = {
addItem: async (userId: string, itemId: number, quantity: bigint = 1n, tx?: any) => {
@@ -18,8 +18,8 @@ export const inventoryService = {
if (existing) {
const newQuantity = (existing.quantity ?? 0n) + quantity;
if (newQuantity > GameConfig.inventory.maxStackSize) {
throw new Error(`Cannot exceed max stack size of ${GameConfig.inventory.maxStackSize}`);
if (newQuantity > config.inventory.maxStackSize) {
throw new Error(`Cannot exceed max stack size of ${config.inventory.maxStackSize}`);
}
const [entry] = await txFn.update(inventory)
@@ -39,12 +39,12 @@ export const inventoryService = {
.from(inventory)
.where(eq(inventory.userId, BigInt(userId)));
if (inventoryCount.count >= GameConfig.inventory.maxSlots) {
throw new Error(`Inventory full (Max ${GameConfig.inventory.maxSlots} slots)`);
if (inventoryCount.count >= config.inventory.maxSlots) {
throw new Error(`Inventory full (Max ${config.inventory.maxSlots} slots)`);
}
if (quantity > GameConfig.inventory.maxStackSize) {
throw new Error(`Cannot exceed max stack size of ${GameConfig.inventory.maxStackSize}`);
if (quantity > config.inventory.maxStackSize) {
throw new Error(`Cannot exceed max stack size of ${config.inventory.maxStackSize}`);
}
const [entry] = await txFn.insert(inventory)