Skip to content

Reads and generates Project Arrhythmia prefabs procedurally

License

Notifications You must be signed in to change notification settings

PA-Toolkit/pa-prefab

Repository files navigation

Welcome to pa-prefab 👋

Version License: MIT

Reads and generates Project Arrhythmia prefabs procedurally

GitHub repository: https://github.com/PA-Toolkit/pa-prefab

IMPORTANT: This library depends on pa-common!

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

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