Skip to content

Commit a66f6ef

Browse files
committed
feat(api): change scriptAPI to uncurry
1 parent af83229 commit a66f6ef

File tree

3 files changed

+58
-28
lines changed

3 files changed

+58
-28
lines changed
Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
let create = () => {
2-
"unsafeGetScriptAttribute": OperateScriptDataMainService.unsafeGetScriptAttribute,
3-
"unsafeGetScriptAttributeFieldValue": OperateScriptAttributeDataMainService.unsafeGetScriptAttributeFieldValue,
4-
"setScriptAttributeFieldValue": OperateScriptDataMainService.setScriptAttributeFieldValue,
5-
"unsafeGetScriptGameObject": ScriptAPI.unsafeGetScriptGameObject,
6-
"getTransformLocalPosition": TransformAPI.getTransformLocalPosition,
7-
"setTransformLocalPosition": TransformAPI.setTransformLocalPosition,
8-
"unsafeGetGameObjectTransformComponent": GameObjectAPI.unsafeGetGameObjectTransformComponent,
9-
"disposeGameObject": GameObjectAPI.disposeGameObject,
2+
"unsafeGetScriptAttribute":
3+
(. script, scriptAttributeName, state) =>
4+
OperateScriptDataMainService.unsafeGetScriptAttribute(
5+
script,
6+
scriptAttributeName,
7+
state,
8+
),
9+
"unsafeGetScriptAttributeFieldValue":
10+
(. fieldName, attribute) =>
11+
OperateScriptAttributeDataMainService.unsafeGetScriptAttributeFieldValue(
12+
fieldName,
13+
attribute,
14+
),
15+
"setScriptAttributeFieldValue":
16+
(. script, (scriptAttributeName, fieldName, value), state) =>
17+
OperateScriptDataMainService.setScriptAttributeFieldValue(
18+
script,
19+
(scriptAttributeName, fieldName, value),
20+
state,
21+
),
22+
"unsafeGetScriptGameObject":
23+
(. script, state) => ScriptAPI.unsafeGetScriptGameObject(script, state),
24+
"getTransformLocalPosition":
25+
(. transform, state) =>
26+
TransformAPI.getTransformLocalPosition(transform, state),
27+
"setTransformLocalPosition":
28+
(. transform, localPosition, state) =>
29+
TransformAPI.setTransformLocalPosition(transform, localPosition, state),
30+
"unsafeGetGameObjectTransformComponent":
31+
(. gameObject, state) =>
32+
GameObjectAPI.unsafeGetGameObjectTransformComponent(gameObject, state),
33+
"disposeGameObject":
34+
(. gameObject, state) =>
35+
GameObjectAPI.disposeGameObject(gameObject, state),
1036
};

