Comparing version
@@ -26,5 +26,6 @@ var __extends = (this && this.__extends) || (function () { | ||
import { System } from '0g'; | ||
import { b2BodyType, b2CircleShape, b2FixtureDef, b2PolygonShape, b2World, } from '@flyover/box2d'; | ||
import { b2BodyType, b2CircleShape, b2EdgeShape, b2FixtureDef, b2PolygonShape, b2World, } from '@flyover/box2d'; | ||
import { ContactListener } from './ContactListener'; | ||
import * as stores from './stores'; | ||
import { createCapsule } from './utils'; | ||
function assignBodyConfig(body, config, id) { | ||
@@ -46,2 +47,3 @@ var | ||
function createFixtureDef(config, id) { | ||
var _a; | ||
var density = config.density, restitution = config.restitution, friction = config.friction, shape = config.shape; | ||
@@ -53,10 +55,29 @@ var fix = new b2FixtureDef(); | ||
fix.userData = { entityId: id }; | ||
if (shape.shape === 'rectangle') { | ||
var s = new b2PolygonShape(); | ||
s.SetAsBox(shape.width / 2, shape.height / 2); | ||
fix.shape = s; | ||
var p; | ||
switch (shape.shape) { | ||
case 'rectangle': | ||
p = new b2PolygonShape(); | ||
p.SetAsBox(shape.width / 2, shape.height / 2); | ||
fix.shape = p; | ||
break; | ||
case 'circle': | ||
fix.shape = new b2CircleShape(shape.radius); | ||
break; | ||
case 'polygon': | ||
p = new b2PolygonShape(); | ||
p.Set(shape.vertices); | ||
fix.shape = p; | ||
break; | ||
case 'edge': | ||
var e = new b2EdgeShape(); | ||
e.Set(shape.v1, shape.v2); | ||
fix.shape = e; | ||
break; | ||
case 'capsule': | ||
p = new b2PolygonShape(); | ||
p.Set(createCapsule(shape.width, shape.height, (_a = shape.segments) !== null && _a !== void 0 ? _a : 8)); | ||
break; | ||
default: | ||
throw new Error("Shape " + shape.shape + " not supported (yet)"); | ||
} | ||
else { | ||
fix.shape = new b2CircleShape(shape.radius); | ||
} | ||
return fix; | ||
@@ -111,2 +132,4 @@ } | ||
if (!_this.defaultWorld) { | ||
// TODO: overkill? | ||
console.warn("No physics world when initializing " + bodyEntity.id); | ||
return; | ||
@@ -113,0 +136,0 @@ } |
@@ -10,2 +10,21 @@ export declare type RectangleBodyShape = { | ||
}; | ||
export declare type BodyShape = RectangleBodyShape | CircleBodyShape; | ||
export interface VectorLike { | ||
x: number; | ||
y: number; | ||
} | ||
export declare type PolygonBodyShape = { | ||
shape: 'polygon'; | ||
vertices: VectorLike[]; | ||
}; | ||
export declare type EdgeBodyShape = { | ||
shape: 'edge'; | ||
v1: VectorLike; | ||
v2: VectorLike; | ||
}; | ||
export declare type CapsuleBodyShape = { | ||
shape: 'capsule'; | ||
width: number; | ||
height: number; | ||
segments?: number; | ||
}; | ||
export declare type BodyShape = RectangleBodyShape | CircleBodyShape | PolygonBodyShape | EdgeBodyShape | CapsuleBodyShape; |
@@ -51,2 +51,3 @@ "use strict"; | ||
var stores = __importStar(require("./stores")); | ||
var utils_1 = require("./utils"); | ||
function assignBodyConfig(body, config, id) { | ||
@@ -68,2 +69,3 @@ var | ||
function createFixtureDef(config, id) { | ||
var _a; | ||
var density = config.density, restitution = config.restitution, friction = config.friction, shape = config.shape; | ||
@@ -75,10 +77,29 @@ var fix = new box2d_1.b2FixtureDef(); | ||
fix.userData = { entityId: id }; | ||
if (shape.shape === 'rectangle') { | ||
var s = new box2d_1.b2PolygonShape(); | ||
s.SetAsBox(shape.width / 2, shape.height / 2); | ||
fix.shape = s; | ||
var p; | ||
switch (shape.shape) { | ||
case 'rectangle': | ||
p = new box2d_1.b2PolygonShape(); | ||
p.SetAsBox(shape.width / 2, shape.height / 2); | ||
fix.shape = p; | ||
break; | ||
case 'circle': | ||
fix.shape = new box2d_1.b2CircleShape(shape.radius); | ||
break; | ||
case 'polygon': | ||
p = new box2d_1.b2PolygonShape(); | ||
p.Set(shape.vertices); | ||
fix.shape = p; | ||
break; | ||
case 'edge': | ||
var e = new box2d_1.b2EdgeShape(); | ||
e.Set(shape.v1, shape.v2); | ||
fix.shape = e; | ||
break; | ||
case 'capsule': | ||
p = new box2d_1.b2PolygonShape(); | ||
p.Set(utils_1.createCapsule(shape.width, shape.height, (_a = shape.segments) !== null && _a !== void 0 ? _a : 8)); | ||
break; | ||
default: | ||
throw new Error("Shape " + shape.shape + " not supported (yet)"); | ||
} | ||
else { | ||
fix.shape = new box2d_1.b2CircleShape(shape.radius); | ||
} | ||
return fix; | ||
@@ -133,2 +154,4 @@ } | ||
if (!_this.defaultWorld) { | ||
// TODO: overkill? | ||
console.warn("No physics world when initializing " + bodyEntity.id); | ||
return; | ||
@@ -135,0 +158,0 @@ } |
@@ -10,2 +10,21 @@ export declare type RectangleBodyShape = { | ||
}; | ||
export declare type BodyShape = RectangleBodyShape | CircleBodyShape; | ||
export interface VectorLike { | ||
x: number; | ||
y: number; | ||
} | ||
export declare type PolygonBodyShape = { | ||
shape: 'polygon'; | ||
vertices: VectorLike[]; | ||
}; | ||
export declare type EdgeBodyShape = { | ||
shape: 'edge'; | ||
v1: VectorLike; | ||
v2: VectorLike; | ||
}; | ||
export declare type CapsuleBodyShape = { | ||
shape: 'capsule'; | ||
width: number; | ||
height: number; | ||
segments?: number; | ||
}; | ||
export declare type BodyShape = RectangleBodyShape | CircleBodyShape | PolygonBodyShape | EdgeBodyShape | CapsuleBodyShape; |
{ | ||
"name": "0g-box2d", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "box2d plugin for 0g", | ||
@@ -25,6 +25,6 @@ "files": [ | ||
"prepublishOnly": "yarn build", | ||
"release": "npm publish --access public" | ||
"release": "npm publish --access public --registry https://registry.npmjs.org" | ||
}, | ||
"peerDependencies": { | ||
"0g": "^0.0.1", | ||
"0g": "^0.0.2", | ||
"@flyover/box2d": "^1.0.1" | ||
@@ -37,7 +37,7 @@ }, | ||
"devDependencies": { | ||
"0g": "^0.0.2", | ||
"@flyover/box2d": "^1.0.1", | ||
"@types/react": "^17.0.0", | ||
"0g": "link:../0g", | ||
"concurrently": "^5.3.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
89235
13.4%55
12.24%1453
13.96%2
100%