redscript-mc 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +72 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +57 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +17 -25
  4. package/CHANGELOG.md +58 -0
  5. package/CONTRIBUTING.md +140 -0
  6. package/README.md +28 -19
  7. package/README.zh.md +28 -19
  8. package/dist/__tests__/cli.test.js +10 -10
  9. package/dist/__tests__/codegen.test.js +1 -1
  10. package/dist/__tests__/diagnostics.test.js +5 -5
  11. package/dist/__tests__/e2e.test.js +146 -5
  12. package/dist/__tests__/formatter.test.d.ts +1 -0
  13. package/dist/__tests__/formatter.test.js +40 -0
  14. package/dist/__tests__/lowering.test.js +36 -3
  15. package/dist/__tests__/mc-integration.test.js +255 -10
  16. package/dist/__tests__/mc-syntax.test.js +3 -3
  17. package/dist/__tests__/nbt.test.js +2 -2
  18. package/dist/__tests__/optimizer-advanced.test.js +3 -3
  19. package/dist/__tests__/runtime.test.js +1 -1
  20. package/dist/ast/types.d.ts +21 -3
  21. package/dist/cli.js +25 -7
  22. package/dist/codegen/mcfunction/index.d.ts +1 -1
  23. package/dist/codegen/mcfunction/index.js +8 -2
  24. package/dist/codegen/structure/index.js +7 -1
  25. package/dist/formatter/index.d.ts +1 -0
  26. package/dist/formatter/index.js +26 -0
  27. package/dist/ir/builder.d.ts +2 -1
  28. package/dist/ir/types.d.ts +7 -2
  29. package/dist/ir/types.js +1 -1
  30. package/dist/lowering/index.d.ts +2 -0
  31. package/dist/lowering/index.js +183 -8
  32. package/dist/mc-test/runner.d.ts +2 -2
  33. package/dist/mc-test/runner.js +3 -3
  34. package/dist/mc-test/setup.js +2 -2
  35. package/dist/parser/index.d.ts +2 -0
  36. package/dist/parser/index.js +75 -7
  37. package/docs/COMPILATION_STATS.md +24 -24
  38. package/docs/IMPLEMENTATION_GUIDE.md +1 -1
  39. package/docs/STRUCTURE_TARGET.md +1 -1
  40. package/editors/vscode/.vscodeignore +1 -0
  41. package/editors/vscode/icons/mcrs.svg +7 -0
  42. package/editors/vscode/icons/redscript-icons.json +10 -0
  43. package/editors/vscode/out/extension.js +152 -9
  44. package/editors/vscode/package.json +10 -3
  45. package/editors/vscode/src/hover.ts +55 -2
  46. package/editors/vscode/src/symbols.ts +42 -0
  47. package/package.json +1 -1
  48. package/src/__tests__/cli.test.ts +10 -10
  49. package/src/__tests__/codegen.test.ts +1 -1
  50. package/src/__tests__/diagnostics.test.ts +5 -5
  51. package/src/__tests__/e2e.test.ts +134 -5
  52. package/src/__tests__/lowering.test.ts +48 -3
  53. package/src/__tests__/mc-integration.test.ts +285 -10
  54. package/src/__tests__/mc-syntax.test.ts +3 -3
  55. package/src/__tests__/nbt.test.ts +2 -2
  56. package/src/__tests__/optimizer-advanced.test.ts +3 -3
  57. package/src/__tests__/runtime.test.ts +1 -1
  58. package/src/ast/types.ts +20 -3
  59. package/src/cli.ts +10 -10
  60. package/src/codegen/mcfunction/index.ts +9 -2
  61. package/src/codegen/structure/index.ts +8 -1
  62. package/src/examples/capture_the_flag.mcrs +208 -0
  63. package/src/examples/{counter.rs → counter.mcrs} +1 -1
  64. package/src/examples/hunger_games.mcrs +301 -0
  65. package/src/examples/new_features_demo.mcrs +193 -0
  66. package/src/examples/parkour_race.mcrs +233 -0
  67. package/src/examples/rpg.mcrs +13 -0
  68. package/src/examples/{shop.rs → shop.mcrs} +1 -1
  69. package/src/examples/{showcase_game.rs → showcase_game.mcrs} +3 -3
  70. package/src/examples/{turret.rs → turret.mcrs} +1 -1
  71. package/src/examples/zombie_survival.mcrs +314 -0
  72. package/src/ir/builder.ts +3 -1
  73. package/src/ir/types.ts +8 -2
  74. package/src/lowering/index.ts +156 -8
  75. package/src/mc-test/runner.ts +3 -3
  76. package/src/mc-test/setup.ts +2 -2
  77. package/src/parser/index.ts +81 -8
  78. package/src/stdlib/README.md +155 -147
  79. package/src/stdlib/bossbar.mcrs +68 -0
  80. package/src/stdlib/{cooldown.rs → cooldown.mcrs} +1 -1
  81. package/src/stdlib/effects.mcrs +64 -0
  82. package/src/stdlib/interactions.mcrs +195 -0
  83. package/src/stdlib/inventory.mcrs +38 -0
  84. package/src/stdlib/mobs.mcrs +99 -0
  85. package/src/stdlib/particles.mcrs +52 -0
  86. package/src/stdlib/sets.mcrs +20 -0
  87. package/src/stdlib/spawn.mcrs +41 -0
  88. package/src/stdlib/teams.mcrs +68 -0
  89. package/src/stdlib/world.mcrs +92 -0
  90. package/src/examples/rpg.rs +0 -13
  91. package/src/stdlib/mobs.rs +0 -99
  92. /package/src/examples/{arena.rs → arena.mcrs} +0 -0
  93. /package/src/examples/{pvp_arena.rs → pvp_arena.mcrs} +0 -0
  94. /package/src/examples/{quiz.rs → quiz.mcrs} +0 -0
  95. /package/src/examples/{stdlib_demo.rs → stdlib_demo.mcrs} +0 -0
  96. /package/src/examples/{world_manager.rs → world_manager.mcrs} +0 -0
  97. /package/src/stdlib/{combat.rs → combat.mcrs} +0 -0
  98. /package/src/stdlib/{math.rs → math.mcrs} +0 -0
  99. /package/src/stdlib/{player.rs → player.mcrs} +0 -0
  100. /package/src/stdlib/{strings.rs → strings.mcrs} +0 -0
  101. /package/src/stdlib/{timer.rs → timer.mcrs} +0 -0
  102. /package/src/templates/{combat.rs → combat.mcrs} +0 -0
  103. /package/src/templates/{economy.rs → economy.mcrs} +0 -0
  104. /package/src/templates/{mini-game-framework.rs → mini-game-framework.mcrs} +0 -0
  105. /package/src/templates/{quest.rs → quest.mcrs} +0 -0
  106. /package/src/test_programs/{zombie_game.rs → zombie_game.mcrs} +0 -0
