Created
December 9, 2013 14:15
-
-
Save BaldarSilveraxe/7872824 to your computer and use it in GitHub Desktop.
Roll20 Trader Joe Hand Out interface
This file contains hidden or 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
on('chat:message', function(msg) { | |
if(msg.type !== "api"){return}; | |
roll20API.contentPlayerid = getObj("player", msg.playerid); | |
roll20API.contentUserid = roll20API.contentPlayerid.get("d20userid"); | |
if(allowedUser.indexOf(roll20API.contentUserid) == -1){return}; | |
roll20API.contentGiven = msg.content.toLowerCase(); | |
if(roll20API.contentGiven.indexOf(' ') == -1){ | |
roll20API.contentMessage = null; | |
roll20API.contentCommand = roll20API.contentGiven.substr(1, roll20API.contentGiven.length); | |
}else{ | |
roll20API.contentMessage = roll20API.contentGiven.substr(roll20API.contentGiven.indexOf(' ') + 1); | |
roll20API.contentCommand = roll20API.contentGiven.substr(1, roll20API.contentGiven.indexOf(' ')-1); | |
}; | |
roll20API.valid = false; | |
if(roll20API.contentMessage == "yes"){roll20API.valid = true;}; | |
traderJoeCommandSwitch(); | |
}); | |
traderJoeCommandSwitch = function() { | |
switch (roll20API.contentCommand){ | |
case "install": | |
refreshCatalog(); | |
refreshCharacters(); | |
resetCursorLocation(); | |
createToFromTable(); | |
refreshToFromTable(); | |
break; | |
case "traderjoeup": | |
moveCursorUp(); | |
refreshToFromTable(); | |
break; | |
case "traderjoedown": | |
moveCursorDown(); | |
refreshToFromTable(); | |
break; | |
case "traderjoeright": | |
cycleRight(); | |
refreshToFromTable(); | |
break; | |
}; | |
}; | |
cycleRight = function () { | |
if(roll20API.tableLocationRow == undefined | |
|| roll20API.tableLocationRow == null | |
|| isNaN(roll20API.tableLocationRow)){roll20API.tableLocationRow = 0;}; | |
if(roll20API.tableLocationRow == 0){state.charactersFrom.push(state.charactersFrom.shift());}; | |
if(roll20API.tableLocationRow == 1){state.charactersTo.push(state.charactersTo.shift());}; | |
if(roll20API.tableLocationRow == 2){state.CatalogFamily.push(state.CatalogFamily.shift());}; | |
}; | |
moveCursorUp = function () { | |
if(roll20API.tableLocationRow == undefined | |
|| roll20API.tableLocationRow == null | |
|| isNaN(roll20API.tableLocationRow)){roll20API.tableLocationRow = 0;}; | |
roll20API.tableLocationRow = roll20API.tableLocationRow - 1; | |
if(roll20API.tableLocationRow < 0){roll20API.tableLocationRow = 2;}; | |
} | |
moveCursorDown = function () { | |
if(roll20API.tableLocationRow == undefined | |
|| roll20API.tableLocationRow == null | |
|| isNaN(roll20API.tableLocationRow)){roll20API.tableLocationRow = 0;}; | |
roll20API.tableLocationRow = roll20API.tableLocationRow + 1; | |
if(roll20API.tableLocationRow > 2){roll20API.tableLocationRow = 0;}; | |
} | |
refreshCatalog = function () { | |
state.CatalogFamily = _.chain(roll20API.TraderJoeCatalog).map(function(item) { return item.family }).uniq().value(); | |
_.each(state.CatalogFamily, function(section) { | |
state.catalogSections[section] = []; | |
_.each(roll20API.TraderJoeCatalog, function(item) { | |
if(item.family == section){state.catalogSections[section].push(item);}; | |
}); | |
}); | |
}; | |
refreshCharacters = function () { | |
state.characters = []; | |
state.charactersTo = []; | |
state.charactersFrom = []; | |
_.each(findObjs({ _type: "character"}), function(loopCharacter) { | |
if(loopCharacter.get("archived") == false){ | |
state.characters.push(loopCharacter); | |
state.charactersTo.push(loopCharacter); | |
state.charactersFrom.push(loopCharacter); | |
}; | |
}); | |
}; | |
resetCursorLocation = function () { | |
roll20API.tableLocationRow = 0; | |
}; | |
createToFromTable = function () { | |
if(findObjs({ _type: "handout", name: "API_Trader_Joe" }).length == 0){ | |
createObj("handout", { | |
name: "API_Trader_Joe", | |
notes: "Welcome to the API Trading Post." | |
}); | |
}; | |
state.API_TraderId = findObjs({ _type: "handout", name: "API_Trader_Joe" })[0].get("_id") | |
}; | |
refreshToFromTable = function () { | |
var tableStyle = roll20API.tableStyle; | |
var Ct1A1 = ""; | |
var Ct1B1 = ""; | |
var Ct1A2 = ""; | |
var Ct1B2 = ""; | |
var Ct1A3 = ""; | |
var Ct1B3 = ""; | |
if(roll20API.tableLocationRow == 0){Ct1A1 = roll20API.tdStyleDbWf;Ct1B1 = roll20API.tdStyleLbBf}; | |
if(roll20API.tableLocationRow == 1){Ct1A2 = roll20API.tdStyleDbWf;Ct1B2 = roll20API.tdStyleLbBf}; | |
if(roll20API.tableLocationRow == 2){Ct1A3 = roll20API.tdStyleDbWf;Ct1B3 = roll20API.tdStyleLbBf}; | |
Ct1B1value = state.charactersFrom[0].name | |
Ct1C1value = state.charactersFrom[0]._id | |
Ct1B2value = state.charactersTo[0].name | |
Ct1C2value = state.charactersTo[0]._id | |
Ct1B3value = state.CatalogFamily[0] | |
var htmlToFrom = "\ | |
<table " + tableStyle + ">\ | |
<tr>\ | |
<td " + Ct1A1 + "><b>From</b></td>\ | |
<td " + Ct1B1 + ">" + Ct1B1value + "</td>\ | |
<td>" + Ct1C1value + "</td>\ | |
<tr>\ | |
</tr>\ | |
<td " + Ct1A2 + "><b>To</b></td>\ | |
<td " + Ct1B2 + ">" + Ct1B2value + "</td>\ | |
<td>" + Ct1C2value + "</td>\ | |
</tr>\ | |
<tr>\ | |
<td " + Ct1A3 + "><b>Item Type</b></td>\ | |
<td colspan=\"2\"" + Ct1B3 + ">" + Ct1B3value + "</td>\ | |
</tr>\ | |
</table>" | |
findObjs({ _type: "handout", _id: state.API_TraderId })[0].set({notes: htmlToFrom}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment