Skip to content

Commit

Permalink
update language feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Alumopper committed Aug 30, 2024
1 parent 52e5f91 commit abb13e1
Show file tree
Hide file tree
Showing 18 changed files with 370 additions and 187 deletions.
24 changes: 20 additions & 4 deletions docs/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const sidebar: DefaultTheme.Sidebar = {
{
text: "顶层语句",
link: "/zh/quickstart/02base/04top-statements",
},
{
text: "原生命令",
link: "/zh/quickstart/02base/05original-command",
}
],
},
Expand All @@ -59,6 +63,10 @@ export const sidebar: DefaultTheme.Sidebar = {
{
text: "内联函数",
link: "/zh/quickstart/04function/03inline-function",
},
{
text: "编译期函数",
link: "/zh/quickstart/04function/04compiletime-function",
}
],
},
Expand All @@ -73,9 +81,13 @@ export const sidebar: DefaultTheme.Sidebar = {
text: "类的成员",
link: "/zh/quickstart/05class/02member",
},
{
text: "单例",
link: "/zh/quickstart/05class/03object",
},
{
text: "继承和抽象",
link: "/zh/quickstart/05class/03inheritance-abstract",
link: "/zh/quickstart/05class/04inheritance-abstract",
}
],
},
Expand Down Expand Up @@ -166,6 +178,10 @@ export const sidebar: DefaultTheme.Sidebar = {
{
text: "JavaVar",
link: "/zh/quickstart/11mni/03javavar",
},
{
text: "注解",
link: "/zh/quickstart/11mni/04annotation",
}
],
},
Expand Down Expand Up @@ -235,11 +251,11 @@ export const sidebar: DefaultTheme.Sidebar = {
link: "/en/quickstart/05class/01define-and-instantiate",
},
{
text: "类的成员",
text: "Member of class ",
link: "/en/quickstart/05class/02member",
},
{
text: "继承和抽象",
text: "Inheritance and abstraction",
link: "/en/quickstart/05class/03inheritance-abstract",
}
],
Expand All @@ -248,7 +264,7 @@ export const sidebar: DefaultTheme.Sidebar = {
text: "Interface",
"items": [
{
text: "定义和实现接口",
text: "Define and implement ",
link: "/en/quickstart/06interface/01define-and-implement",
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ hero:
text: QuickStart
link: /en/quickstart/index
- theme: alt
text: Overview
link: /en/overview
text: GitHub
link: https://github.com/MinecraftFunctionPlusPlus/MCFPP

features:
- title: Ultimate Experience
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ hero:
text: 快速开始
link: /zh/quickstart/index
- theme: alt
text: 语法总览
link: /zh/overview
text: GitHub
link: https://github.com/MinecraftFunctionPlusPlus/MCFPP

features:
- title: 极致体验
details: 通过精心设计的语法,让数据包的开发体验更加流畅
- title: 跨版本编译
details: 一份代码,多版本支持,无需担心Mojang的一周一改
- title: 无缝集成
details: 强大的MNI框架,基于数据包编译期更多的可能
details: 强大的MNI框架,基于数据包编译期,提供更多的可能
---

4 changes: 2 additions & 2 deletions docs/zh/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ hero:
text: 快速开始
link: /zh/quickstart/index
- theme: alt
text: 语法总览
link: /zh/overview
text: GitHub
link: https://github.com/MinecraftFunctionPlusPlus/MCFPP

features:
- title: 极致体验
Expand Down
25 changes: 24 additions & 1 deletion docs/zh/quickstart/01project/02config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,27 @@ lastUpdated: true

# 配置文件

TODO
MCFPP的工程配置文件是一个json文件,一般存放在这个工程的根目录下。它的Json格式如下:

```json
{
//项目文件的路径列表。使用通配符选择所有文件
"files": [
"src/main/mcfpp/**"
],
//项目的源代码目录。文件的命名空间根据文件相对于源代码目录的相对路径决定
"sourcePath": "src/main/mcfpp",
//数据包的描述。是一个原始JSON文本
"description": "",
//数据包的默认命名空间,将会决定数据包中storage等数据的命名空间
"namespace": "test",
//数据包的输出路径。数据包、库文件将会输出在此目录下
"targetPath": "src/main/resources/lib",
//是否 *不* 生成数据包。默认为false
"noDatapack": false,
//是否 *忽略* 标准库。默认为false。如果为true,将不会引用mcfpp的标准库。
"ignoreStdLib": false,
//是否是库。默认为false。库不需要拥有一个入口函数
"isLib": false
}
```
28 changes: 14 additions & 14 deletions docs/zh/quickstart/02base/01variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ int b = i * 6;
|dict|表示一个字典|`{"a":1,"b":2,"c":3}`|
|map|字典的更高级包装,拥有比字典更多的功能|同上|
|string|表示一个字符串|`"mcfpp"`,`"qwq"`|
|jtext|表示一个Json原始文本|`"mcfpp"`,`{"text":"mcfpp","color":"#114514"}`|
|text|表示一个Json原始文本|`"mcfpp"`,`{"text":"mcfpp","color":"#114514"}`|
|entity|表示一个实体。储存了一个实体的UUID||
|selector|表示一个目标选择器|`@a`,`@p[limit=6]`|
|selector|表示一个目标选择器|`@a`,`@p`|

以下是对类型的简要介绍,可以逐一展开查看:

Expand All @@ -43,43 +43,43 @@ int b = i * 6;
:::

::: details float
**float**类型是MCFPP中表示一个单精度浮点数的类型。它可以是正数、负数、零,也可以是十进制、科学计数法等。MCFPP的浮点数运算依赖[小豆的数学库完成](https:#github.com/xiaodou8593/math2.0)。浮点数的运算为纯粹的记分板运算,因此占用量不会很大。
表示MCFPP中的一个浮点数。它的精度和单精度浮点数相当。它可以是正数、负数、零,也可以是十进制、科学计数法等。MCFPP的浮点数运算依赖[小豆的数学库完成](https:#github.com/xiaodou8593/math2.0)。浮点数的运算为纯粹的记分板运算,因此占用量不会很大。
:::

::: details bool
**bool**类型是MCFPP中表示一个布尔型数据的类型。它只有两个值:`true``false`。bool类型的数据会被储存为一个记分板变量,因此它的大小和记分板的大小一样。
表示一个布尔型数据。它只有两个值:`true``false`。bool类型的数据会被储存为一个记分板变量,因此它的大小和记分板的大小一样。
:::

::: details nbt
**nbt**类型表示一个NBT数据。不过实际上,NBT类型的数据更多情况下只是储存了一个NBT路径,因此把它们称作NBT指针也不足为过。值得注意的是,**nbt**类型的变量是大多数基本类型的基础,例如`list``map`等都依托NBT数据的操作实现。
表示一个NBT数据。不过实际上,NBT类型的数据更多情况下只是储存了一个NBT路径,因此把它们称作NBT指针也不足为过。值得注意的是,**nbt**类型的变量是大多数基本类型的基础,例如`list``map`等都依托NBT数据的操作实现。
:::

::: details list
**list**类型表示一个列表`list`类型实现了java中`ArrayList`的大多数方法,详细可以参考标准库的API。`list`会被储存为一个NBT列表。
表示一个列表`list`类型实现了java中`ArrayList`的大多数方法,详细可以参考标准库的API。`list`会被储存为一个NBT列表。
:::

::: details dict
**dict**类型表示一个字典,被储存为一个NBT复合标签。受MC的限制,`dict`类型只能进行基本的键值对插入和删除操作,无法进行遍历操作。你可以使用`map`来进行更多的操作。
表示一个字典,被储存为一个NBT复合标签。受MC的限制,`dict`类型只能进行基本的键值对插入和删除操作,无法进行遍历操作。你可以使用`map`来进行更多的操作。
:::

::: details map
**map**类型是`dict`类型的更高级包装,拥有比`dict`更多的功能。`map`类型实现了java中`HashMap`的大多数方法,详细可以参考标准库的API。但是值得注意的是,`map`的更高级包装意味着`map`会拥有比`dict`更多的开销。
`dict`类型的更高级包装,拥有比`dict`更多的功能。`map`类型实现了java中`HashMap`的大多数方法,详细可以参考标准库的API。但是值得注意的是,`map`的更高级包装意味着`map`会拥有比`dict`更多的开销。
:::

::: details string
TODO
表示一个字符串,即NBT中的string标签。
:::

::: details jtext
TODO
::: details text
表示一个原始JSON文本,相较于`string`类型,`text`类型可以包含更多的格式信息,例如颜色、粗体等。`text`类型的数据会被储存为一个NBT复合标签。
:::

::: details entity
TODO
表示单个实体。储存为一个UUID整数型NBT数组。
:::

::: details selector
TODO
表示一个目标选择器。储存为一个字符串。
:::

## var关键字
Expand All @@ -98,7 +98,7 @@ var i; # [!code error] #错误,缺少初始化表达式

## 变量修饰符

变量修饰符可以用来表示变量的类型,包括`dynamic``const``import`
变量修饰符可以用来表示变量的类型,包括`dynamic``const`

- dynamic

Expand Down
31 changes: 31 additions & 0 deletions docs/zh/quickstart/02base/05original-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
lastUpdated: true
---

# 原生命令

MCFPP支持Minecraft原生命令的使用。有两种方法可以使用原生命令:

## 使用`/`插入命令

`/`开头的语句将会被认为是一个原生命令。例如:

```mcfpp
func test(){
/summon minecraft:armor_stand ~ ~ ~
}
```

将会直接在test函数中插入一个summon命令。

## 使用`insert`函数

`insert`函数可以将一个字符串插入到当前位置。例如:

```mcfpp
func test(){
insert("summon minecraft:armor_stand ~ ~ ~");
}
```

将会将`insert`参数中的原文插入到test函数中。值得注意的是,`insert`函数的参数是一个字符串,因此你可以在其中插入任何内容,这同时意味着编译器不会对命令格式进行任何检查。
18 changes: 1 addition & 17 deletions docs/zh/quickstart/03namespace/01namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,4 @@ func test(){ # test:test函数

一个文件中只能声明一次命名空间。

同样的,你也可以在项目配置文件中声明这个命名空间。

```json
{
"file":[
"*"
"D:/workspace/mcfpp/project/*"
],
"version":"1.19.4",
"include":[
"D:/workspace/mcfpp/another_project.json"
],
"targetPath":"./out",
//工程的默认命名空间。可选,默认为default // [!code focus]
"namespace":"mcfpp" // [!code focus]
}
```
若没有声明命名空间,文件的命名空间将会由文件路径相对于源代码路径的相对路径决定。例如,假设源代码目录为`src/main/mcfpp`,那么文件`src/main/mcfpp/test/test.mcfpp`的命名空间将会是`test.test`。源代码路径通过工程配置文件中的`sourcePath`决定。
2 changes: 1 addition & 1 deletion docs/zh/quickstart/04function/02static-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
lastUpdate: true
---

# static关键字
# static关键字<Badge type="tip">可能更改</Badge>

`static`关键字用于声明一个静态参数。静态参数表示,在参数传递的过程中,是传递的参数本身而不是参数的值,因此在函数中对参数的修改会影响外部的变量。例如:

Expand Down
7 changes: 7 additions & 0 deletions docs/zh/quickstart/04function/04compiletime-function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
lastUpdate: true
---

# 编译期函数

TODO
26 changes: 21 additions & 5 deletions docs/zh/quickstart/05class/01define-and-instantiate.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Person{
}
```


## 类的定义

作为一个面向对象的编程语言,MCFPP有完善的面向对象的语法和功能。它的语法和Java/C#的语法非常相似,所以,如果你有相关的基础的话,你应该可以很轻松地上手。
Expand All @@ -45,14 +44,31 @@ class ClassName{

一般情况下,你可以使用`ClassName(参数列表)`来创建一个对象的实例。比如本篇开头的示例`Person`类可以用`Person p = Person("Alumopper",16)`来创建。在MCFPP中,你并不需要`new`关键字。它被省略掉了。

## 类的初始化器<Badge type="tip" text="未来特性" />
## 类的初始化器

在创建类的时候,你可以使用类初始化器来对类的某些成员变量初始化,例如对于上文中的`Person`,有:

```mcfpp
Person p = Person("Alumopper",16){
Person p = Person("Alumopper",16)[
sex = "女"
};
];
```

这样,`p``sex`成员变量就被初始化为`"女"`了。

::: tip

### 不仅仅是类的初始化

事实上,类初始化器可以用在任何地方,而不只是在类的初始化的时候。比如

```mcfpp
func main(){
Test t = Test();
t = t[a = 100];
print(t.toText());
}
```

这样,`p``sex`成员变量就被初始化为`"女"`了。
在这个例子中,类的初始化器实际上是域操作器。`t = t[a = 100]`将t中的a赋值为100。
:::
49 changes: 0 additions & 49 deletions docs/zh/quickstart/05class/03inheritance-abstract.md

This file was deleted.

Loading

0 comments on commit abb13e1

Please sign in to comment.