Apps Home
|
My Uploads
|
Create an App
jessicalolly-tip-stats
Author:
unaa
Description
Source Code
Launch App
Current Users
Created by:
Unaa
App Images
// Personalized app for Jessicalolly's room. // - by Unaa. class JLRoom { // Background image used for texts. static get PANEL_BACKGROUND_ID_TEXTS() { return "c903b73e-ded8-4218-8d88-87492ad7088f"; } // Background image used for tip statistics. static get PANEL_BACKGROUND_ID_TIPS() { return "c903b73e-ded8-4218-8d88-87492ad7088f"; } constructor() { this.index = -1; this.interval = cb.settings.switchInterval || 5; this.lastTip = {user: "", amount: 0}; this.mvp = {user: "", amount: 0}; this.tips = new Map(); this.viewType = "text"; this.topText = ""; this.bottomText = ""; this.texts = [ {t: cb.settings.Text1, s: cb.settings.Subtext1}, {t: cb.settings.Text2, s: cb.settings.Subtext2} ]; this.tick(); cb.onDrawPanel(() => this.drawPanel()); cb.onTip((tip) => { this.lastTip = {user: tip.from_user, amount: tip.amount}; this.handleTipSorting(tip); }); } handleTipSorting(tip) { if (!this.tips.has(tip.from_user)) { this.tips.set(tip.from_user, 0); } this.tips.set(tip.from_user, this.tips.get(tip.from_user) + tip.amount); let aHigh = 0, uHigh = ''; this.tips.forEach((amount, user) => { if (aHigh < amount) { aHigh = amount; uHigh = user; } }); if (aHigh && uHigh) { this.mvp = {user: uHigh, amount: aHigh}; } } /** * Selects the next lines of text to display in the panel. * This method is executed every <interval> seconds. */ tick() { this.index++; // Reset the view index back to 0 once we've reached the end. if (this.index === 3 && this.mvp.user !== '') { this.index = 0; } // Don't show tip statistics if there are none. if (this.index === 2 && this.mvp.user === '') { this.index = 0; } switch (this.index) { case 0: // Show text + subtext #1 this.viewType = "text"; this.topText = this.texts[0].t; this.bottomText = this.texts[0].s; break; case 1: // Show text + subtext #2 this.viewType = "text"; this.topText = this.texts[1].t; this.bottomText = this.texts[1].s; break; case 2: // Show tip stats this.viewType = "tips"; this.topText = "Latest: " + this.lastTip.user + ' - ' + this.lastTip.amount; this.bottomText = "MVP: " + this.mvp.user + ' - ' + this.mvp.amount; break; } // Let the viewers update their panels & schedule the next tick. cb.drawPanel(); cb.setTimeout(() => this.tick(), this.interval * 1000); } /** * Draws the panel for the viewers. * * @returns {{template: string, layers: *[]}} */ drawPanel() { return { "template": "image_template", "layers": [ { "type": "image", "fileID": this.viewType === "text" ? JLRoom.PANEL_BACKGROUND_ID_TEXTS : JLRoom.PANEL_BACKGROUND_ID_TIPS }, { "type": "text", "top": 14, "left": this.viewType === "text" ? 72 : 72, "text": this.topText, "font-size": 12, "font-family": "Monotype Corsiva, Comic Sans MS, cursive", "color": "#37017C", "max-width": 200 }, { "type": "text", "top": 37, "left": this.viewType === "text" ? 65 : 65, "text": this.bottomText, "font-size": 12, "font-family": "Monotype Corsiva, Comic Sans MS, cursive", "color": "#f2deff", "max-width": 220 } ] }; } } cb.settings_choices = [ { name: "Text1", label: "Text #1", type: "str", minLength: 0, maxLength: 128, defaultValue: "Welcome!" }, { name: "Text2", label: "Text #2", type: "str", minLength: 0, maxLength: 128, defaultValue: "Hi there!" }, { name: "Subtext1", label: "Subtext #1", type: "str", minLength: 0, maxLength: 128, defaultValue: "Enjoy your stay <3" }, { name: "Subtext2", label: "Subtext #2", type: "str", minLength: 0, maxLength: 128, defaultValue: "Don't forget to say hi!" }, { name: "switchInterval", label: "Amount of seconds to alternate between texts & tip stats", type: "int", minValue: 1, maxValue: 300, defaultValue: 5 } ]; new JLRoom();
© Copyright Freesexcam 2011- 2024. All Rights Reserved.