Skip to content

Commit

Permalink
Ts things
Browse files Browse the repository at this point in the history
  • Loading branch information
makidoll committed Dec 21, 2018
1 parent 4581295 commit 0b6ac62
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 83 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
@@ -1,3 +1,3 @@
[submodule "_typings"]
path = _typings
url = https://github.com/MarcusLlewellyn/hifi-typescript
[submodule "_snail"]
path = _snail
url = https://github.com/theepicsnail/hifi
1 change: 1 addition & 0 deletions _snail
Submodule _snail added at ac6267
1 change: 0 additions & 1 deletion _typings
Submodule _typings deleted from bc5436
66 changes: 37 additions & 29 deletions ts-client-scripts/_minecraft/_inventory.js
@@ -1,72 +1,80 @@
var ConnectionHandler = (function () {
function ConnectionHandler() {
var EventHandler = (function () {
function EventHandler() {
this.connections = [];
}
ConnectionHandler.prototype.connect = function (con, fun) {
con.connect(fun);
EventHandler.prototype.connect = function (event, callback) {
event.connect(callback);
this.connections.push({
con: con, fun: fun
event: event,
callback: callback
});
};
ConnectionHandler.prototype.disconnectAll = function () {
this.connections.forEach(function (connection) {
connection.con.disconnect(connection.fun);
EventHandler.prototype.disconnectAll = function () {
this.connections.forEach(function (con) {
con.event.disconnect(con.callback);
});
};
return ConnectionHandler;
return EventHandler;
}());
var Inventory = (function () {
function Inventory() {
this.selectedIndex = 0;
this.imageSizes = {
inventory: { width: 546, height: 66 },
selector: { width: 72, height: 72 }
};
this.selectedIndex = 0;
this.overlays = {
this.overlayIDs = {
inventory: Overlays.addOverlay("image", {
x: Window.innerWidth / 2 - this.imageSizes.inventory.width / 2,
y: this.imageSizes.inventory.height / 2,
width: this.imageSizes.inventory.width,
height: this.imageSizes.inventory.height,
imageURL: "file:///D:/Git/hifi-stuff/client-scripts/minecraftHifi/assets/inventory.png"
imageURL: Script.resolvePath("assets/inventory.png")
}),
selector: Overlays.addOverlay("image", {
x: Window.innerWidth / 2 - this.imageSizes.selector.width / 2 + (this.selectedIndex - 4) * 60,
y: this.imageSizes.selector.height / 2 - 6,
width: this.imageSizes.selector.width,
height: this.imageSizes.selector.height,
imageURL: "file:///D:/Git/hifi-stuff/client-scripts/minecraftHifi/assets/selector.png"
imageURL: Script.resolvePath("assets/selector.png")
})
};
this.events = new EventHandler();
this.events.connect(Window.geometryChanged, this.geometryChanged.bind(this));
this.events.connect(Overlays.mousePressOnOverlay, this.mousePressOnOverlay.bind(this));
}
Inventory.prototype.changeSelectedIndex = function (index) {
this.selectedIndex = index;
Overlays.editOverlay(this.overlays.selector, {
x: Window.innerWidth / 2 - this.imageSizes.selector.width / 2 + (this.selectedIndex - 4) * 60
});
};
Inventory.prototype.geometryChanged = function () {
Overlays.editOverlay(this.overlays.inventory, {
console.log(JSON.stringify(this));
Overlays.editOverlay(this.overlayIDs.inventory, {
x: Window.innerWidth / 2 - this.imageSizes.inventory.width / 2
});
Overlays.editOverlay(this.overlays.selector, {
Overlays.editOverlay(this.overlayIDs.selector, {
x: Window.innerWidth / 2 - this.imageSizes.selector.width / 2 + (this.selectedIndex - 4) * 60
});
};
Inventory.prototype.mousePressOnOverlay = function (overlayID, event) {
switch (overlayID) {
case this.overlayIDs.inventory:
console.log(JSON.stringify(event.pos2D));
break;
}
};
Inventory.prototype.changeSelectedIndex = function (index) {
this.selectedIndex = index;
Overlays.editOverlay(this.overlayIDs.selector, {
x: Window.innerWidth / 2 - this.imageSizes.selector.width / 2 + (this.selectedIndex - 4) * 60
});
};
Inventory.prototype.unload = function () {
var _this = this;
Object.keys(this.overlays).forEach(function (key) {
Overlays.deleteOverlay(_this.overlays[key]);
this.events.disconnectAll();
Object.keys(this.overlayIDs).forEach(function (key) {
Overlays.deleteOverlay(_this.overlayIDs[key]);
});
};
return Inventory;
}());
var inventory = new Inventory();
var cons = new ConnectionHandler();
cons.connect(Window.geometryChanged, function () {
inventory.geometryChanged();
});
Script.scriptEnding.connect(function () {
cons.disconnectAll();
inventory.unload();
});
console.log("test");
19 changes: 0 additions & 19 deletions ts-client-scripts/_minecraft/src/ConnectionHandler.ts

This file was deleted.

24 changes: 24 additions & 0 deletions ts-client-scripts/_minecraft/src/EventHandler.ts
@@ -0,0 +1,24 @@
class EventHandler {
private connections: {
event: any,
callback: Function,
}[];

constructor() {
this.connections = [];
}

connect(event: any, callback: Function) {
event.connect(callback);
this.connections.push({
event: event,
callback: callback
});
}

disconnectAll() {
this.connections.forEach(con=>{
con.event.disconnect(con.callback);
});
}
}
71 changes: 41 additions & 30 deletions ts-client-scripts/_minecraft/src/Inventory.ts
@@ -1,66 +1,77 @@
/// <reference path="ConnectionHandler.ts" />
/// <reference path="EventHandler.ts" />

class Inventory {
private overlays: {[key: string]: Uuid};
private imageSizes: {[key: string]: {width: number, height: number}} = {
inventory: { width: 546, height: 66},
selector: { width: 72, height: 72},
};
private events: EventHandler;
private overlayIDs: {[key: string]: Uuid};
private imageSizes: {[key: string]: {width: number, height: number}};
selectedIndex: number = 0;

constructor() {
this.overlays = {
this.imageSizes = {
inventory: { width: 546, height: 66},
selector: { width: 72, height: 72},
};

this.overlayIDs = {
inventory: Overlays.addOverlay("image", {
x: Window.innerWidth/2 - this.imageSizes.inventory.width/2,
y: this.imageSizes.inventory.height/2,
width: this.imageSizes.inventory.width,
height: this.imageSizes.inventory.height,
imageURL: "file:///D:/Git/hifi-stuff/client-scripts/minecraftHifi/assets/inventory.png",
imageURL: Script.resolvePath("assets/inventory.png"),
}),
selector: Overlays.addOverlay("image", {
x: Window.innerWidth/2 - this.imageSizes.selector.width/2 + (this.selectedIndex-4)*60,
y: this.imageSizes.selector.height/2 - 6,
width: this.imageSizes.selector.width,
height: this.imageSizes.selector.height,
imageURL: "file:///D:/Git/hifi-stuff/client-scripts/minecraftHifi/assets/selector.png",
imageURL: Script.resolvePath("assets/selector.png"),
})
}
};

this.events = new EventHandler();
this.events.connect(Window.geometryChanged, this.geometryChanged.bind(this));
this.events.connect(Overlays.mousePressOnOverlay, this.mousePressOnOverlay.bind(this));
}

changeSelectedIndex(index: number) {
this.selectedIndex = index;
private geometryChanged() {
console.log(JSON.stringify(this));

Overlays.editOverlay(this.overlays.selector, {
Overlays.editOverlay(this.overlayIDs.inventory, {
x: Window.innerWidth/2 - this.imageSizes.inventory.width/2,
});
Overlays.editOverlay(this.overlayIDs.selector, {
x: Window.innerWidth/2 - this.imageSizes.selector.width/2 + (this.selectedIndex-4)*60,
});
}

geometryChanged() {
Overlays.editOverlay(this.overlays.inventory, {
x: Window.innerWidth/2 - this.imageSizes.inventory.width/2,
});
Overlays.editOverlay(this.overlays.selector, {
private mousePressOnOverlay(overlayID, event) {
switch (overlayID) {
case this.overlayIDs.inventory:
console.log(JSON.stringify(event.pos2D));

break;
}
}

changeSelectedIndex(index: number) {
this.selectedIndex = index;

Overlays.editOverlay(this.overlayIDs.selector, {
x: Window.innerWidth/2 - this.imageSizes.selector.width/2 + (this.selectedIndex-4)*60,
});
}

unload() {
Object.keys(this.overlays).forEach(key=>{
Overlays.deleteOverlay(this.overlays[key]);
this.events.disconnectAll();

Object.keys(this.overlayIDs).forEach(key=>{
Overlays.deleteOverlay(this.overlayIDs[key]);
});
}
}

let inventory = new Inventory();
let cons = new ConnectionHandler();

cons.connect(Window.geometryChanged, ()=>{
inventory.geometryChanged();
})

Script.scriptEnding.connect(()=>{
cons.disconnectAll();
inventory.unload();
});

console.log("test")
});
2 changes: 1 addition & 1 deletion ts-client-scripts/_minecraft/tsconfig.json
Expand Up @@ -7,7 +7,7 @@
"removeComments": true
},
"include": [
"../../_typings",
"../../_snail/typings",
"src"
],
"exclude": [ "typings" ]
Expand Down

0 comments on commit 0b6ac62

Please sign in to comment.