summaryrefslogtreecommitdiff
path: root/src/block.ts
diff options
context:
space:
mode:
authorJ08nY2016-04-29 00:09:43 +0200
committerJ08nY2016-04-29 00:09:43 +0200
commit7caff3e0edcf8982ec716143ed030b2790061b39 (patch)
tree16673b30ff5fcb35c53bdcbeeea0cf0fa9b22d25 /src/block.ts
parente243829840896b29c2508d3984b229adc3074edc (diff)
downloadomniplex-master.tar.gz
omniplex-master.tar.zst
omniplex-master.zip
pointerlock workHEADmaster
Diffstat (limited to 'src/block.ts')
-rw-r--r--src/block.ts181
1 files changed, 98 insertions, 83 deletions
diff --git a/src/block.ts b/src/block.ts
index bd80239..0d5b97e 100644
--- a/src/block.ts
+++ b/src/block.ts
@@ -1,5 +1,95 @@
module Omni {
+ export class Block {
+ private state:number;
+
+ private mesh:Physijs.BoxMesh;
+
+ static states:number[];
+ static mesh_file:string = "";
+
+ //will take the correct state as params?
+ constructor(private geometry:THREE.Geometry, private materials:THREE.Material[]) {
+ this.mesh = new Physijs.BoxMesh(geometry, materials[0], 0);
+ }
+
+ getState():number {
+ return this.state;
+ }
+
+ setState(state:number):void {
+ this.state = state;
+ }
+
+ setPosition(pos:THREE.Vector3):void {
+ this.mesh.position.copy(pos);
+ }
+
+ getPosition():THREE.Vector3 {
+ return this.mesh.position.clone();
+ }
+
+ getObject():THREE.Object3D {
+ return this.mesh;
+ }
+
+ }
+
+ /**
+ * Plain block without any puzzles.
+ */
+ export class PlainBlock extends Block {
+ static mesh_file = "plainBlock.json";
+ static states:number[] = [];
+
+ constructor(loader:BlockLoader) {
+ super(loader.getMesh(PlainBlock.mesh_file), loader.getMaterials(PlainBlock.mesh_file));
+ }
+ }
+
+ /**
+ * Button block with 2 states
+ */
+ export class ButtonBlock extends Block {
+ //need to make good design choices here, with the handling of states..
+ static mesh_file = "buttonBlock.json";
+ static states:number[] = [0, 1];
+
+ constructor(loader:BlockLoader) {
+ super(loader.getMesh(ButtonBlock.mesh_file), loader.getMaterials(ButtonBlock.mesh_file));
+ }
+ }
+
+ /**
+ * Lever block with 4 positions/states
+ */
+ export class LeverBlock extends Block {
+ static mesh_file = "leverBlock.json";
+ static states:number[] = [0, 1, 2, 3];
+
+ constructor(loader:BlockLoader) {
+ super(loader.getMesh(LeverBlock.mesh_file), loader.getMaterials(LeverBlock.mesh_file));
+ }
+ }
+
+ /**
+ *
+ */
+ export class AzimuthBlock extends Block {
+ static mesh_file = "azimuthBlock.json";
+ static states:number[] = [0, 1, 2, 3];
+
+ }
+
+ /**
+ *
+ */
+ export class PullBlock extends Block {
+ static mesh_file = "pullBlock.json";
+ static states:number[] = [];
+
+ }
+
export class BlockLoader {
private manager:THREE.LoadingManager = new THREE.LoadingManager();
private loader:THREE.JSONLoader = new THREE.JSONLoader(this.manager);
@@ -10,12 +100,13 @@ module Omni {
private loaded:boolean = false;
static URL_PREFIX:string = "json/";
- static FILES:string[] = [
+ static BLOCKS:string[] = [
PlainBlock.mesh_file,
LeverBlock.mesh_file,
- ButtonBlock.mesh_file,
- AzimuthBlock.mesh_file,
- PullBlock.mesh_file];
+ //ButtonBlock.mesh_file,
+ //AzimuthBlock.mesh_file,
+ //PullBlock.mesh_file,
+ ];
/**
* @param files what files to load()
@@ -23,6 +114,7 @@ module Omni {
constructor(private files:string[]) {
this.manager.onLoad = () => {
this.loaded = true;
+ console.debug("BlockLoader: loaded");
};
}
@@ -30,7 +122,7 @@ module Omni {
* Load all the geometries and materials from mesh_files
*/
load():void {
- console.log("BlockLoader: loading...");
+ console.debug("BlockLoader: loading...");
this.files.forEach((file) => {
this.loadOne(file);
});
@@ -58,7 +150,7 @@ module Omni {
* Dispose of all the geometries and mats
*/
dispose():void {
- console.log("BlockLoader: disposing...");
+ console.debug("BlockLoader: disposing...");
if (this.loaded) {
this.files.forEach((file) => {
this.geometries[file].dispose();
@@ -90,81 +182,4 @@ module Omni {
return this.materials[file];
}
}
-
- export class Block {
- private state:number;
-
- private mesh:Physijs.BoxMesh;
-
- static states:number[];
- static mesh_file:string = "";
-
- //will take the correct state as params?
- constructor() {
-
- }
-
- getState():number {
- return this.state;
- }
-
- setState(state:number):void {
- this.state = state;
- }
- }
-
- /**
- * Plain block without any puzzles.
- */
- export class PlainBlock extends Block {
- static mesh_file = "plainBlock.json";
- static states:number[] = [];
-
- constructor() {
- super();
- }
- }
-
- /**
- * Button block with 2 states
- */
- export class ButtonBlock extends Block {
- //need to make good design choices here, with the handling of states..
- static mesh_file = "buttonBlock.json";
- static states:number[] = [0, 1];
-
- constructor() {
- super();
- }
- }
-
- /**
- * Lever block with 4 positions/states
- */
- export class LeverBlock extends Block {
- static mesh_file = "leverBlock.json";
- static states:number[] = [0, 1, 2, 3];
-
- constructor() {
- super();
- }
- }
-
- /**
- *
- */
- export class AzimuthBlock extends Block {
- static mesh_file = "azimuthBlock.json";
- static states:number[] = [0, 1, 2, 3];
-
- }
-
- /**
- *
- */
- export class PullBlock extends Block {
- static mesh_file = "pullBlock.json";
- static states:number[] = [];
-
- }
} \ No newline at end of file