Skip to content

Commit

Permalink
feat(rapier): add rapier
Browse files Browse the repository at this point in the history
wip rapier
  • Loading branch information
nartc committed Oct 4, 2023
1 parent be14df8 commit ff76de7
Show file tree
Hide file tree
Showing 37 changed files with 1,563 additions and 15 deletions.
6 changes: 4 additions & 2 deletions libs/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@
"packageGroup": [
"angular-three-soba",
"angular-three-postprocessing",
"angular-three-cannon"
"angular-three-cannon",
"angular-three-rapier"
]
},
"ng-update": {
"migrations": "./plugin/migrations.json",
"packageGroup": [
"angular-three-soba",
"angular-three-postprocessing",
"angular-three-cannon"
"angular-three-cannon",
"angular-three-rapier"
]
},
"web-types": "./web-types.json"
Expand Down
1 change: 1 addition & 0 deletions libs/core/src/lib/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export class NgtPortal implements OnInit {
requestAnimationFrame(() => {
this.portalStore.set((injectState) => this.inject(this.parentStore.get(), injectState));
});

this.portalContentView = this.portalContentAnchor.createEmbeddedView(this.portalContentTemplate);
safeDetectChanges(this.portalContentView);
this.portalContentRendered = true;
Expand Down
6 changes: 5 additions & 1 deletion libs/core/src/lib/utils/signal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export function signalStore<State extends object>(

const computedCache = new Map();

if (!options) {
options = { equal: Object.is };
}

if (typeof initialState === 'function') {
source = signal({} as State, options);
state = source.asReadonly();
Expand Down Expand Up @@ -180,5 +184,5 @@ function parseStoreOptions(keysAndOptions: any[]): [string[], CreateComputedOpti
return [keysAndOptions.slice(0, -1), keysAndOptions.at(-1)];
}

return [keysAndOptions];
return [keysAndOptions, { equal: Object.is }];
}
10 changes: 10 additions & 0 deletions libs/plugin/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"factory": "./src/generators/init-cannon/generator",
"schema": "./src/generators/init-cannon/schema.json",
"description": "Init Angular Three cannon with proper packages "
},
"rapier": {
"factory": "./src/generators/init-rapier/generator",
"schema": "./src/generators/init-rapier/schema.json",
"description": "Init Angular Three rapier with proper packages "
}
},
"schematics": {
Expand All @@ -44,6 +49,11 @@
"factory": "./src/generators/init-cannon/compat",
"schema": "./src/generators/init-cannon/schema.json",
"description": "Init Angular Three cannon with proper packages "
},
"rapier": {
"factory": "./src/generators/init-rapier/compat",
"schema": "./src/generators/init-rapier/schema.json",
"description": "Init Angular Three rapier with proper packages "
}
}
}
6 changes: 4 additions & 2 deletions libs/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
"packageGroup": [
"angular-three-soba",
"angular-three-postprocessing",
"angular-three-cannon"
"angular-three-cannon",
"angular-three-rapier"
]
},
"ng-update": {
"migrations": "./migrations.json",
"packageGroup": [
"angular-three-soba",
"angular-three-postprocessing",
"angular-three-cannon"
"angular-three-cannon",
"angular-three-rapier"
]
},
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions libs/plugin/src/generators/init-rapier/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { convertNxGenerator } from '@nx/devkit';
import init from './generator';

export default convertNxGenerator(init);
21 changes: 21 additions & 0 deletions libs/plugin/src/generators/init-rapier/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { readJson, Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { ANGULAR_THREE_VERSION, RAPIER_COMPAT_VERSION } from '../versions';
import init from './generator';

describe('init generator', () => {
let appTree: Tree;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
});

it('should add three dependencies', async () => {
await init(appTree);

const packageJson = readJson(appTree, 'package.json');

expect(packageJson.dependencies['angular-three-rapier']).toEqual(ANGULAR_THREE_VERSION);
expect(packageJson.dependencies['@dimforge/rapier3d-compat']).toEqual(RAPIER_COMPAT_VERSION);
});
});
28 changes: 28 additions & 0 deletions libs/plugin/src/generators/init-rapier/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { addDependenciesToPackageJson, installPackagesTask, logger, readJson, type Tree } from '@nx/devkit';
import { ANGULAR_THREE_VERSION, NGXTENSION_VERSION, RAPIER_COMPAT_VERSION } from '../versions';

