Apps Home
|
Create an App
LogProgress
Author:
unefesseeetaulitdev
Description
Source Code
Launch App
Current Users
Created by:
Unefesseeetaulitdev
// This app is basically the standard tip goal with a progress bar, // courtesy of chelsea2950 (Dorothy's Tip Goals author). // Instead of increasing linearly with tips, the progress bar increases // logarithmically, giving more weight to early donnations and less to // late donnations. // This is done to try to incentivize donnations for big goals, and avoid // discouraging early donnors // // The intended use case is for couple who just want to stream their regular // lovemaking sessions without having to set intermediary goals that would // interrupt their natural flow while still trying to maximize tips. // vars var total_tipped = 0; var last_tip_username = null; var last_tip_amount = 0; var subject_is_set_with_0 = false; cb.settings_choices = [ {name: 'tokens', type: 'int', minValue: 1, default: 100}, {name: 'goal_description', type: 'str', minLength: 1, maxLength: 255} ]; // handlers cb.onTip(function(tip) { total_tipped += tip['amount'] update_subject(); last_tip_amount = tip['amount'] last_tip_username = tip['from_user'] cb.drawPanel(); }); cb.onDrawPanel(function(user) { var remaining_label, remaining; if (total_tipped < cb.settings.tokens) { remaining_label = "Remaining Goal :" remaining = cb.settings.tokens - total_tipped; } else { remaining_label = "Tips over Goal :"; remaining = total_tipped - cb.settings.tokens + ", Thank you <3"; } return { 'template': '3_rows_of_labels', 'row1_label': remaining_label, 'row1_value': remaining, 'row2_label': 'Progress:', 'row2_value': goalBar(total_tipped, cb.settings.tokens), 'row3_label': 'Latest Tip Received:', 'row3_value': format_username(last_tip_username) + ' (' + last_tip_amount + ')' }; }); function get_log(x) { // take 25 * log_10(x + 1)**2 for a smooth log function that starts at 0 and // meets 100 at 100. // since js only handles ln, we convert the base and it gives // 4.715292425290347 * ln(x + 1)**2 // We use the |0 shortcut to convert to int return 4.715292425290347 * Math.log(x + 1) * Math.log(x + 1)|0; } function charRepeat(char, amount) { var string = ""; for (var i = 0; i < amount; i += 1) { string += char; } return string; } function goalBar(current,total) { var percent = Math.min(100 * (current / total), 100); var log_percent = get_log(percent); bar = ''; full = '\u25C6'; half = '\u25C8'; empty = '\u25C7'; drawn = 0; var empty_amount = (log_percent / 10)|0; bar += charRepeat(full, empty_amount); if (log_percent % 10 >= 5) { bar += half + charRepeat(empty, 9 - empty_amount) } else { bar += charRepeat(empty, 10 - empty_amount) } return bar; } // helper functions function update_subject() { var remaining = cb.settings.tokens - total_tipped; if (remaining <= 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; cb.changeRoomSubject( cb.settings.goal_description + " [Goal reached!]" ); } else { cb.changeRoomSubject( cb.settings.goal_description + " [" + remaining + " tokens remaining]" ); } } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function init() { update_subject(); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.