Skip to content

Commit 84299db

Browse files
committed
修复了作为函数参数的变量是Concrete的问题
1 parent 3e7851b commit 84299db

27 files changed

+296
-119
lines changed

.mclib

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
{
1919
"id":"test",
2020
"functions":[
21+
{
22+
"id":"test",
23+
"normalParams":[
24+
{
25+
"id":"t",
26+
"type":"template(test:Test)",
27+
"isStatic":false
28+
}
29+
],
30+
"returnType":"template(test:Test)",
31+
"isAbstract":false,
32+
"tags":[
33+
34+
]
35+
},
2136
{
2237
"id":"main",
2338
"normalParams":[
@@ -34,7 +49,35 @@
3449

3550
],
3651
"template":[
37-
52+
{
53+
"id":"Test",
54+
"parents":[
55+
"mcfpp.lang:DataObject"
56+
],
57+
"field":{
58+
"vars":[
59+
{
60+
"id":"a",
61+
"type":"int"
62+
},
63+
{
64+
"id":"b",
65+
"type":"int"
66+
},
67+
{
68+
"id":"c",
69+
"type":"int"
70+
},
71+
{
72+
"id":"d",
73+
"type":"int"
74+
}
75+
],
76+
"functions":[
77+
78+
]
79+
}
80+
}
3881
],
3982
"enum":[
4083

src/main/kotlin/top/mcfpp/io/LibReader.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ object CompoundDataFieldReader: ILibJsonReader<CompoundDataField> {
237237
val field = CompoundDataField(ArrayList(), ClassReader.currClass?:TemplateReader.currTemplate)
238238
jsonObject.getJSONArray("vars").forEach {
239239
run {
240-
val type = UnresolvedType(jsonObject.getString("type"))
241-
val identifier = jsonObject.getString("id")
240+
val type = UnresolvedType((it as JSONObject) .getString("type"))
241+
val identifier = it.getString("id")
242242
val v = UnresolvedVar(identifier, type, field)
243243
field.putVar(v.identifier, v, false)
244244
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import top.mcfpp.lang.value.MCFPPValue
55
import top.mcfpp.model.Member
66
import top.mcfpp.model.function.Function
77
import java.util.UUID
8-
import javax.xml.crypto.Data
98

109
class Accessor(override var value: Var<*>, identifier: String = UUID.randomUUID().toString()) : Var<Accessor>(identifier), MCFPPValue<Var<*>> {
1110

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ open class DataTemplateObject : Var<DataTemplateObject> {
103103
//是成员
104104
//TODO 选择两个实体的代价和复制整个模板数据的代价谁更大?
105105
val b = if(obj.parentClass() != null) obj.getTempVar() else obj
106-
val c = Commands.selectRun(parent!!, Command("data modify $nbtPath set from ${b.nbtPath}"))
106+
val c = Commands.selectRun(parent!!, Commands.dataSetFrom(nbtPath, b.nbtPath))
107107
Function.addCommands(c)
108-
}else{
109-
if(obj.parentClass() != null){
108+
}else {
109+
if (obj.parentClass() != null) {
110110
//obj是成员
111-
val c = Commands.selectRun(obj.parent!!, Command("data modify ${obj.nbtPath} set from $nbtPath"))
111+
val c = Commands.selectRun(obj.parent!!, Commands.dataSetFrom(obj.nbtPath, nbtPath))
112112
Function.addCommands(c)
113-
}else{
114-
Function.addCommand("data modify $nbtPath set from ${obj.nbtPath}")
113+
} else {
114+
Function.addCommand(Commands.dataSetFrom(nbtPath, obj.nbtPath))
115115
}
116116
}
117117
}
@@ -235,16 +235,23 @@ open class DataTemplateObject : Var<DataTemplateObject> {
235235
}
236236
return DataTemplateObjectConcrete(this, compoundTag)
237237
}
238+
239+
fun toFunctionParam(){
240+
Function.extraFunction.runInFunction {
241+
for (field in this.instanceField.allVars){
242+
if(field is MCFPPValue<*>){
243+
field.toDynamic(true)
244+
}
245+
}
246+
}
247+
}
248+
238249
}
239250

240251
class DataTemplateObjectConcrete: DataTemplateObject, MCFPPValue<CompoundTag>{
241252

242253
override var value: CompoundTag
243254

244-
override fun defaultValue(): CompoundTag {
245-
return templateType.getDefaultValue()
246-
}
247-
248255
/**
249256
* 创建一个固定的DataTemplate
250257
*
@@ -292,13 +299,17 @@ class DataTemplateObjectConcrete: DataTemplateObject, MCFPPValue<CompoundTag>{
292299
if(cmd.size == 2){
293300
Function.addCommand(cmd[0])
294301
}
295-
Function.addCommand(cmd.last().build("data modify $nbtPath set ${SNBTUtil.toSNBT(value)}"))
302+
Function.addCommand(cmd.last().build(Commands.dataSetValue(nbtPath, value)))
296303
}else {
297-
Function.addCommand("data modify $nbtPath set ${SNBTUtil.toSNBT(value)}")
304+
Function.addCommand(Commands.dataSetValue(nbtPath, value))
298305
}
299306
val re = DataTemplateObject(this)
300307
if(replace){
301-
Function.currFunction.field.putVar(identifier, re, true)
308+
if(parentTemplate() != null) {
309+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
310+
}else{
311+
Function.currFunction.field.putVar(identifier, re, true)
312+
}
302313
}
303314
return re
304315
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ class EntityVarConcrete: EntityVar, MCFPPValue<IntArrayTag>{
8585

8686
override var value: IntArrayTag
8787

88-
override fun defaultValue(): IntArrayTag {
89-
return IntArrayTag(intArrayOf(0,0,0,0))
90-
}
91-
9288
constructor(curr: FieldContainer, value: IntArrayTag, identifier: String = UUID.randomUUID().toString()) : super(curr, identifier){
9389
this.value = value
9490
}
@@ -123,7 +119,11 @@ class EntityVarConcrete: EntityVar, MCFPPValue<IntArrayTag>{
123119
}
124120
val re = EntityVar(this)
125121
if(replace){
126-
Function.currFunction.field.putVar(identifier, re, true)
122+
if(parentTemplate() != null){
123+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
124+
}else{
125+
Function.currFunction.field.putVar(identifier, re, true)
126+
}
127127
}
128128
return re
129129
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ class EnumVarConcrete : EnumVar, MCFPPValue<Int>{
124124

125125
override var value: Int
126126

127-
override fun defaultValue(): Int {
128-
return 0
129-
}
130-
131127
/**
132128
* 创建一个固定的int
133129
*
@@ -189,7 +185,11 @@ class EnumVarConcrete : EnumVar, MCFPPValue<Int>{
189185
}
190186
val re = EnumVar(this)
191187
if(replace){
192-
Function.currFunction.field.putVar(identifier, re, true)
188+
if(parentTemplate() != null){
189+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
190+
}else{
191+
Function.currFunction.field.putVar(identifier, re, true)
192+
}
193193
}
194194
return re
195195
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package top.mcfpp.lang
22

33
import net.querz.nbt.tag.CompoundTag
4-
import net.querz.nbt.tag.ListTag
54
import net.querz.nbt.tag.StringTag
65
import net.querz.nbt.tag.Tag
76
import top.mcfpp.exception.OperationNotImplementException
@@ -36,10 +35,6 @@ class JavaVar : Var<JavaVar>, MCFPPValue<Any?>{
3635

3736
override var type: MCFPPType = MCFPPBaseType.JavaVar
3837

39-
override fun defaultValue(): Any? {
40-
return null
41-
}
42-
4338
/**
4439
* 创建一个固定的JavaVar
4540
*

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import top.mcfpp.lang.type.MCFPPBaseType
77
import top.mcfpp.lang.type.MCFPPType
88
import top.mcfpp.lang.value.MCFPPValue
99
import top.mcfpp.lib.ChatComponent
10-
import top.mcfpp.lib.PlainChatComponent
1110
import top.mcfpp.model.CompoundData
1211
import top.mcfpp.model.FieldContainer
1312
import top.mcfpp.model.Member
@@ -117,10 +116,6 @@ class JsonTextConcrete : MCFPPValue<ChatComponent>, JsonText {
117116

118117
override var value: ChatComponent
119118

120-
override fun defaultValue(): ChatComponent {
121-
return PlainChatComponent("")
122-
}
123-
124119
/**
125120
* 创建一个固定的int
126121
*
@@ -170,7 +165,11 @@ class JsonTextConcrete : MCFPPValue<ChatComponent>, JsonText {
170165
}
171166
val re = NBTBasedData(this)
172167
if(replace){
173-
Function.currFunction.field.putVar(identifier, re, true)
168+
if(parentTemplate() != null){
169+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
170+
}else{
171+
Function.currFunction.field.putVar(identifier, re, true)
172+
}
174173
}
175174
return re
176175
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ class MCAnyConcrete : MCAny, MCFPPValue<Var<*>>{
200200

201201
override var value: Var<*>
202202

203-
override fun defaultValue(): Var<*> {
204-
return MCIntConcrete(0, "any_default")
205-
}
206-
207203
/**
208204
* 创建一个固定的int
209205
*
@@ -276,7 +272,11 @@ class MCAnyConcrete : MCAny, MCFPPValue<Var<*>>{
276272
override fun toDynamic(replace: Boolean): Var<*> {
277273
val re = MCAny(this)
278274
if(replace){
279-
Function.currFunction.field.putVar(identifier, re, true)
275+
if(parentTemplate() != null){
276+
parentTemplate()!!.field.putVar(identifier, re, true)
277+
}else{
278+
Function.currFunction.field.putVar(identifier, re, true)
279+
}
280280
}
281281
return re
282282
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import top.mcfpp.model.function.Function
1111
import top.mcfpp.util.LogProcessor
1212
import top.mcfpp.util.TextTranslator
1313
import top.mcfpp.util.TextTranslator.translate
14+
import javax.xml.crypto.Data
1415

1516
/**
1617
* 布尔型变量是mcfpp的基本类型之一,它表示一个只有0,1两种取值可能性的值。
@@ -240,10 +241,6 @@ class MCBoolConcrete : MCBool, MCFPPValue<Boolean>{
240241

241242
override var value: Boolean
242243

243-
override fun defaultValue(): Boolean {
244-
return false
245-
}
246-
247244
/**
248245
* 创建一个固定的bool
249246
*
@@ -333,7 +330,11 @@ class MCBoolConcrete : MCBool, MCFPPValue<Boolean>{
333330
override fun toDynamic(replace: Boolean): Var<*> {
334331
val re = MCBool(this)
335332
if(replace){
336-
Function.currFunction.field.putVar(identifier, re, true)
333+
if(parentTemplate() != null){
334+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
335+
}else{
336+
Function.currFunction.field.putVar(identifier, re, true)
337+
}
337338
}
338339
return re
339340
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ open class MCFPPTypeVar : Var<MCFPPTypeVar>, MCFPPValue<MCFPPType> {
1414

1515
override var type: MCFPPType = MCFPPBaseType.Type
1616

17-
override fun defaultValue(): MCFPPType {
18-
return MCFPPBaseType.Any
19-
}
20-
2117
constructor(type: MCFPPType = MCFPPBaseType.Any, identifier: String = UUID.randomUUID().toString()) : super(identifier) {
2218
this.value = type
2319
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@ class MCFloatConcrete : MCFloat, MCFPPValue<Float>{
451451
setJavaValue(value)
452452
}
453453

454-
override fun defaultValue(): Float {
455-
return 0.0f
456-
}
457-
458454
/**
459455
* 创建一个固定的float
460456
*
@@ -494,7 +490,11 @@ class MCFloatConcrete : MCFloat, MCFPPValue<Float>{
494490
(int1 as MCIntConcrete).toDynamic(false)
495491
(exp as MCIntConcrete).toDynamic(false)
496492
if(replace){
497-
Function.currFunction.field.putVar(identifier, qwq, true)
493+
if(parentTemplate() != null){
494+
(parent as DataTemplateObject).instanceField.putVar(identifier, qwq, true)
495+
}else{
496+
Function.currFunction.field.putVar(identifier, qwq, true)
497+
}
498498
}
499499
return qwq
500500
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,6 @@ class MCIntConcrete : MCInt, MCFPPValue<Int>{
424424

425425
override var value: Int
426426

427-
override fun defaultValue(): Int {
428-
return 0
429-
}
430-
431427
/**
432428
* 创建一个固定的int
433429
*
@@ -488,7 +484,11 @@ class MCIntConcrete : MCInt, MCFPPValue<Int>{
488484
}
489485
val re = MCInt(this)
490486
if(replace){
491-
Function.currFunction.field.putVar(identifier, re, true)
487+
if(parentTemplate() != null){
488+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
489+
}else{
490+
Function.currFunction.field.putVar(identifier, re, true)
491+
}
492492
}
493493
return re
494494
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ class MCStringConcrete: MCString, MCFPPValue<StringTag>{
100100

101101
override var value: StringTag
102102

103-
override fun defaultValue(): StringTag {
104-
return StringTag("")
105-
}
106-
107103
/**
108104
* 创建一个固定的string
109105
*

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,6 @@ class NBTBasedDataConcrete<T: Tag<*>> : NBTBasedData<T>, MCFPPValue<T> {
400400

401401
override var value : T
402402

403-
override fun defaultValue(): T {
404-
return value
405-
}
406-
407403
/**
408404
* 创建一个固定的int
409405
*
@@ -491,7 +487,11 @@ class NBTBasedDataConcrete<T: Tag<*>> : NBTBasedData<T>, MCFPPValue<T> {
491487
}
492488
val re = NBTBasedData(this)
493489
if(replace){
494-
Function.currFunction.field.putVar(identifier, re, true)
490+
if(parentTemplate() != null){
491+
(parent as DataTemplateObject).instanceField.putVar(identifier, re, true)
492+
}else {
493+
Function.currFunction.field.putVar(identifier, re, true)
494+
}
495495
}
496496
return re
497497
}

0 commit comments

Comments
 (0)