Skip to content
Permalink
Browse files

Ts things

  • Loading branch information...
makitsune committed Dec 21, 2018
1 parent 4581295 commit 0b6ac62b0cc86d0e7ecb762c92bbbb2245e36da2
@@ -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 _snail
Submodule _snail added at ac6267
Submodule _typings deleted from bc5436
@@ -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");

This file was deleted.

Oops, something went wrong.
@@ -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);
});
}
}
@@ -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")
});
@@ -7,7 +7,7 @@
"removeComments": true
},
"include": [
"../../_typings",
"../../_snail/typings",
"src"
],
"exclude": [ "typings" ]

0 comments on commit 0b6ac62

Please sign in to comment.
You can’t perform that action at this time.