Skip to content
Permalink
Browse files

feat(asset): convert->script: support script component not has event …

…function data/attribute
  • Loading branch information...
yyc-git committed Apr 10, 2019
1 parent 164469f commit 6def26847a56f2d4727e07646a4e1785d3b153ee
@@ -22,26 +22,7 @@ let build = (scriptDataMap, {scriptRecord} as state) => {
script,
state,
),
/* OperateScriptDataMainService.unsafeGetScriptEventFunctionDataEntries(
script,
state,
)
|> Js.Array.map(((name, eventFunctionData)) =>
(
name,
SerializeService.serializeFunction(
eventFunctionData,
),
)
), */
attributeMapStr:
/* OperateScriptDataMainService.unsafeGetScriptAttributeEntries(
script,
state,
)
|> Js.Array.map(((name, attribute)) =>
(name, SerializeService.serializeFunction(attribute))
), */
ConvertScriptDataUtils.unsafeGetAttributeMapStr(
script,
state,
@@ -33,12 +33,19 @@ let _convertEventFunctionDataMapToStr = eventDataMap =>
|> Obj.magic
|> Js.Json.stringify;

let _buildEmptyMapStr = () => "{}";

let unsafeGetEventFunctionDataMapStr = (script, {scriptRecord} as state) => {
let {scriptEventFunctionDataMap} as scriptRecord = scriptRecord;

scriptEventFunctionDataMap
|> ImmutableSparseMapService.unsafeGetAndCheck(script)
|> _convertEventFunctionDataMapToStr;
switch (
scriptEventFunctionDataMap
|> WonderCommonlib.ImmutableSparseMapService.get(script)
) {
| None => _buildEmptyMapStr()
| Some(eventFunctionDataMap) =>
eventFunctionDataMap |> _convertEventFunctionDataMapToStr
};
};

let _convertAttributeMapToStr = attributeMap =>
@@ -47,9 +54,17 @@ let _convertAttributeMapToStr = attributeMap =>
let unsafeGetAttributeMapStr = (script, {scriptRecord} as state) => {
let {scriptAttributeMap} as scriptRecord = scriptRecord;

scriptAttributeMap
|> ImmutableSparseMapService.unsafeGetAndCheck(script)
|> _convertAttributeMapToStr;
/* scriptAttributeMap
|> ImmutableSparseMapService.unsafeGetAndCheck(script)
|> _convertAttributeMapToStr; */

switch (
scriptAttributeMap
|> WonderCommonlib.ImmutableSparseMapService.get(script)
) {
| None => _buildEmptyMapStr()
| Some(attributeMap) => attributeMap |> _convertAttributeMapToStr
};
};

let convertEventFunctionDataMapJsonToRecord =
@@ -2254,8 +2254,9 @@ let _ =
AssetScriptTool.buildEventFunctionDataMap(
~initFunc=Some(AssetScriptTool.buildEventFunc()),
(),
),
~attributeMap=AssetScriptTool.buildAttributeMap(),
)
->Some,
~attributeMap=AssetScriptTool.buildAttributeMap()->Some,
(),
),
~state,
@@ -2292,8 +2293,9 @@ let _ =
AssetScriptTool.buildEventFunctionDataMap(
~updateFunc=Some(AssetScriptTool.buildEventFunc2()),
(),
),
~attributeMap=AssetScriptTool.buildAttributeMap(),
)
->Some,
~attributeMap=AssetScriptTool.buildAttributeMap()->Some,
(),
),
~state,
@@ -828,42 +828,78 @@ let _ =
(),
)
);
test("test has data", () => {
let eventFunctionDataMap =
AssetScriptTool.buildEventFunctionDataMap();
let attributeMap = AssetScriptTool.buildAttributeMap();
let eventFunctionDataMapStr =
ConvertScriptDataUtils._convertEventFunctionDataMapToStr(
eventFunctionDataMap,

describe("test has data", () => {
test("test only has event function data", () => {
let eventFunctionDataMap =
AssetScriptTool.buildEventFunctionDataMap();
let eventFunctionDataMapStr =
ConvertScriptDataUtils._convertEventFunctionDataMapToStr(
eventFunctionDataMap,
);

ConvertGLBTool.testGLTFResultByGLTF(
~sandbox=sandbox^,
~embeddedGLTFJsonStr=
ConvertGLBTool.buildGLTFJsonOfScript(
~eventFunctionDataMap=Some(eventFunctionDataMap),
~attributeMap=None,
(),
),
~state,
~testFunc=
({scripts}) =>
scripts
|> expect
== [|
{
eventFunctionDataMap:
eventFunctionDataMapStr
|> Js.Json.parseExn
|> Obj.magic,
attributeMap: Js.Dict.empty(),
},
|],
(),
);
let attributeMapStr =
ConvertScriptDataUtils._convertAttributeMapToStr(attributeMap);
});
test("test has event function data and attribute data", () => {
let eventFunctionDataMap =
AssetScriptTool.buildEventFunctionDataMap();
let attributeMap = AssetScriptTool.buildAttributeMap();
let eventFunctionDataMapStr =
ConvertScriptDataUtils._convertEventFunctionDataMapToStr(
eventFunctionDataMap,
);
let attributeMapStr =
ConvertScriptDataUtils._convertAttributeMapToStr(attributeMap);

ConvertGLBTool.testGLTFResultByGLTF(
~sandbox=sandbox^,
~embeddedGLTFJsonStr=
ConvertGLBTool.buildGLTFJsonOfScript(
~eventFunctionDataMap,
~attributeMap,
(),
),
~state,
~testFunc=
({scripts}) =>
scripts
|> expect
== [|
{
eventFunctionDataMap:
eventFunctionDataMapStr
|> Js.Json.parseExn
|> Obj.magic,
attributeMap:
attributeMapStr |> Js.Json.parseExn |> Obj.magic,
},
|],
(),
);
ConvertGLBTool.testGLTFResultByGLTF(
~sandbox=sandbox^,
~embeddedGLTFJsonStr=
ConvertGLBTool.buildGLTFJsonOfScript(
~eventFunctionDataMap=Some(eventFunctionDataMap),
~attributeMap=Some(attributeMap),
(),
),
~state,
~testFunc=
({scripts}) =>
scripts
|> expect
== [|
{
eventFunctionDataMap:
eventFunctionDataMapStr
|> Js.Json.parseExn
|> Obj.magic,
attributeMap:
attributeMapStr |> Js.Json.parseExn |> Obj.magic,
},
|],
(),
);
});
});
})
);
@@ -1049,21 +1049,24 @@ let buildGLTFJsonOfArcballCameraController = (~isBindEvent=true, ()) => {

let buildGLTFJsonOfScript =
(
~eventFunctionDataMap=AssetScriptTool.buildEventFunctionDataMap(),
~attributeMap=AssetScriptTool.buildAttributeMap(),
~eventFunctionDataMap=Some(AssetScriptTool.buildEventFunctionDataMap()),
~attributeMap=Some(AssetScriptTool.buildAttributeMap()),
(),
) => {
let eventFunctionDataMapStr =
ConvertScriptDataUtils._convertEventFunctionDataMapToStr(
eventFunctionDataMap,
);

/* WonderLog.Log.print(eventFunctionDataMap) |> ignore; */
switch (eventFunctionDataMap) {
| None => ConvertScriptDataUtils._buildEmptyMapStr()
| Some(eventFunctionDataMap) =>
eventFunctionDataMap
|> ConvertScriptDataUtils._convertEventFunctionDataMapToStr
};

let attributeMapStr =
ConvertScriptDataUtils._convertAttributeMapToStr(attributeMap);

/* WonderLog.Log.print(attributeMap) |> ignore; */
switch (attributeMap) {
| None => ConvertScriptDataUtils._buildEmptyMapStr()
| Some(attributeMap) =>
attributeMap |> ConvertScriptDataUtils._convertAttributeMapToStr
};

buildGLTFJson(
~nodes=

0 comments on commit 6def268

Please sign in to comment.
You can’t perform that action at this time.