@@ -0,0 +1,72 @@
1
+ name: 🐛 Bug Report
2
+ description: Report a bug in RedScript
3
+ labels: ["bug"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for reporting a bug! Please fill out the sections below.
9
+
10
+ - type: textarea
11
+ id: description
12
+ attributes:
13
+ label: Description
14
+ description: What happened?
15
+ placeholder: A clear description of the bug
16
+ validations:
17
+ required: true
18
+
19
+ - type: textarea
20
+ id: reproduction
21
+ attributes:
22
+ label: Code to Reproduce
23
+ description: Minimal RedScript code that triggers the bug
24
+ render: rust
25
+ placeholder: |
26
+ fn example() {
27
+ // your code here
28
+ }
29
+ validations:
30
+ required: true
31
+
32
+ - type: textarea
33
+ id: expected
34
+ attributes:
35
+ label: Expected Behavior
36
+ description: What should have happened?
37
+ validations:
38
+ required: true
39
+
40
+ - type: textarea
41
+ id: actual
42
+ attributes:
43
+ label: Actual Behavior
44
+ description: What actually happened?
45
+ validations:
46
+ required: true
47
+
48
+ - type: input
49
+ id: version
50
+ attributes:
51
+ label: RedScript Version
52
+ description: Run `redscript --version`
53
+ placeholder: "1.0.0"
54
+ validations:
55
+ required: true
56
+
57
+ - type: dropdown
58
+ id: os
59
+ attributes:
60
+ label: Operating System
61
+ options:
62
+ - macOS
63
+ - Windows
64
+ - Linux
65
+ validations:
66
+ required: true
67
+
68
+ - type: textarea
69
+ id: context
70
+ attributes:
71
+ label: Additional Context
72
+ description: Any other relevant information (error messages, stack traces, etc.)
@@ -0,0 +1,57 @@
1
+ name: ✨ Feature Request
2
+ description: Suggest a new feature for RedScript
3
+ labels: ["enhancement"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for your feature idea! Please describe it below.
9
+
10
+ - type: textarea
11
+ id: problem
12
+ attributes:
13
+ label: Problem
14
+ description: What problem does this feature solve?
15
+ placeholder: I'm always frustrated when...
16
+ validations:
17
+ required: true
18
+
19
+ - type: textarea
20
+ id: solution
21
+ attributes:
22
+ label: Proposed Solution
23
+ description: How would you like RedScript to solve this?
24
+ placeholder: |
25
+ I'd like a syntax like:
26
+ ```rs
27
+ // example code
28
+ ```
29
+ validations:
30
+ required: true
31
+
32
+ - type: textarea
33
+ id: alternatives
34
+ attributes:
35
+ label: Alternatives Considered
36
+ description: Any alternative solutions or workarounds you've considered?
37
+
38
+ - type: dropdown
39
+ id: category
40
+ attributes:
41
+ label: Category
42
+ options:
43
+ - Language Feature
44
+ - Builtin Function
45
+ - Standard Library
46
+ - CLI / Tooling
47
+ - VSCode Extension
48
+ - Documentation
49
+ - Other
50
+ validations:
51
+ required: true
52
+
53
+ - type: textarea
54
+ id: context
55
+ attributes:
56
+ label: Additional Context
57
+ description: Any other context, examples, or screenshots
@@ -1,34 +1,26 @@
1
- ## What does this PR do?
1
+ ## Description
2
2
 
3
- <!-- Brief description -->
3
+ <!-- What does this PR do? -->
4
4
 
5
- ## Type of change
5
+ ## Type of Change
6
6
 
7
- - [ ] Bug fix
8
- - [ ] New language feature
9
- - [ ] New builtin / stdlib
10
- - [ ] Optimizer improvement
11
- - [ ] Tooling / CLI
12
- - [ ] Docs
7
+ - [ ] 🐛 Bug fix
8
+ - [ ] New feature
9
+ - [ ] 📝 Documentation
10
+ - [ ] ♻️ Refactor
11
+ - [ ] 🧪 Tests
13
12
 
14
- ## Checklist
15
-
16
- - [ ] `npm run build` passes
17
- - [ ] `npm test` passes (all existing tests green)
18
- - [ ] New tests added for new behavior
19
- - [ ] If adding a builtin: added to `docs/LANGUAGE_REFERENCE.md` and wiki Builtins page
20
- - [ ] If changing syntax: updated `docs/LANGUAGE_REFERENCE.md`
13
+ ## Related Issues
21
14
 
22
- ## Test coverage
15
+ <!-- Link related issues: Fixes #123 -->
23
16
 
24
- <!-- Which test file(s) cover this change? -->
17
+ ## Checklist
25
18
 
26
- ## Example
19
+ - [ ] `npm run build` passes
20
+ - [ ] `npm test` passes
21
+ - [ ] Tests added for new features
22
+ - [ ] Documentation updated (if applicable)
27
23
 
28
- ```rs
29
- // Show a RedScript snippet demonstrating the new feature
30
- ```
24
+ ## Screenshots / Examples
31
25
 
32
- ```mcfunction
33
- # Show the expected compiled output
34
- ```
26
+ <!-- If applicable, show before/after or example output -->
package/CHANGELOG.md ADDED
@@ -0,0 +1,58 @@
1
+ # Changelog
2
+
3
+ All notable changes to RedScript will be documented in this file.
4
+
5
+ ## [1.0.0] - 2026-03-12
6
+
7
+ ### 🎉 Initial Release
8
+
9
+ #### Language Features
10
+ - Variables with type inference: `let x = 5;`
11
+ - Functions with typed parameters and return types
12
+ - Control flow: `if`/`else`, `while`, `for i in 0..10`
13
+ - `foreach` for entity iteration
14
+ - Structs and Enums
15
+ - Lambda expressions: `(x: int) => x * 2`
16
+ - NBT structured parameters
17
+ - `@load` decorator for datapack initialization
18
+ - Global variables (compile to scoreboard fake players)
19
+ - `#mc_name` syntax for bare Minecraft identifiers
20
+ - Match expressions with pattern matching
21
+
22
+ #### Builtins (34+)
23
+ - Player: `say`, `tell`, `title`, `actionbar`, `give`, `kill`, `tp`, `effect`
24
+ - Scoreboard: `scoreboard_get`, `scoreboard_set`, `scoreboard_add`
25
+ - World: `setblock`, `fill`, `summon`, `weather`, `time_set`, `gamerule`
26
+ - Data: `data_get`, `data_merge`
27
+ - Runtime Sets: `set_new`, `set_add`, `set_contains`, `set_remove`
28
+ - And more...
29
+
30
+ #### Standard Library
31
+ - `math.mcrs` - `abs`, `min`, `max`, `clamp`, `sign`
32
+ - `player.mcrs` - `heal`, `feed`, `teleport_spawn`
33
+ - `cooldown.mcrs` - Cooldown management
34
+ - `timer.mcrs` - Timer utilities
35
+ - `combat.mcrs` - Combat helpers
36
+ - `mobs.mcrs` - Mob spawning utilities
37
+ - `sets.mcrs` - Set operations
38
+ - `strings.mcrs` - String formatting
39
+
40
+ #### CLI
41
+ - `redscript compile` - Compile to datapack
42
+ - `redscript watch` - Watch mode with hot reload
43
+ - `redscript check` - Type checking
44
+ - `redscript fmt` - Code formatter
45
+ - `redscript repl` - Interactive REPL
46
+ - Output targets: datapack, cmdblock, structure
47
+
48
+ #### Tooling
49
+ - VSCode Extension (v0.8.2) with syntax highlighting, autocomplete, go-to-definition, rename
50
+ - Online IDE: https://redscript-ide.pages.dev
51
+ - Documentation: https://redscript-docs.pages.dev
52
+ - Paper plugin for integration testing
53
+
54
+ #### Optimizer
55
+ - Dead code elimination
56
+ - Constant folding
57
+ - Inline simple functions
58
+ - Remove redundant scoreboard operations
@@ -0,0 +1,140 @@
1
+ # Contributing to RedScript
2
+
3
+ Thanks for your interest in contributing to RedScript! 🎮
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Node.js 18+
10
+ - npm or pnpm
11
+
12
+ ### Setup
13
+
14
+ ```bash
15
+ git clone https://github.com/bkmashiro/redscript.git
16
+ cd redscript
17
+ npm install
18
+ npm run build
19
+ npm test
20
+ ```
21
+
22
+ ### Project Structure
23
+
24
+ ```
25
+ redscript/
26
+ ├── src/
27
+ │ ├── parser/ # Lexer & Parser (grammar → AST)
28
+ │ ├── lowering/ # AST → mcfunction code generation
29
+ │ ├── cli.ts # CLI entry point
30
+ │ ├── stdlib/ # Standard library (.mcrs files)
31
+ │ ├── examples/ # Example datapacks
32
+ │ └── __tests__/ # Jest tests
33
+ ├── redscript-vscode/ # VSCode extension
34
+ └── docs/ # Documentation
35
+ ```
36
+
37
+ ## Development Workflow
38
+
39
+ ### Building
40
+
41
+ ```bash
42
+ npm run build # Compile TypeScript
43
+ npm run watch # Watch mode
44
+ ```
45
+
46
+ ### Testing
47
+
48
+ ```bash
49
+ npm test # Run all tests
50
+ npm test -- --watch # Watch mode
51
+ npm test -- -t "foreach" # Run specific test
52
+ ```
53
+
54
+ ### Code Style
55
+
56
+ - TypeScript with strict mode
57
+ - No semicolons (handled by prettier)
58
+ - 2-space indentation
59
+
60
+ ## Making Changes
61
+
62
+ ### Adding a New Builtin Function
63
+
64
+ 1. Add to `BUILTINS` map in `src/lowering/index.ts`:
65
+
66
+ ```typescript
67
+ my_builtin: ([arg1, arg2]) => `my command ${arg1} ${arg2}`,
68
+ ```
69
+
70
+ 2. For complex builtins (returning values), add special handling in `lowerCall()`.
71
+
72
+ 3. Add tests in `src/__tests__/`:
73
+
74
+ ```typescript
75
+ it('compiles my_builtin', () => {
76
+ const source = `fn test() { my_builtin("a", "b"); }`
77
+ const files = compile(source)
78
+ expect(getFunction(files, 'test')).toContain('my command a b')
79
+ })
80
+ ```
81
+
82
+ 4. Add documentation in docs.
83
+
84
+ ### Adding Language Features
85
+
86
+ 1. Update grammar in `src/parser/` (lexer + parser)
87
+ 2. Add AST types if needed
88
+ 3. Update lowering in `src/lowering/`
89
+ 4. Add comprehensive tests
90
+ 5. Update VSCode extension syntax highlighting
91
+
92
+ ### Stdlib Contributions
93
+
94
+ Add utility functions to `src/stdlib/`:
95
+
96
+ ```mcrs
97
+ // src/stdlib/my_utils.mcrs
98
+
99
+ /// Useful helper function
100
+ fn my_helper(target: selector) {
101
+ // implementation
102
+ }
103
+ ```
104
+
105
+ ## Pull Request Process
106
+
107
+ 1. Fork the repo
108
+ 2. Create a feature branch: `git checkout -b feat/my-feature`
109
+ 3. Make changes with tests
110
+ 4. Run `npm run build && npm test`
111
+ 5. Commit with clear message: `feat: add X` / `fix: resolve Y`
112
+ 6. Push and open PR
113
+
114
+ ### Commit Convention
115
+
116
+ - `feat:` New feature
117
+ - `fix:` Bug fix
118
+ - `docs:` Documentation
119
+ - `test:` Tests
120
+ - `refactor:` Code refactoring
121
+ - `chore:` Maintenance
122
+
123
+ ## Testing on Real Server
124
+
125
+ For integration testing with a real Minecraft server:
126
+
127
+ 1. Set up Paper 1.21.4 server with [testharness plugin](https://github.com/bkmashiro/redscript-testharness)
128
+ 2. Run: `npm run test:mc`
129
+
130
+ See [Testing Guide](https://redscript-docs.pages.dev/en/guide/testing) for details.
131
+
132
+ ## Need Help?
133
+
134
+ - Open an issue for bugs or feature requests
135
+ - Check existing issues before creating new ones
136
+ - Join discussions in GitHub Discussions
137
+
138
+ ## License
139
+
140
+ By contributing, you agree that your contributions will be licensed under the MIT License.
package/README.md CHANGED
@@ -7,11 +7,16 @@
7
7
  Write clean game logic. RedScript handles the scoreboard spaghetti.
8
8
 
9
9
  [![CI](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml)
10
+ [![Tests](https://img.shields.io/badge/tests-510%20passing-brightgreen)](https://github.com/bkmashiro/redscript)
10
11
  [![npm](https://img.shields.io/npm/v/redscript-mc?color=cb3837)](https://www.npmjs.com/package/redscript-mc)
12
+ [![npm downloads](https://img.shields.io/npm/dm/redscript-mc?color=cb3837)](https://www.npmjs.com/package/redscript-mc)
13
+ [![VSCode](https://img.shields.io/badge/VSCode-Extension-007ACC?logo=visualstudiocode)](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
14
+ [![Online IDE](https://img.shields.io/badge/Try-Online%20IDE-orange)](https://redscript-ide.pages.dev)
11
15
  [![license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
12
- [![tests](https://img.shields.io/badge/tests-423%20passing-brightgreen)](./src/__tests__)
13
16
 
14
- [中文版](./README.zh.md) · [Wiki](https://github.com/bkmashiro/redscript/wiki) · [Quick Start](#quick-start)
17
+ [中文版](./README.zh.md) · [Quick Start](#quick-start) · [Docs](https://redscript-docs.pages.dev) · [Contributing](./CONTRIBUTING.md)
18
+
19
+ ### 🚀 [Try it online — no install needed!](https://redscript-ide.pages.dev)
15
20
 
16
21
  </div>
17
22
 
@@ -24,8 +29,8 @@ You want to make a Minecraft mini-game. You need a countdown timer, kill counter
24
29
  With RedScript, it's this:
25
30
 
26
31
  ```rs
27
- // pvp_game.rs
28
- import "stdlib/player.rs"
32
+ // pvp_game.mcrs
33
+ import "stdlib/player.mcrs"
29
34
 
30
35
  const GAME_TIME: int = 300;
31
36
 
@@ -67,20 +72,24 @@ One file. Compiles to a ready-to-use datapack in seconds.
67
72
 
68
73
  ### Quick Start
69
74
 
70
- #### Install
75
+ #### Option 1: Online IDE (No Install)
71
76
 
72
- ```bash
73
- npm install -g redscript
74
- ```
77
+ **[→ redscript-ide.pages.dev](https://redscript-ide.pages.dev)** — Write code, see output instantly.
78
+
79
+ #### Option 2: VSCode Extension
80
+
81
+ 1. Install [RedScript for VSCode](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
82
+ 2. Get syntax highlighting, auto-complete, hover docs, and more
75
83
 
76
- #### Compile
84
+ #### Option 3: CLI
77
85
 
78
86
  ```bash
79
- redscript compile pvp_game.rs -o ./my-datapack
87
+ npm install -g redscript-mc
88
+ redscript compile game.mcrs -o ./my-datapack
80
89
  ```
81
90
 
82
91
  ```
83
- ✓ Compiled pvp_game.rs
92
+ ✓ Compiled pvp_game.mcrs
84
93
  Namespace : pvp_game
85
94
  Functions : 7
86
95
  Commands : 34 → 28 (optimizer: −18%)
@@ -230,11 +239,11 @@ redscript validate <file> Validate MC commands
230
239
  ### Standard Library
231
240
 
232
241
  ```rs
233
- import "stdlib/math.rs" // abs, min, max, clamp
234
- import "stdlib/player.rs" // is_alive, in_range, get_health
235
- import "stdlib/timer.rs" // start_timer, tick_timer, has_elapsed
236
- import "stdlib/cooldown.rs" // set_cooldown, check_cooldown
237
- import "stdlib/mobs.rs" // ZOMBIE, SKELETON, CREEPER, ... (60+ constants)
242
+ import "stdlib/math.mcrs" // abs, min, max, clamp
243
+ import "stdlib/player.mcrs" // is_alive, in_range, get_health
244
+ import "stdlib/timer.mcrs" // start_timer, tick_timer, has_elapsed
245
+ import "stdlib/cooldown.mcrs" // set_cooldown, check_cooldown
246
+ import "stdlib/mobs.mcrs" // ZOMBIE, SKELETON, CREEPER, ... (60+ constants)
238
247
  ```
239
248
 
240
249
  ---
@@ -244,10 +253,10 @@ import "stdlib/mobs.rs" // ZOMBIE, SKELETON, CREEPER, ... (60+ constants)
244
253
  | | |
245
254
  |---|---|
246
255
  | 📖 [Language Reference](docs/LANGUAGE_REFERENCE.md) | Full syntax & type system |
247
- | 🔧 [Builtins](https://github.com/bkmashiro/redscript/wiki/Builtins) | All 34+ MC builtin functions |
248
- | ⚡ [Optimizer](https://github.com/bkmashiro/redscript/wiki/Optimizer) | How the optimizer works |
256
+ | 🔧 [Builtins](https://redscript-docs.pages.dev/Builtins) | All 34+ MC builtin functions |
257
+ | ⚡ [Optimizer](https://redscript-docs.pages.dev/Optimizer) | How the optimizer works |
249
258
  | 🧱 [Structure Target](docs/STRUCTURE_TARGET.md) | Compile to NBT command block structures |
250
- | 🧪 [Integration Testing](https://github.com/bkmashiro/redscript/wiki/Integration-Testing) | Test against a real Paper server |
259
+ | 🧪 [Integration Testing](https://redscript-docs.pages.dev/Integration-Testing) | Test against a real Paper server |
251
260
  | 🏗 [Implementation Guide](docs/IMPLEMENTATION_GUIDE.md) | Compiler internals |
252
261
 
253
262
  ---
package/README.zh.md CHANGED
@@ -7,11 +7,16 @@
7
7
  写干净的游戏逻辑,把记分板的面条代码交给 RedScript 处理。
8
8
 
9
9
  [![CI](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml)
10
+ [![Tests](https://img.shields.io/badge/tests-510%20passing-brightgreen)](https://github.com/bkmashiro/redscript)
10
11
  [![npm](https://img.shields.io/npm/v/redscript-mc?color=cb3837)](https://www.npmjs.com/package/redscript-mc)
12
+ [![npm downloads](https://img.shields.io/npm/dm/redscript-mc?color=cb3837)](https://www.npmjs.com/package/redscript-mc)
13
+ [![VSCode](https://img.shields.io/badge/VSCode-插件-007ACC?logo=visualstudiocode)](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
14
+ [![在线 IDE](https://img.shields.io/badge/试用-在线IDE-orange)](https://redscript-ide.pages.dev)
11
15
  [![license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
12
- [![tests](https://img.shields.io/badge/tests-423%20passing-brightgreen)](./src/__tests__)
13
16
 
14
- [English](./README.md) · [Wiki](https://github.com/bkmashiro/redscript/wiki) · [快速开始](#快速开始)
17
+ [English](./README.md) · [快速开始](#快速开始) · [文档](https://redscript-docs.pages.dev) · [贡献指南](./CONTRIBUTING.md)
18
+
19
+ ### 🚀 [在线试用 — 无需安装!](https://redscript-ide.pages.dev)
15
20
 
16
21
  </div>
17
22
 
@@ -24,8 +29,8 @@
24
29
  用 RedScript,就是这样:
25
30
 
26
31
  ```rs
27
- // pvp_game.rs
28
- import "stdlib/player.rs"
32
+ // pvp_game.mcrs
33
+ import "stdlib/player.mcrs"
29
34
 
30
35
  const GAME_TIME: int = 300;
31
36
 
@@ -67,20 +72,24 @@ fn on_kill() {
67
72
 
68
73
  ### 快速开始
69
74
 
70
- #### 安装
75
+ #### 方式 1:在线 IDE(无需安装)
71
76
 
72
- ```bash
73
- npm install -g redscript
74
- ```
77
+ **[→ redscript-ide.pages.dev](https://redscript-ide.pages.dev)** — 写代码,实时看输出。
78
+
79
+ #### 方式 2:VSCode 插件
80
+
81
+ 1. 安装 [RedScript for VSCode](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
82
+ 2. 获得语法高亮、自动补全、悬停文档等功能
75
83
 
76
- #### 编译
84
+ #### 方式 3:命令行
77
85
 
78
86
  ```bash
79
- redscript compile pvp_game.rs -o ./my-datapack
87
+ npm install -g redscript-mc
88
+ redscript compile game.mcrs -o ./my-datapack
80
89
  ```
81
90
 
82
91
  ```
83
- ✓ 已编译 pvp_game.rs
92
+ ✓ 已编译 pvp_game.mcrs
84
93
  命名空间 : pvp_game
85
94
  函数数量 : 7
86
95
  命令数量 : 34 → 28 (优化器节省了 18%)
@@ -230,11 +239,11 @@ redscript validate <file> 验证 MC 命令语法
230
239
  ### 标准库
231
240
 
232
241
  ```rs
233
- import "stdlib/math.rs" // abs, min, max, clamp
234
- import "stdlib/player.rs" // is_alive, in_range, get_health
235
- import "stdlib/timer.rs" // start_timer, tick_timer, has_elapsed
236
- import "stdlib/cooldown.rs" // set_cooldown, check_cooldown
237
- import "stdlib/mobs.rs" // ZOMBIE, SKELETON, CREEPER ... (60+ 实体常量)
242
+ import "stdlib/math.mcrs" // abs, min, max, clamp
243
+ import "stdlib/player.mcrs" // is_alive, in_range, get_health
244
+ import "stdlib/timer.mcrs" // start_timer, tick_timer, has_elapsed
245
+ import "stdlib/cooldown.mcrs" // set_cooldown, check_cooldown
246
+ import "stdlib/mobs.mcrs" // ZOMBIE, SKELETON, CREEPER ... (60+ 实体常量)
238
247
  ```
239
248
 
240
249
  ---
@@ -244,10 +253,10 @@ import "stdlib/mobs.rs" // ZOMBIE, SKELETON, CREEPER ... (60+ 实体常量
244
253
  | | |
245
254
  |---|---|
246
255
  | 📖 [语言参考](docs/LANGUAGE_REFERENCE.md) | 完整语法与类型系统 |
247
- | 🔧 [内置函数](https://github.com/bkmashiro/redscript/wiki/Builtins) | 所有 34+ MC 内置函数 |
248
- | ⚡ [优化器](https://github.com/bkmashiro/redscript/wiki/Optimizer) | 各优化 Pass 说明 |
256
+ | 🔧 [内置函数](https://redscript-docs.pages.dev/Builtins) | 所有 34+ MC 内置函数 |
257
+ | ⚡ [优化器](https://redscript-docs.pages.dev/Optimizer) | 各优化 Pass 说明 |
249
258
  | 🧱 [结构体目标](docs/STRUCTURE_TARGET.md) | 编译到 NBT 命令方块结构体 |
250
- | 🧪 [集成测试](https://github.com/bkmashiro/redscript/wiki/Integration-Testing) | 在真实 Paper 服务器上测试 |
259
+ | 🧪 [集成测试](https://redscript-docs.pages.dev/Integration-Testing) | 在真实 Paper 服务器上测试 |
251
260
  | 🏗 [实现指南](docs/IMPLEMENTATION_GUIDE.md) | 编译器内部原理 |
252
261
 
253
262
  ---
@@ -43,10 +43,10 @@ describe('CLI API', () => {
43
43
  describe('imports', () => {
44
44
  it('compiles a file with imported helpers', () => {
45
45
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-imports-'));
46
- const libPath = path.join(tempDir, 'lib.rs');
47
- const mainPath = path.join(tempDir, 'main.rs');
46
+ const libPath = path.join(tempDir, 'lib.mcrs');
47
+ const mainPath = path.join(tempDir, 'main.mcrs');
48
48
  fs.writeFileSync(libPath, 'fn double(x: int) -> int { return x + x; }\n');
49
- fs.writeFileSync(mainPath, 'import "./lib.rs"\n\nfn main() { let value: int = double(2); }\n');
49
+ fs.writeFileSync(mainPath, 'import "./lib.mcrs"\n\nfn main() { let value: int = double(2); }\n');
50
50
  const source = fs.readFileSync(mainPath, 'utf-8');
51
51
  const result = (0, index_1.compile)(source, { namespace: 'imports', filePath: mainPath });
52
52
  expect(result.files.length).toBeGreaterThan(0);
@@ -55,12 +55,12 @@ describe('CLI API', () => {
55
55
  });
56
56
  it('deduplicates circular imports', () => {
57
57
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-circular-'));
58
- const aPath = path.join(tempDir, 'a.rs');
59
- const bPath = path.join(tempDir, 'b.rs');
60
- const mainPath = path.join(tempDir, 'main.rs');
61
- fs.writeFileSync(aPath, 'import "./b.rs"\n\nfn from_a() -> int { return 1; }\n');
62
- fs.writeFileSync(bPath, 'import "./a.rs"\n\nfn from_b() -> int { return from_a(); }\n');
63
- fs.writeFileSync(mainPath, 'import "./a.rs"\n\nfn main() { let value: int = from_b(); }\n');
58
+ const aPath = path.join(tempDir, 'a.mcrs');
59
+ const bPath = path.join(tempDir, 'b.mcrs');
60
+ const mainPath = path.join(tempDir, 'main.mcrs');
61
+ fs.writeFileSync(aPath, 'import "./b.mcrs"\n\nfn from_a() -> int { return 1; }\n');
62
+ fs.writeFileSync(bPath, 'import "./a.mcrs"\n\nfn from_b() -> int { return from_a(); }\n');
63
+ fs.writeFileSync(mainPath, 'import "./a.mcrs"\n\nfn main() { let value: int = from_b(); }\n');
64
64
  const source = fs.readFileSync(mainPath, 'utf-8');
65
65
  const result = (0, index_1.compile)(source, { namespace: 'circular', filePath: mainPath });
66
66
  expect(result.ir.functions.filter(fn => fn.name === 'from_a')).toHaveLength(1);
@@ -110,7 +110,7 @@ fn build() {
110
110
  describe('--stats flag', () => {
111
111
  it('prints optimizer statistics', () => {
112
112
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'redscript-stats-'));
113
- const inputPath = path.join(tempDir, 'input.rs');
113
+ const inputPath = path.join(tempDir, 'input.mcrs');
114
114
  const outputDir = path.join(tempDir, 'out');
115
115
  fs.writeFileSync(inputPath, 'fn build() { setblock((0, 64, 0), "minecraft:stone"); setblock((1, 64, 0), "minecraft:stone"); }');
116
116
  const stdout = (0, child_process_1.execFileSync)(process.execPath, ['-r', 'ts-node/register', path.join(process.cwd(), 'src/cli.ts'), 'compile', inputPath, '-o', outputDir, '--stats'], { cwd: process.cwd(), encoding: 'utf-8' });
@@ -10,7 +10,7 @@ describe('generateDatapack', () => {
10
10
  expect(JSON.parse(meta.content).pack.pack_format).toBe(26);
11
11
  });
12
12
  it('generates __load.mcfunction with objective setup', () => {
13
- const mod = { namespace: 'mypack', functions: [], globals: ['counter'] };
13
+ const mod = { namespace: 'mypack', functions: [], globals: [{ name: 'counter', init: 0 }] };
14
14
  const files = (0, mcfunction_1.generateDatapack)(mod);
15
15
  const load = files.find(f => f.path.includes('__load.mcfunction'));
16
16
  expect(load?.content).toContain('scoreboard objectives add rs dummy');
@@ -23,8 +23,8 @@ describe('DiagnosticError', () => {
23
23
  });
24
24
  it('includes file path when available', () => {
25
25
  const source = 'let x = foo();';
26
- const error = new diagnostics_1.DiagnosticError('TypeError', 'Unknown function: foo', { file: 'test.rs', line: 1, col: 9 }, source.split('\n'));
27
- expect((0, diagnostics_1.formatError)(error, source)).toContain('Error in test.rs at line 1, col 9:');
26
+ const error = new diagnostics_1.DiagnosticError('TypeError', 'Unknown function: foo', { file: 'test.mcrs', line: 1, col: 9 }, source.split('\n'));
27
+ expect((0, diagnostics_1.formatError)(error, source)).toContain('Error in test.mcrs at line 1, col 9:');
28
28
  });
29
29
  });
30
30
  describe('format', () => {
@@ -43,9 +43,9 @@ describe('DiagnosticError', () => {
43
43
  expect(formatted).toContain('^');
44
44
  });
45
45
  it('formats error with file path', () => {
46
- const error = new diagnostics_1.DiagnosticError('LexError', 'Unexpected character', { file: 'test.rs', line: 1, col: 1 }, ['@@@']);
46
+ const error = new diagnostics_1.DiagnosticError('LexError', 'Unexpected character', { file: 'test.mcrs', line: 1, col: 1 }, ['@@@']);
47
47
  const formatted = error.format();
48
- expect(formatted).toContain('test.rs:');
48
+ expect(formatted).toContain('test.mcrs:');
49
49
  expect(formatted).toContain('[LexError]');
50
50
  });
51
51
  it('handles missing source lines gracefully', () => {
@@ -110,7 +110,7 @@ describe('compile function', () => {
110
110
  expect(result.error?.message).toContain("Expected ';'");
111
111
  });
112
112
  it('includes file path in error', () => {
113
- const result = (0, compile_1.compile)('fn main() { }', { filePath: 'test.rs' });
113
+ const result = (0, compile_1.compile)('fn main() { }', { filePath: 'test.mcrs' });
114
114
  // This is valid, but test that filePath is passed through
115
115
  expect(result.success).toBe(true);
116
116
  });