Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addMaterialObject(
name: string,
gameObject: GameObject,
loose: boolean,
rowsByMaterial: Record
) {
const elementBehavior = getBehavior(gameObject, PrimaryElementBehavior);
if (!elementBehavior) {
return;
}
const { Units } = elementBehavior.templateData;
// Use custom provided name, as many objects (food, clothing) have the same primary element.
const row = getMaterialRow(name, rowsByMaterial);
if (loose) {
row.looseCount++;
row.looseGrams += Units;
} else {
row.storedCount++;
row.storedGrams += Units;
}
behaviors: exportBehaviors
};
const hash = objectHash(exportObject, { algorithm: "sha1" });
exportObject.$sha1 = hash;
const content = JSON.stringify(exportObject, null, 2);
const blob = new Blob([content], {
type: "application/javascript;charset=utf-8"
});
// TODO: Should have a config file defining valid behavior exports and file name source.
let fileName = "export.json";
if (gameObjectType === "Minion") {
const identity = getBehavior(gameObject, MinionIdentityBehavior);
if (identity) {
fileName = `${identity.templateData.name}.json`;
}
}
saveAs(blob, fileName);
}
(gameObjectsById, gameObjectId) => {
const gameObject = gameObjectsById[gameObjectId];
if (!gameObject) {
return null;
}
return getBehavior(gameObject, behaviorName);
}
)(gameObjectIdSelector);
const primaryElementBehavior = createSelector(selectedValue, value => {
if (!value) {
return null;
}
return getBehavior(value, PrimaryElementBehavior);
});
}
const saveGameGroup = find(
saveGame.gameObjects,
x => x.name === "SaveGame"
);
if (!saveGameGroup) {
return null;
}
const saveGameObject = saveGameGroup.gameObjects[0];
if (!saveGameObject) {
return null;
}
const spaceBehavior = getBehavior(
saveGameObject,
SpacecraftManagerBehavior
);
if (!spaceBehavior) {
return null;
}
return spaceBehavior.templateData;
}
)
const gameObjects = gameObjectsByIdSelector.local(state);
if (!gameObjects || !gameObjects[gameObjectId]) {
return state;
}
const gameObject = gameObjects[gameObjectId];
const typesById = gameObjectTypesByIdSelector.local(state);
if (!typesById || !typesById[gameObjectId]) {
return state;
}
const gameObjectType = typesById[gameObjectId];
const copyBehaviors: Record = {};
for (const behaviorName of behaviors) {
const behavior = getBehavior(gameObject, behaviorName);
if (!behavior) {
continue;
}
copyBehaviors[behaviorName] = {
templateData: behavior.templateData,
extraData: behavior.extraData
};
}
return {
...state,
copyPasteData: {
gameObjectType,
behaviors: copyBehaviors
}
};
export function getGameObjectId(gameObject: GameObject): number | null {
const idBehavior = getBehavior(gameObject, KPrefabIDBehavior);
if (!idBehavior) {
return null;
}
return idBehavior.templateData.InstanceID;
}