Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
107 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Submodule _typings
deleted from
bc5436
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters