pa-prefab
v2.0.0
Published
Reads and generates Project Arrhythmia prefabs procedurally
Downloads
4
Readme
Reads and generates Project Arrhythmia prefabs procedurally
GitHub repository: https://github.com/PA-Toolkit/pa-prefab
Install
npm install pa-prefab
Build
npm run build
Usage
Importing
Node.js
const { Prefab, PrefabType } = require("pa-prefab");
or
import { Prefab, PrefabType } from "pa-prefab";
Browser
<head>
<script type="text/javascript" src="path/to/pa-prefab.js"/>
</head>
<script>
const Prefab = PAPrefab.Prefab;
const PrefabType = PAPrefab.PrefabType;
</script>
Creating a prefab
It is recommended to use the CreatePrefab(string, PrefabType)
function to create a new prefab.
const { Prefab, PrefabType } = require("pa-prefab");
let myPrefab = new Prefab("Hello Prefab Toolkit!", PrefabType.Misc1);
Creating an object
To create an object, make a new object with new PAObject(name, Prefab)
and add it to the prefab with Prefab.addObject(PAObject)
.
const { Prefab, PrefabType } = require("pa-prefab");
const { PAObject } = require("pa-common");
let myPrefab = new Prefab("Hello Prefab Toolkit!", PrefabType.Misc1);
let myObject = new PAObject("Hello Object!", myPrefab);
myPrefab.addObject(myObject);
Modifying the object
Setting the object's name
myObject.name = "Hello world!";
Toggling position/scale/rotation parenting
myObject.positionParenting = true;
myObject.scaleParenting = false;
myObject.rotationParenting = true;
Similarly, for parent offset
myObject.positionParentOffset = 0.0;
myObject.scaleParentOffset = 1.0;
myObject.rotationParentOffset = 2.0;
Changing render depth
myObject.renderDepth = 5; // This should be an integer!
Changing object type
const { ObjectType } = require("pa-common");
myObject.objectType = ObjectType.Helper;
Changing object shape
const { Shape } = require("pa-common");
myObject.shape = Shape.Circle;
Changing object sub-shape
const { CircleOption } = require("pa-common");
myObject.shapeOption = CircleOption.HalfHollow;
Changing object text
myObject.text = "The quick brown fox jumps over the lazy dog."; // Note: This will be ignored unless your object shape is Text.
Changing object auto kill type
const { AutoKillType } = require("pa-common");
myObject.autoKillType = AutoKillType.Fixed;
Changing object auto kill offset
myObject.autoKillOffset = 5.0;
Changing object origin
myObject.originX = 0.5;
myObject.originY = 0.5;
Changing editor locked/collapsed state and bin/layer
myObject.editorLocked = false;
myObject.editorCollapse = true;
myObject.editorBin = 1;
myObject.editorLayer = 0;
Animating the object
There are four lists of different keyframe types inside the object. Each list is empty initially. You can add keyframes to those list to animate them. Note that there should be at least one keyframe per list.
myObject.pushPosition(0.0, 0.0, 0.0);
myObject.pushScale(0.0, 1.0, 1.0);
myObject.pushRotation(0.0, 0.0);
myObject.pushColor(0.0, 0);
Building the prefab
You can convert the prefab to a JSON string to write it to a file.
const { fs } = require("fs");
fs.writeFileSync("my_new_prefab.lsp", prefab.toString());
Reading an existing prefab
You can read an existing prefab from a string.
const { fs } = require("fs");
const { Prefab, PrefabType } = require("pa-prefab");
let json = JSON.parse(jsonStr);
let prefab = new Prefab("", PrefabType.Bombs); // will be overriden by fromJson!
prefab.fromJson(json);
Run tests
npm run test
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator