Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
timhaywood committed Sep 25, 2020
1 parent 866cb77 commit 7ce377d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ For a legacy version that works in the ExtendScript engine, view the [Extendscri
2. **Create a reference to the library in an expression:**

```javascript
const funcLib = footage('aefunctions.jsx').sourceData.getFunctions(time);
const funcLib = footage('aefunctions.jsx').sourceData.getFunctions();
```

(You can name the library variable whatever you'd like).

`getFunctions` does some initial setup, and then returns an object containing the functions.

> Passing the `time` value to `getFunctions` avoids passing it to each function that accesses the comp time.
3. **Access the functions in your expression:**

```javascript
Expand All @@ -63,7 +59,7 @@ For a legacy version that works in the ExtendScript engine, view the [Extendscri
An example expression that uses the library is:

```javascript
const ae = footage('aefunctions.jsx').sourceData.getFunctions(time);
const ae = footage('aefunctions.jsx').sourceData.getFunctions();
ae.attachKeys(2, 2);
```

Expand All @@ -72,7 +68,7 @@ You can also [destructure](https://developer.mozilla.org/en-US/docs/Web/JavaScri
```javascript
const { attachKeys, countLines } = footage(
'aefunctions.jsx'
).sourceData.getFunctions(time);
).sourceData.getFunctions();
```

[Back To Top ↑]
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aefunctions",
"version": "1.4.0",
"version": "1.5.0",
"description": "Speed up your After Effects expression writing with a library of useful functions",
"main": "dist/aefunctions.jsx",
"scripts": {
Expand Down Expand Up @@ -30,6 +30,6 @@
"typescript": "^3.9.7"
},
"dependencies": {
"expression-globals-typescript": "^2.1.1"
"expression-globals-typescript": "^3.0.0"
}
}
16 changes: 7 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {
PathProperty,
Layer,
Comp,
add,
Vector,
mul,
Points,
Vector2D,
PathValue,
Expand All @@ -14,7 +12,7 @@ const thisProperty = new PathProperty<PathValue>([[0, 0]]);
const thisLayer = new Layer();
const thisComp = new Comp();

function getFunctions(time: number) {
function getFunctions(time: number = thisLayer.time) {
function attachKeys(inKeys: number = 2, outKeys: number = 2) {
if (inKeys >= 1 && outKeys >= 1) {
// There is in and out animation
Expand Down Expand Up @@ -102,9 +100,9 @@ function getFunctions(time: number) {
let velocity = thisProperty.velocityAtTime(
thisProperty.key(curKey).time - thisComp.frameDuration / 10
) as Vector;
return add(
return thisLayer.add(
thisProperty.value as Vector,
mul(
thisLayer.mul(
velocity,
(amp * Math.sin(freq * t * 2 * Math.PI)) / Math.exp(decay * t)
)
Expand Down Expand Up @@ -135,10 +133,10 @@ function getFunctions(time: number) {
columnWidth * (columnNum - 1),
rowHeight * (rowNum - 1),
];
const topRight: Vector = add(topLeft, [columnWidth, 0]);
const topRight: Vector = thisLayer.add(topLeft, [columnWidth, 0]);

const bottomLeft: Vector = add(topLeft, [0, rowHeight]);
const bottomRight: Vector = add(topRight, [0, rowHeight]);
const bottomLeft: Vector = thisLayer.add(topLeft, [0, rowHeight]);
const bottomRight: Vector = thisLayer.add(topRight, [0, rowHeight]);

return [topLeft, topRight, bottomRight, bottomLeft];
}
Expand All @@ -160,7 +158,7 @@ function getFunctions(time: number) {
const x = xGrid * 1.75 - yGrid;
const y = xGrid + yGrid / 1.75;

return add(offset, [x, y]);
return thisLayer.add(offset, [x, y]);
}

function getLayerBoundsPath(
Expand Down

0 comments on commit 7ce377d

Please sign in to comment.