# Leveling Module

The Leveling Module is a feature-rich system that allows server administrators to create and manage progression systems for their Rust game servers. This document outlines the components, features, and implementation details of the Leveling Module.

## Overview

The Leveling Module enables server administrators to create custom progression paths for players based on different criteria:

* **Economy**: Progress based on in-game currency accumulation
* **Kills**: Progress based on player vs. player combat performance
* **Playtime**: Progress based on time spent on the server

Each progression path (called a "Pass") contains multiple levels with customizable rewards, requirements, and bonus items.

## Components

### 1. LevelingModule.tsx

The main component that serves as the container for the entire leveling system. It handles:

* Data fetching and persistence
* State management
* Pass creation and management
* Level management
* Import/export functionality
* Module enabling/disabling via ModuleToggle

The component features a consistent header across both mobile and desktop views with:

* Module title and icon
* Enable/disable toggle
* Description
* Navigation back to the main dashboard

### 2. MobileLevelingView\.tsx

A mobile-optimized view of the Leveling Module that provides a responsive interface for smaller screens. The mobile view maintains feature parity with the desktop version while optimizing the layout for touch interactions and smaller screens. Features include:

* **Consistent Header**: Same header as desktop with module title, icon, enable/disable toggle, and back navigation
* **Pass Selection**: Horizontal scrollable tabs for selecting different passes
* **Pass Creation**: Interface for creating new passes with different criteria types (Economy, Kills, Playtime)
* **Level Management**: Add, edit, and delete levels with the same functionality as desktop
* **Pagination**: Navigate through levels with a page-based system instead of the desktop's scrollable view
* **Settings Management**: Configure pass properties like name, description, and access restrictions
* **Import/Export**: Share passes with other administrators using the same code or JSON options as desktop

## Features

### Pass Management

* Create passes based on different criteria (Economy, Kills, Playtime)
* Rename and customize passes
* Configure access restrictions (Everyone, VIP Only, Specific Users)
* Delete passes when no longer needed
* Auto-save changes to localStorage for offline support

### Level Management

* Add levels with custom names, descriptions, and icons
* Set progression requirements for each level
* Assign kit codes for rewards
* Add optional bonus rewards
* Reorder levels via drag and drop (desktop) or pagination (mobile)
* Auto-align levels based on their numerical order

### Sharing and Import/Export

* Generate shareable codes for passes (Base64 encoded)
* Export passes as JSON files with metadata
* Import passes from codes or JSON files
* Copy passes between servers
* Custom icon support for levels and bonuses

### Responsive Design

* Desktop-optimized view for larger screens
* Mobile-optimized view for tablets and phones
* Automatic detection of device screen size using the `useMediaQuery` hook
* Conditional rendering of appropriate view based on screen size
* Consistent functionality across device sizes

## Technical Implementation

### State Management

The Leveling Module uses React's useState and useEffect hooks for local state management. Key state elements include:

* `passes`: Array of all passes with their levels and settings
* `activePass`: Currently selected pass
* `levelPages`: Pagination state for mobile view
* `isSettingsMode`: Toggle for settings view
* `hasChanges`: Tracks unsaved changes for the save indicator
* `initialLoad`: Prevents change detection during initial data loading

### Data Persistence

Passes are stored in:

1. PostgreSQL database via Supabase (primary storage)
2. LocalStorage (fallback when offline or API unavailable)

The module implements a robust fallback system that:

* Attempts to save to the database first
* Falls back to localStorage if the API is unavailable
* Loads from localStorage if database fetch fails
* Tracks changes to prompt users to save

### Change Tracking

The module implements a sophisticated change tracking system:

* Detects changes to passes and levels
* Tracks module enable/disable state changes
* Prevents false change detection during initial load
* Provides visual feedback when changes are pending

### Mobile Optimization

The MobileLevelingView component implements several mobile-specific optimizations:

* Horizontal scrolling for pass selection
* Simplified UI with focused views
* Touch-friendly button sizes
* Pagination for level management (with configurable levels per page)
* Collapsible sections to save space
* Optimized layout for small screens

### Performance Optimizations

* Lazy loading of UI components using React.lazy and dynamic imports
* Efficient state updates to minimize re-renders
* Debounced auto-save to localStorage
* Optimized drag and drop for level reordering

### Code Maintenance

* Regular code cleanup to remove redundant imports and declarations
* Consistent import structure to prevent duplication
* Proper TypeScript typing for improved code quality
* Adherence to project coding standards

## Usage

Server administrators can access the Leveling Module from their dashboard. The interface allows them to:

1. Create passes based on different criteria
2. Add and configure levels within each pass
3. Set requirements and rewards for progression
4. Configure access restrictions
5. Share passes with other administrators
6. Import passes from other servers

## API Integration

The Leveling Module interacts with the backend API through these endpoints:

* `GET /api/leveling/passes/:serverId`: Fetch passes for a server
* `POST /api/leveling/passes/:serverId/bulk`: Save multiple passes at once

The API uses JWT authentication with Bearer tokens for secure access.

## Future Enhancements

Planned improvements for the Leveling Module include:

* Real-time collaboration for team management
* Advanced analytics for player progression
* Custom icons and visual themes
* Integration with server events
* Automated rewards distribution
* Enhanced import/export capabilities

***

Last Updated: July 17, 2025


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rust-central-1.gitbook.io/rust-central-docs/modules/leveling_module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
