Skip to content

Latest commit

 

History

History
273 lines (219 loc) · 7.59 KB

SCRIPTING_SYSTEM.md

File metadata and controls

273 lines (219 loc) · 7.59 KB

🎮 Scripting System Setup - Complete Summary

✅ What Was Done

1. Created Script Organization Structure

assets/util/scripts/
├── README.md                           # Complete scripting guide
├── core/                               # Core utilities
│   ├── utils.js                       # Helper functions (distance, lerp, random, etc.)
│   └── constants.js                   # Game constants (combat, stats, animations)
├── behaviors/                          # AI behaviors
│   └── enemy/
│       └── goblin.json                # Example goblin AI behavior tree
├── abilities/                          # Character abilities
│   └── warrior/
│       └── slash.js                   # Example warrior slash ability
├── weapons/                            # Weapon behaviors
├── quests/                             # Quest definitions
├── events/                             # World events
└── ui/                                 # UI scripts

2. Created ScriptManager

  • Location: src/scripting/ScriptManager.js
  • Features:
    • ✅ Load JavaScript modules
    • ✅ Load JSON data files
    • ✅ Script caching
    • ✅ Hot-reload support (development)
    • ✅ Category-based organization
    • ✅ Easy script reloading

3. Created Example Scripts

  • Core Utils (assets/util/scripts/core/utils.js):

    • Math helpers (clamp, lerp, distance)
    • Random utilities
    • Time formatting
    • Debounce/throttle
    • And more...
  • Constants (assets/util/scripts/core/constants.js):

    • Combat stats
    • Character stats
    • Enemy types
    • Animations
    • UI settings
    • Physics constants
  • Goblin AI (assets/util/scripts/behaviors/enemy/goblin.json):

    • Behavior tree structure
    • Combat, chase, and patrol behaviors
    • Stats and loot tables
  • Slash Ability (assets/util/scripts/abilities/warrior/slash.js):

    • Complete ability class
    • Cooldown management
    • Damage calculation
    • Target finding
    • Animation integration

4. Updated Configuration

  • File: config/assets.json
  • Added: Scripts section with paths to core scripts

5. Created Documentation

  • Scripting Guide: docs/SCRIPTING_SYSTEM_GUIDE.md
    • Complete guide to scripting system
    • C# alternatives explained
    • "Hinglish" warning fix
    • Package recommendations
    • Example scripts

🚫 C# Scripting - Answer

Can You Use C# Scripts?

NO - C# scripting is NOT natively supported because:

  • This is a JavaScript/Babylon.js game (not Unity)
  • Runs in web browsers (JavaScript environment)
  • No .NET runtime available

Alternatives:

  1. ✅ JavaScript Modules (Recommended) - Native, best performance
  2. ✅ Lua Scripts - Available from Grudge-PlayGround, good for modding
  3. ✅ JSON Behavior Trees - Great for AI and data-driven logic
  4. ⚠️ WebAssembly - Possible but complex (not recommended)

🐛 "Hinglish Phrase Detected" Warning

What It Is:

  • FALSE POSITIVE from your IDE
  • Language detection plugin misidentifying JavaScript code

How to Fix:

Add to .vscode/settings.json:

{
    "files.associations": {
        "*.js": "javascript"
    }
}

Or disable the language detection extension.

📦 Recommended Packages

For Lua Scripting (Optional):

npm install fengari fengari-web

For Better Development (Recommended):

npm install --save-dev typescript @types/node esbuild vite

Current Dependencies:

Your package.json already has:

  • ✅ @types/node - TypeScript definitions
  • ✅ express - Server
  • ✅ eslint - Linting
  • ✅ prettier - Code formatting

🎯 How to Use the Scripting System

1. Initialize ScriptManager

import { scriptManager } from './src/scripting/ScriptManager.js';

// Initialize with hot-reload for development
await scriptManager.init({ hotReload: true });

2. Load and Use Scripts

JavaScript Module:

// Load ability script
const abilityScript = await scriptManager.loadAbility('warrior/slash.js');
const { SlashAbility } = abilityScript.data;

// Create and use ability
const slash = new SlashAbility(player);
await slash.execute(target);

JSON Behavior:

// Load behavior
const behaviorScript = await scriptManager.loadBehavior('enemy/goblin.json');
const goblinBehavior = behaviorScript.data;

// Use behavior data
enemy.setBehavior(goblinBehavior);

Core Utils:

// Load utils
const utilsScript = await scriptManager.loadScript('core', 'utils.js');
const { distance3D, lerp, randomInt } = utilsScript.data;

// Use utilities
const dist = distance3D(player.position, enemy.position);
const interpolated = lerp(0, 100, 0.5);
const random = randomInt(1, 10);

3. Hot Reload (Development)

// Reload a script after editing
await scriptManager.reloadScript('abilities/warrior/slash.js');

📝 Next Steps

1. Share Your Scripts

Please share your C# scripts or any other scripts you have, and I can:

  • ✅ Convert C# to JavaScript
  • ✅ Create equivalent Lua scripts
  • ✅ Design JSON behavior trees
  • ✅ Integrate them into the system

2. Install Recommended Packages (Optional)

# For Lua scripting support
npm install fengari fengari-web

# For better development experience
npm install --save-dev vite

3. Test the System

// In your game initialization code
import { scriptManager } from './src/scripting/ScriptManager.js';

async function initGame() {
    // Initialize script manager
    await scriptManager.init({ hotReload: true });
    
    // Load core scripts
    const utils = await scriptManager.loadScript('core', 'utils.js');
    const constants = await scriptManager.loadScript('core', 'constants.js');
    
    console.log('✅ Scripting system ready!');
}

4. Create Your Own Scripts

Follow the examples in:

  • assets/util/scripts/abilities/warrior/slash.js - Ability example
  • assets/util/scripts/behaviors/enemy/goblin.json - AI example
  • assets/util/scripts/core/utils.js - Utility functions

📚 Documentation Files

  1. assets/util/scripts/README.md - Script directory guide
  2. docs/SCRIPTING_SYSTEM_GUIDE.md - Complete scripting guide
  3. src/scripting/ScriptManager.js - ScriptManager implementation
  4. This file - Setup summary

🤝 Ready to Help!

I'm ready to:

  1. ✅ Convert your C# scripts to JavaScript
  2. ✅ Create custom abilities, behaviors, or systems
  3. ✅ Set up Lua scripting if needed
  4. ✅ Design behavior trees for AI
  5. ✅ Fix any scripting issues

Please share your scripts and let me know what you'd like to do with them!

🎨 Example: Converting C# to JavaScript

C# Script (Unity):

public class PlayerController : MonoBehaviour {
    public float speed = 5f;
    
    void Update() {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        transform.position += new Vector3(h, 0, v) * speed * Time.deltaTime;
    }
}

JavaScript Equivalent (Babylon.js):

export class PlayerController {
    constructor(mesh, scene) {
        this.mesh = mesh;
        this.scene = scene;
        this.speed = 5;
    }
    
    update(deltaTime) {
        const inputMap = this.scene.inputMap;
        const h = (inputMap['d'] ? 1 : 0) - (inputMap['a'] ? 1 : 0);
        const v = (inputMap['w'] ? 1 : 0) - (inputMap['s'] ? 1 : 0);
        
        this.mesh.position.x += h * this.speed * deltaTime;
        this.mesh.position.z += v * this.speed * deltaTime;
    }
}

Ready when you are! Share your scripts and let's get them working in your game! 🚀