Skip to content

Commit fcee43c

Browse files
committed
Feature: 向量类型
1 parent d6e7245 commit fcee43c

File tree

4 files changed

+10
-50
lines changed

4 files changed

+10
-50
lines changed

.mclib

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,7 @@
3434

3535
],
3636
"template":[
37-
{
38-
"id":"Test",
39-
"parents":[
40-
"mcfpp.lang:DataObject"
41-
],
42-
"field":{
43-
"vars":[
44-
{
45-
"id":"a",
46-
"type":"int"
47-
},
48-
{
49-
"id":"b",
50-
"type":"int"
51-
},
52-
{
53-
"id":"c",
54-
"type":"int"
55-
},
56-
{
57-
"id":"d",
58-
"type":"int"
59-
}
60-
],
61-
"functions":[
62-
63-
]
64-
}
65-
}
37+
6638
],
6739
"enum":[
6840

src/main/kotlin/top/mcfpp/lang/Var.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ abstract class Var<Self: Var<Self>> : Member, Cloneable, CanSelectMember, Serial
455455

456456
fun replacedBy(v : Var<*>){
457457
if(v == this) return
458-
if(v is MCInt && v.holder != null){
459-
when(val holder = v.holder){
458+
if(v is MCInt && this is MCInt && holder != null){
459+
when(val holder = holder){
460460
is VectorVar -> {
461461
holder.components.forEachIndexed { index, varr ->
462462
if(varr == this){
@@ -543,6 +543,9 @@ abstract class Var<Self: Var<Self>> : Member, Cloneable, CanSelectMember, Serial
543543
is MCFPPEnumType -> {
544544
`var` = EnumVar(type.enum, container, identifier)
545545
}
546+
is MCFPPVectorType -> {
547+
`var` = VectorVar(type.dimension, container, identifier)
548+
}
546549
//还有模板什么的
547550
else -> {
548551
LogProcessor.error("Unknown type: $type")

src/main/kotlin/top/mcfpp/lang/VectorVar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ open class VectorVar: Var<VectorVar>, Indexable<MCInt>, ScoreHolder {
6060
LogProcessor.error("Cannot assign vector '$identifier' with different dimension '${b.identifier}'")
6161
}
6262
for (i in 0 until dimension){
63-
components[i].assign(b.components[i])
63+
components[i].replacedBy(components[i].assign(b.components[i]))
6464
}
6565
}
6666
is MCInt -> {
6767
for (i in 0 until dimension){
68-
components[i].assign(b)
68+
components[i].replacedBy(components[i].assign(b))
6969
}
7070
}
7171
else -> {

test/test.mcfpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
namespace test;
22

3-
data Test{
4-
int a;
5-
int b;
6-
int c;
7-
int d;
8-
}
9-
10-
func rayCast(Action operation){
11-
if(Context.isSolidBlock()){
12-
operation();
13-
}
14-
Context.setY(~0.1).run { rayCast(operation); };
15-
}
16-
173
func main(){
18-
Test t = {a:1, b:2, c:3, d:4};
19-
t = t[a = 100];
20-
print(t.toText());
4+
vec3 a = [0,1,2];
5+
print(a[0]);
216
}

0 commit comments

Comments
 (0)