wonder.js
Version:
82 lines (71 loc) • 4.25 kB
JavaScript
;
var Caml_option = require("bs-platform/lib/js/caml_option.js");
var ArrayService$Wonderjs = require("../../../atom/ArrayService.js");
var ArrayService$WonderCommonlib = require("wonder-commonlib/lib/js/src/ArrayService.js");
var HierachyTransformService$Wonderjs = require("../../../record/main/transform/HierachyTransformService.js");
var GameObjectTransformService$Wonderjs = require("../../../record/main/transform/GameObjectTransformService.js");
var RecordTransformMainService$Wonderjs = require("../transform/RecordTransformMainService.js");
var GetComponentGameObjectService$Wonderjs = require("../../../record/main/gameObject/GetComponentGameObjectService.js");
var _getChildren = HierachyTransformService$Wonderjs.unsafeGetChildren;
function _addChildren(parentArr, transformRecord, totalChildrenArr) {
var totalChildrenArr$1 = ArrayService$Wonderjs.fastConcat(totalChildrenArr, parentArr);
return ArrayService$WonderCommonlib.reduceOneParam((function (param, parent) {
var transformRecord = param[0];
return _addChildren(HierachyTransformService$Wonderjs.unsafeGetChildren(parent, transformRecord), transformRecord, param[1]);
}), /* tuple */[
transformRecord,
totalChildrenArr$1
], parentArr);
}
function getAllChildrenTransform(gameObject, state) {
var transformRecord = RecordTransformMainService$Wonderjs.getRecord(state);
var parent = GetComponentGameObjectService$Wonderjs.unsafeGetTransformComponent(gameObject, state[/* gameObjectRecord */10]);
return _addChildren(HierachyTransformService$Wonderjs.unsafeGetChildren(parent, transformRecord), RecordTransformMainService$Wonderjs.getRecord(state), /* array */[])[1];
}
function getAllGameObjects(gameObject, state) {
var allTransformChildren = getAllChildrenTransform(gameObject, state);
var transformRecord = RecordTransformMainService$Wonderjs.getRecord(state);
return ArrayService$Wonderjs.fastConcat(/* array */[gameObject], allTransformChildren.map((function (transform) {
return GameObjectTransformService$Wonderjs.unsafeGetGameObject(transform, transformRecord);
})));
}
function getAllChildren(gameObject, state) {
return getAllGameObjects(gameObject, state).slice(1);
}
function _getAllComponentsOfGameObject(gameObject, getComponentFunc, state) {
var gameObjectRecord = state[/* gameObjectRecord */10];
return ArrayService$WonderCommonlib.reduceOneParam((function (param, gameObject) {
var allComponents = param[1];
var gameObjectRecord = param[0];
var match = getComponentFunc(gameObject, gameObjectRecord);
if (match !== undefined) {
return /* tuple */[
gameObjectRecord,
ArrayService$Wonderjs.push(Caml_option.valFromOption(match), allComponents)
];
} else {
return /* tuple */[
gameObjectRecord,
allComponents
];
}
}), /* tuple */[
gameObjectRecord,
/* array */[]
], getAllGameObjects(gameObject, state))[1];
}
function getAllDirectionLightComponentsOfGameObject(gameObject, state) {
return _getAllComponentsOfGameObject(gameObject, GetComponentGameObjectService$Wonderjs.getDirectionLightComponent, state);
}
function getAllPointLightComponentsOfGameObject(gameObject, state) {
return _getAllComponentsOfGameObject(gameObject, GetComponentGameObjectService$Wonderjs.getPointLightComponent, state);
}
exports._getChildren = _getChildren;
exports._addChildren = _addChildren;
exports.getAllChildrenTransform = getAllChildrenTransform;
exports.getAllGameObjects = getAllGameObjects;
exports.getAllChildren = getAllChildren;
exports._getAllComponentsOfGameObject = _getAllComponentsOfGameObject;
exports.getAllDirectionLightComponentsOfGameObject = getAllDirectionLightComponentsOfGameObject;
exports.getAllPointLightComponentsOfGameObject = getAllPointLightComponentsOfGameObject;
/* ArrayService-Wonderjs Not a pure module */