src/service/state/main/data/StateDataMainType.re

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,27 +191,28 @@ and arcballCameraControllerRecord = {
191191
and scriptAPIJsObj = {
192192
.
193193
"unsafeGetScriptAttribute":
194-
(int, string, state) => ScriptAttributeType.scriptAttribute,
194+
(. int, string, state) => ScriptAttributeType.scriptAttribute,
195195
"unsafeGetScriptAttributeFieldValue":
196-
(string, ScriptAttributeType.scriptAttribute) =>
196+
(. string, ScriptAttributeType.scriptAttribute) =>
197197
ScriptAttributeType.scriptAttributeValue,
198-
"unsafeGetScriptGameObject": (int, state) => int,
198+
"unsafeGetScriptGameObject": (. int, state) => int,
199199
"setScriptAttributeFieldValue":
200200
(
201+
.
201202
int,
202203
(string, string, ScriptAttributeType.scriptAttributeValue),
203204
state
204205
) =>
205206
state,
206207
"getTransformLocalPosition":
207-
(transform, state) =>
208+
(. transform, state) =>
208209
(
209210
Js.Typed_array.Float32Array.elt,
210211
Js.Typed_array.Float32Array.elt,
211212
Js.Typed_array.Float32Array.elt,
212213
),
213214
"setTransformLocalPosition":
214-
(
215+
(.
215216
transform,
216217
(
217218
Js.Typed_array.Float32Array.elt,
@@ -222,8 +223,8 @@ and scriptAPIJsObj = {
222223
) =>
223224
state,
224225
"unsafeGetGameObjectTransformComponent":
225-
(GameObjectPrimitiveType.gameObject, state) => int,
226-
"disposeGameObject": (GameObjectPrimitiveType.gameObject, state) => state,
226+
(. GameObjectPrimitiveType.gameObject, state) => int,
227+
"disposeGameObject": (. GameObjectPrimitiveType.gameObject, state) => state,
227228
}
228229
and apiRecord = {
229230
scriptAPIJsObj,

test/tool/service/script/ScriptTool.re

100644100755
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module API = {
135135
let unsafeGetScriptAttributeFieldValue =
136136
api##unsafeGetScriptAttributeFieldValue;
137137

138-
unsafeGetScriptAttributeFieldValue(fieldName, scriptAttribute)
138+
unsafeGetScriptAttributeFieldValue(. fieldName, scriptAttribute)
139139
|> ScriptAttributeType.scriptAttributeValueToInt;
140140
};
141141

@@ -144,6 +144,7 @@ module API = {
144144
let setScriptAttributeFieldValue = api##setScriptAttributeFieldValue;
145145

146146
setScriptAttributeFieldValue(
147+
.
147148
script,
148149
(
149150
scriptAttributeName,
@@ -159,7 +160,7 @@ module API = {
159160
let unsafeGetScriptAttributeFieldValue =
160161
api##unsafeGetScriptAttributeFieldValue;
161162

162-
unsafeGetScriptAttributeFieldValue(fieldName, scriptAttribute)
163+
unsafeGetScriptAttributeFieldValue(. fieldName, scriptAttribute)
163164
|> ScriptAttributeType.scriptAttributeValueToFloat;
164165
};
165166

@@ -168,6 +169,7 @@ module API = {
168169
let setScriptAttributeFieldValue = api##setScriptAttributeFieldValue;
169170

170171
setScriptAttributeFieldValue(
172+
.
171173
script,
172174
(
173175
scriptAttributeName,
@@ -249,14 +251,15 @@ module TestCaseWithOneEventFuncAndOneAttribute = {
249251

250252
let transform =
251253
unsafeGetGameObjectTransformComponent(
252-
unsafeGetScriptGameObject(script, state),
254+
.
255+
unsafeGetScriptGameObject(. script, state),
253256
state,
254257
);
255258

256-
let (x, y, z) = getTransformLocalPosition(transform, state);
259+
let (x, y, z) = getTransformLocalPosition(. transform, state);
257260

258261
let state =
259-
setTransformLocalPosition(transform, (x +. 10., y, z), state);
262+
setTransformLocalPosition(. transform, (x +. 10., y, z), state);
260263

261264
state;
262265
};
@@ -268,7 +271,7 @@ module TestCaseWithOneEventFuncAndOneAttribute = {
268271
let unsafeGetScriptAttribute = api##unsafeGetScriptAttribute;
269272

270273
let scriptAttribute =
271-
unsafeGetScriptAttribute(script, scriptAttributeName, state);
274+
unsafeGetScriptAttribute(. script, scriptAttributeName, state);
272275

273276
let state =
274277
API.setScriptAttributeIntFieldValue(
@@ -291,7 +294,7 @@ module TestCaseWithOneEventFuncAndOneAttribute = {
291294
let unsafeGetScriptAttribute = api##unsafeGetScriptAttribute;
292295

293296
let scriptAttribute =
294-
unsafeGetScriptAttribute(script, scriptAttributeName, state);
297+
unsafeGetScriptAttribute(. script, scriptAttributeName, state);
295298

296299
let state =
297300
API.setScriptAttributeFloatFieldValue(
@@ -427,9 +430,9 @@ module TestCaseWithOneEventFuncAndTwoAttributes = {
427430
let unsafeGetScriptAttribute = api##unsafeGetScriptAttribute;
428431

429432
let scriptAttribute1 =
430-
unsafeGetScriptAttribute(script, scriptAttribute1Name, state);
433+
unsafeGetScriptAttribute(. script, scriptAttribute1Name, state);
431434
let scriptAttribute2 =
432-
unsafeGetScriptAttribute(script, scriptAttribute2Name, state);
435+
unsafeGetScriptAttribute(. script, scriptAttribute2Name, state);
433436

434437
let state =
435438
API.setScriptAttributeFloatFieldValue(
@@ -581,9 +584,9 @@ module TestCaseWithTwoEventFuncsAndTwoAttributes = {
581584
let unsafeGetScriptAttribute = api##unsafeGetScriptAttribute;
582585

583586
let scriptAttribute1 =
584-
unsafeGetScriptAttribute(script, scriptAttribute1Name, state);
587+
unsafeGetScriptAttribute(. script, scriptAttribute1Name, state);
585588
let scriptAttribute2 =
586-
unsafeGetScriptAttribute(script, scriptAttribute2Name, state);
589+
unsafeGetScriptAttribute(. script, scriptAttribute2Name, state);
587590

588591
let state =
589592
API.setScriptAttributeIntFieldValue(
@@ -614,9 +617,9 @@ module TestCaseWithTwoEventFuncsAndTwoAttributes = {
614617
let unsafeGetScriptAttribute = api##unsafeGetScriptAttribute;
615618

616619
let scriptAttribute1 =
617-
unsafeGetScriptAttribute(script, scriptAttribute1Name, state);
620+
unsafeGetScriptAttribute(. script, scriptAttribute1Name, state);
618621
let scriptAttribute2 =
619-
unsafeGetScriptAttribute(script, scriptAttribute2Name, state);
622+
unsafeGetScriptAttribute(. script, scriptAttribute2Name, state);
620623

621624
let state =
622625
API.setScriptAttributeFloatFieldValue(

0 commit comments

Comments
 (0)