Use Typescript to develop Genshin UGC - Miliastra Wonderland
AI Code Generation and Node Graph Integration
Overview of AI Code Generation
- The AI generates code that is automatically converted into node graphs, which are then integrated into a Millastra Wonderland map.
- A standard JavaScript (JS) code example demonstrates complex control flow, seamlessly compiled into a Millastra Wonderland node graph with consistent results.
Introduction to Genshin TS
- Genshin TS is an open-source project written in TypeScript, allowing developers to utilize existing AI coding tools and the npm ecosystem for enhanced development.
- The project includes bilingual annotations (Chinese and English), full type system support, and optimizations for common types like entities.
Features of Genshin TS
- Supports multiple node graphs from a single file using different IDs; same IDs across files merge into one graph.
- Offers features such as automatic type inference, Unity 3D API support, bilingual event registration, and various optimization techniques including dead code elimination.
Integration with Other Projects
Reverse Engineering Insights
- Mention of another open-source project that provides a more complete reverse engineering approach than the speaker's own work.
- This third-party module has been integrated into Genshin TS, enhancing its capabilities while being licensed under MIT.
Project Setup Options
- Users can create a dev template using
npm create genens, install it as a dependency in other projects, or use CLI compiler APIs for custom workflows.
- After setting up the project template, users can run commands to install dependencies and enter watch mode for real-time compilation.
Injection Process and Safety Features
Map Injection Workflow
- Users can retrieve the most recently updated map list via
npm run mapscommand; detailed bilingual comments assist in configuration.
- During injection processes, safety checks are performed alongside backup creation to protect map data.
Error Handling Mechanisms
- If undefined signals occur during signal send/receive features, warnings are issued automatically.
- The injector auto-fixes mismatches between declared node graph types and injection targets.
Code Writing Efficiency
Simplified Variable Definition
- Variables can be defined using simple JS object literals for name/type/value without manual type selection due to automatic type inference.
Advanced Control Flow Usage
- Familiar conventional syntax allows writing calculations without creating nodes individually; advanced flow constructs like return or switch statements are supported.
Compiler Optimization Techniques in Genshin TS
Node Graph Resource Management
- The compiler optimizes complex blocks involving multiple operations and 3D vectors, converting them into a single print node for efficiency.
- Introducing event parameters changes the optimization behavior, allowing for more complex calculations to be represented as sums before conversion to strings.
- Familiar JavaScript functions like
setTimeoutandsetIntervalare used for delays, simplifying timer management without needing extensive logic.
- The compiler can autogenerate a pool of timer names to mimic real JavaScript behavior, enhancing performance when events trigger timers with shared names.
Helper Functions and API Integration
- A variety of JS-style and Unity 3D style APIs are provided for common operations, such as vector manipulations and dictionary handling.
- ESLint warnings help guide developers on using appropriate constructs when object operations are involved in the code.
- Global objects allow quick access to level entities, improving query performance by caching level objects within the node graph.
Entity Type Optimizations
- Detailed type-level optimizations ensure strict validation of entity types during parameter passing to prevent misuse.
- Regular TypeScript code can be written outside the node graph function scope while still utilizing npm libraries at compile time.
Streamlined Workflow with GSTS Server Functions
- Functions prefixed with
GSTS serverfacilitate defining reusable functions within the node graph scope; limitations exist but ESLint provides guidance on these constraints.
- Modern editors support TSP level tricks and ESLint rules seamlessly, enhancing developer experience through AI recognition of types.
Compilation Process Overview
- The workflow resembles Unity development: writing code leads to compilation that generates intermediate artifacts like GSTS files and JSo representations.
- These artifacts provide insights into variable connections and nodes, aiding in debugging by tracing errors back to specific components.