export default async function (tree: Tree) {
logger.log('Initializing Angular Three Rapier...');

const packageJson = readJson(tree, 'package.json');

const version =
packageJson['dependencies']?.['angular-three'] ||
packageJson['devDependencies']?.['angular-three'] ||
ANGULAR_THREE_VERSION;

addDependenciesToPackageJson(
tree,
{
'angular-three-rapier': version,
'angular-three-soba': version,
'@dimforge/rapier3d-compat': RAPIER_COMPAT_VERSION,
ngxtension: NGXTENSION_VERSION,
},
{},
);

return () => {
installPackagesTask(tree);
};
}
6 changes: 6 additions & 0 deletions libs/plugin/src/generators/init-rapier/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Init",
"title": "Init Angular Three Cannon"
}
2 changes: 2 additions & 0 deletions libs/plugin/src/generators/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export const CANNON_WORKER_API_VERSION = '^2.0.0';
export const CANNON_ES_VERSION = '^0.20.0';
export const CANNON_ES_DEBUGGER_VERSION = '^1.0.0';

export const RAPIER_COMPAT_VERSION = '0.11.2';

export const NGXTENSION_VERSION = '^0.3.0';
2 changes: 2 additions & 0 deletions libs/plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { default as initCannonGenerator } from './generators/init-cannon/generator';
export { default as initPostprocessingGenerator } from './generators/init-postprocessing/generator';
export { default as initRapierGenerator } from './generators/init-rapier/generator';
export { default as initSobaGenerator } from './generators/init-soba/generator';
export { default as initGenerator } from './generators/init/generator';
40 changes: 40 additions & 0 deletions libs/rapier/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "platform",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "platform",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
7 changes: 7 additions & 0 deletions libs/rapier/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# rapier

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test rapier` to execute the unit tests.
22 changes: 22 additions & 0 deletions libs/rapier/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'rapier',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../coverage/libs/rapier',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
7 changes: 7 additions & 0 deletions libs/rapier/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/rapier",
"lib": {
"entryFile": "src/index.ts"
}
}
38 changes: 38 additions & 0 deletions libs/rapier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "angular-three-rapier",
"version": "0.0.0-replace",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/angular-threejs/angular-three/tree/main/libs/rapier"
},
"author": {
"name": "Chau Tran",
"email": "nartc7789@gmail.com",
"url": "https://nartc.me"
},
"description": "Cannon.js physics integration with Angular Three",
"keywords": [
"angular",
"threejs",
"renderer",
"rapier",
"physics"
],
"license": "MIT",
"peerDependencies": {
"@angular/common": " ^16.0.0",
"@angular/core": " ^16.0.0",
"@dimforge/rapier3d-compat": "0.11.2",
"angular-three": "^2.0.0",
"angular-three-soba": "^2.0.0",
"ngxtension": "^0.1.0",
"three": ">=0.148.0"
},
"dependencies": {
"tslib": "^2.3.0"
},
"sideEffects": false
}
47 changes: 47 additions & 0 deletions libs/rapier/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "rapier",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/rapier/src",
"prefix": "platform",
"tags": [],
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/angular:package",
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
"options": {
"project": "libs/rapier/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/rapier/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/rapier/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/rapier/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/rapier/**/*.ts", "libs/rapier/**/*.html", "libs/rapier/package.json"]
}
}
}
}
4 changes: 4 additions & 0 deletions libs/rapier/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib/instanced-rigid-bodies';
export * from './lib/physics';
export * from './lib/rigid-body';
export * from './lib/types';
Loading

0 comments on commit ff76de7

Please sign in to comment.