Skip to content
Permalink
Browse files

feat(script): fix script component: support Int type

  • Loading branch information...
yyc-git committed May 31, 2019
1 parent bcf22bc commit 560e7fbed7b171a538b0be95ffb8b9e023fdb706
@@ -62,6 +62,11 @@ module Method = {
|> Wonderjs.ScriptAttributeType.scriptAttributeValueToFloat
=== (value2 |> Wonderjs.ScriptAttributeType.scriptAttributeValueToFloat);

let _isIntValueEqual = (value1, value2) =>
value1
|> Wonderjs.ScriptAttributeType.scriptAttributeValueToInt
=== (value2 |> Wonderjs.ScriptAttributeType.scriptAttributeValueToInt);

let _blurScriptAttributeFieldDefaultValue =
(
(uiState, dispatchFunc),
@@ -93,74 +98,128 @@ module Method = {
attribute,
) =>
Wonderjs.(
ScriptAttributeType.
/* TODO handle Int: add MainEditorIntInputBaseComponent */
(
switch (type_) {
| Float =>
<MainEditorFloatInputBaseComponent
label=fieldName
title=fieldName
defaultValue={
ScriptAttributeEngineService.unsafeGetScriptAttributeFieldDefaultValue(
ScriptAttributeType.(
switch (type_) {
| Float =>
<FloatInput
label=fieldName
title=fieldName
defaultValue={
ScriptAttributeEngineService.unsafeGetScriptAttributeFieldDefaultValue(
fieldName,
attribute,
)
|> Wonderjs.ScriptAttributeType.scriptAttributeValueToFloat
|> string_of_float
}
onChange=(
value =>
_changeScriptAttributeFieldDefaultValue(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue,
)
|> Wonderjs.ScriptAttributeType.scriptAttributeValueToFloat
}
changeComponentValueFunc=(
value =>
_changeScriptAttributeFieldDefaultValue(
)
onBlur=(
value =>
_blurScriptAttributeFieldDefaultValue(
(uiState, dispatchFunc),
_isFloatValueEqual,
(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue,
)
)
blurValueFunc=(
value =>
_blurScriptAttributeFieldDefaultValue(
(uiState, dispatchFunc),
_isFloatValueEqual,
(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue,
),
)
)
dragDropFunc=(
value =>
_blurScriptAttributeFieldDefaultValue(
(uiState, dispatchFunc),
_isFloatValueEqual,
(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue,
),
)
),
)
)
onDragDrop=(
value =>
_blurScriptAttributeFieldDefaultValue(
(uiState, dispatchFunc),
_isFloatValueEqual,
(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue,
),
)
)
/>
| Int =>
<IntInput
key={DomHelper.getRandomKey()}
label=fieldName
title=fieldName
defaultValue={
ScriptAttributeEngineService.unsafeGetScriptAttributeFieldDefaultValue(
fieldName,
attribute,
)
/>
| type_ =>
WonderLog.Log.fatal(
WonderLog.Log.buildFatalMessage(
~description={j|unknown field type: $type_|j},
~reason="",
~solution={j||j},
~params={j||j},
),
|> Wonderjs.ScriptAttributeType.scriptAttributeValueToInt
|> string_of_int
}
onChange=(
value =>
_changeScriptAttributeFieldDefaultValue(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.intToScriptAttributeValue,
)
)
}
)
onBlur=(
value =>
_blurScriptAttributeFieldDefaultValue(
(uiState, dispatchFunc),
_isIntValueEqual,
(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.intToScriptAttributeValue,
),
)
)
onDragDrop=(
value =>
_blurScriptAttributeFieldDefaultValue(
(uiState, dispatchFunc),
_isIntValueEqual,
(
script,
attributeName,
fieldName,
attribute,
value
|> Wonderjs.ScriptAttributeType.intToScriptAttributeValue,
),
)
)
/>
| type_ =>
WonderLog.Log.fatal(
WonderLog.Log.buildFatalMessage(
~description={j|unknown field type: $type_|j},
~reason="",
~solution={j||j},
~params={j||j},
),
)
}
)
);

let _renderScriptAttributeFields =
@@ -114,9 +114,15 @@ module TestUpdateScriptAttributeInAllScriptComponents = {
);

MainEditorInspectorAddComponentTool.addScriptComponent();
/* (
GameObjectTool.getCurrentSceneTreeNodeScript()
) */
};

let getFieldName = nodeId => {
let (fieldName, field) =
getAttributeEntries(nodeId)
|> StateLogicService.getEditorState
|> ArrayService.unsafeGetFirst;

fieldName;
};

let prepareForOneScriptComponent = sandbox => {
@@ -133,12 +139,7 @@ module TestUpdateScriptAttributeInAllScriptComponents = {
(),
);

let (fieldName, field) =
getAttributeEntries(addedNodeId)
|> StateLogicService.getEditorState
|> ArrayService.unsafeGetFirst;

(script, addedNodeId, fieldName);
(script, addedNodeId, getFieldName(addedNodeId));
};

let prepareForTwoScriptComponents = sandbox => {
@@ -164,11 +165,6 @@ module TestUpdateScriptAttributeInAllScriptComponents = {
(),
);

let (fieldName, field) =
getAttributeEntries(addedNodeId)
|> StateLogicService.getEditorState
|> ArrayService.unsafeGetFirst;

((script1, script2), addedNodeId, fieldName);
((script1, script2), addedNodeId, getFieldName(addedNodeId));
};
};
@@ -134,6 +134,16 @@ let changeScriptAttributeFieldDefaultValueFloat =
defaultValue |> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue,
);

let changeScriptAttributeFieldDefaultValueInt =
(script, attributeName, fieldName, attribute, defaultValue) =>
MainEditorScriptAttribute.Method._changeScriptAttributeFieldDefaultValue(
script,
attributeName,
fieldName,
attribute,
defaultValue |> Wonderjs.ScriptAttributeType.intToScriptAttributeValue,
);

let blurScriptAttributeFieldDefaultValueFloat =
(script, attributeName, fieldName, attribute, defaultValue) =>
MainEditorScriptAttribute.Method._blurScriptAttributeFieldDefaultValue(
@@ -19,6 +19,9 @@ let getScriptAttributeFieldType =
let buildFloatValue = value =>
value |> Wonderjs.ScriptAttributeType.floatToScriptAttributeValue;

let buildIntValue = value =>
value |> Wonderjs.ScriptAttributeType.intToScriptAttributeValue;

let getScriptAttributeFieldCount = (script, attributeName, engineState) =>
ScriptToolEngine.getScriptAttributeEntries(
script,

0 comments on commit 560e7fb

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