mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-12-04 04:43:59 +01:00
add db commands and test payout (worked!)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Socket event handlers for the Wowngeon game
|
||||
* Socket event handlers for the Wownerogue game
|
||||
*/
|
||||
const SocketHandlers = {
|
||||
_initialized: false,
|
||||
@@ -53,6 +53,7 @@ const SocketHandlers = {
|
||||
socket.on('address_confirmed', this.onAddressConfirmed);
|
||||
socket.on('address_update_error', this.onAddressUpdateError);
|
||||
socket.on('address_prompt', this.onAddressPrompt);
|
||||
socket.on('game_mode_info', this.onGameModeInfo);
|
||||
socket.on('payment_created', this.onPaymentCreated);
|
||||
socket.on('payment_confirmed', this.onPaymentConfirmed);
|
||||
socket.on('payment_detected', this.onPaymentDetected);
|
||||
@@ -67,7 +68,7 @@ const SocketHandlers = {
|
||||
SocketHandlers._didConnect = true;
|
||||
// Include stored session token in a lightweight resume emit (if server did not get it via handshake)
|
||||
try {
|
||||
const existing = localStorage.getItem('wowngeon_token');
|
||||
const existing = localStorage.getItem('wownerogue_token');
|
||||
if (existing) {
|
||||
// If we later decide to rely solely on query param at io() creation, this is harmless redundancy.
|
||||
socket.io.opts.query = socket.io.opts.query || {};
|
||||
@@ -84,7 +85,7 @@ const SocketHandlers = {
|
||||
|
||||
onSessionToken: function(data) {
|
||||
if (data && data.token) {
|
||||
try { localStorage.setItem('wowngeon_token', data.token); } catch(e) {}
|
||||
try { localStorage.setItem('wownerogue_token', data.token); } catch(e) {}
|
||||
$('#messages').append($('<li class="status">').text('New session established. Token stored.'));
|
||||
UI.scrollChat();
|
||||
}
|
||||
@@ -92,7 +93,7 @@ const SocketHandlers = {
|
||||
|
||||
onSessionResumed: function(data) {
|
||||
if (data && data.token) {
|
||||
try { localStorage.setItem('wowngeon_token', data.token); } catch(e) {}
|
||||
try { localStorage.setItem('wownerogue_token', data.token); } catch(e) {}
|
||||
$('#messages').append($('<li class="status">').text('Session resumed.'));
|
||||
UI.scrollChat();
|
||||
}
|
||||
@@ -301,6 +302,18 @@ const SocketHandlers = {
|
||||
|
||||
onAddressConfirmed: function(data) {
|
||||
console.log('Address confirmed:', data);
|
||||
|
||||
// Cleanup previous address-related messages to reduce clutter
|
||||
$('#messages li').each(function() {
|
||||
const text = $(this).text();
|
||||
if (text.includes('Paste your payout address') ||
|
||||
text.includes('Detected payout address') ||
|
||||
text.includes('Type \'confirm\' to save') ||
|
||||
text.includes('Address detected. Type confirm')) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
|
||||
$('#messages').append($('<li class="address-confirmed" style="color: #0f0; white-space: pre-line;">').text(data.message));
|
||||
UI.scrollChat();
|
||||
if (typeof AddressModal !== 'undefined') {
|
||||
@@ -323,9 +336,32 @@ const SocketHandlers = {
|
||||
}
|
||||
},
|
||||
|
||||
onGameModeInfo: function(data) {
|
||||
console.log('Game mode info received:', data);
|
||||
|
||||
if (typeof UI !== 'undefined' && UI.updateGameTitle) {
|
||||
UI.updateGameTitle(data.cryptoType);
|
||||
}
|
||||
|
||||
if (typeof PaymentUI !== 'undefined') {
|
||||
PaymentUI.updateConfig(data);
|
||||
// Show shop button if payments enabled
|
||||
if (data.paymentsEnabled) {
|
||||
$('#shopButton').show();
|
||||
} else {
|
||||
$('#shopButton').hide();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onPaymentCreated: function(data) {
|
||||
console.log('Payment created:', data);
|
||||
if (typeof AudioAlerts !== 'undefined') { AudioAlerts.playRequestCoin(); }
|
||||
|
||||
if (typeof PaymentUI !== 'undefined') {
|
||||
PaymentUI.showPaymentRequest(data);
|
||||
}
|
||||
|
||||
const parts = [];
|
||||
const reusedCopy = data.reused
|
||||
? '🔁 <strong>Pending payment request still active.</strong> Use the same amount and address below.'
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Payment UI Manager
|
||||
* Handles the game mode selection and payment modal interactions
|
||||
*/
|
||||
const PaymentUI = {
|
||||
config: null,
|
||||
|
||||
init: function() {
|
||||
console.log("Initializing PaymentUI...");
|
||||
|
||||
// Bind close button
|
||||
$('#close-payment').on('click', function() {
|
||||
$('#payment-ui').hide();
|
||||
});
|
||||
|
||||
// Bind mode options
|
||||
$('.mode-option').on('click', function() {
|
||||
const mode = $(this).data('mode');
|
||||
PaymentUI.handleModeSelection(mode);
|
||||
});
|
||||
|
||||
// Bind check payment button
|
||||
$('#check-payment').on('click', function() {
|
||||
const paymentId = $(this).data('payment-id');
|
||||
if (paymentId && window.socket) {
|
||||
window.socket.emit('check_payment_status', { paymentId });
|
||||
$(this).text('Checking...');
|
||||
setTimeout(() => $('#check-payment').text('🔄 Check Payment'), 1000);
|
||||
}
|
||||
});
|
||||
|
||||
// Bind copy button
|
||||
$('#copy-address').on('click', function() {
|
||||
const addr = $('#payment-address').val();
|
||||
if(addr) {
|
||||
// Try modern clipboard API first
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(addr).then(() => {
|
||||
$('#copy-address').text('Copied!');
|
||||
setTimeout(() => $('#copy-address').html('📋 Copy Address'), 2000);
|
||||
});
|
||||
} else {
|
||||
// Fallback
|
||||
const $temp = $("<input>");
|
||||
$("body").append($temp);
|
||||
$temp.val(addr).select();
|
||||
document.execCommand("copy");
|
||||
$temp.remove();
|
||||
$('#copy-address').text('Copied!');
|
||||
setTimeout(() => $('#copy-address').html('📋 Copy Address'), 2000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Bind Shop Button (will be added to index.html)
|
||||
$('#shopButton').on('click', function() {
|
||||
PaymentUI.show();
|
||||
});
|
||||
},
|
||||
|
||||
updateConfig: function(config) {
|
||||
console.log("PaymentUI config updated:", config);
|
||||
this.config = config;
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
if (!this.config) return;
|
||||
|
||||
const currency = this.config.cryptoType || 'WOW';
|
||||
const decimals = currency === 'XMR' ? 12 : 11;
|
||||
const divisor = Math.pow(10, decimals);
|
||||
|
||||
// Update PAID_SINGLE
|
||||
if (this.config.directModeEnabled) {
|
||||
const price = (this.config.singleGamePrice / divisor).toFixed(decimals === 12 ? 4 : 2);
|
||||
const $el = $('.mode-option[data-mode="PAID_SINGLE"]');
|
||||
$el.html(`<strong>💰 PAID SINGLE</strong> - ${price} ${currency} per game<br><span style="font-size:0.8em;color:#aaa;">Payouts enabled for winners</span>`);
|
||||
$el.show();
|
||||
} else {
|
||||
$('.mode-option[data-mode="PAID_SINGLE"]').hide();
|
||||
}
|
||||
|
||||
// Update PAID_CREDITS
|
||||
if (this.config.creditsModeEnabled) {
|
||||
// Note: config.creditsPackagePrice is for the default package
|
||||
const price = (this.config.creditsPackagePrice / divisor).toFixed(decimals === 12 ? 4 : 2);
|
||||
// We assume the default package size is 10 if not specified, but let's be vague if unsure
|
||||
// Ideally we'd get package info. For now, "Credits Package" is safe.
|
||||
const $el = $('.mode-option[data-mode="PAID_CREDITS"]');
|
||||
$el.html(`<strong>🎫 CREDITS PACKAGE</strong> - ${price} ${currency}<br><span style="font-size:0.8em;color:#aaa;">Bulk discount, no payouts</span>`);
|
||||
$el.show();
|
||||
} else {
|
||||
$('.mode-option[data-mode="PAID_CREDITS"]').hide();
|
||||
}
|
||||
|
||||
// Update FREE
|
||||
if (!this.config.paymentsEnabled) {
|
||||
$('.mode-option[data-mode="FREE"]').show();
|
||||
// If payments are disabled, maybe hide the others?
|
||||
// The logic above handles hiding if enabled flags are false.
|
||||
} else {
|
||||
// If payments are enabled, FREE is usually disabled/hidden
|
||||
$('.mode-option[data-mode="FREE"]').hide();
|
||||
}
|
||||
},
|
||||
|
||||
handleModeSelection: function(mode) {
|
||||
console.log("Mode selected:", mode);
|
||||
|
||||
if (mode === 'FREE') {
|
||||
$('#payment-ui').hide();
|
||||
return;
|
||||
}
|
||||
|
||||
let paymentType = 'single_game';
|
||||
if (mode === 'PAID_CREDITS') {
|
||||
paymentType = 'credits_package';
|
||||
}
|
||||
|
||||
if (window.socket) {
|
||||
window.socket.emit('request_payment', { type: paymentType });
|
||||
|
||||
// Show loading state
|
||||
$('.game-modes').hide();
|
||||
$('#payment-details').show();
|
||||
$('#payment-status').text('Requesting payment address...');
|
||||
$('#payment-amount').text('...');
|
||||
$('#payment-address').val('Loading...');
|
||||
}
|
||||
},
|
||||
|
||||
showPaymentRequest: function(data) {
|
||||
$('#payment-ui').show();
|
||||
$('#payment-details').show();
|
||||
$('.game-modes').hide(); // Hide selection, show payment
|
||||
$('.payment-header strong').text('💳 Payment Required');
|
||||
|
||||
const displayAmount = data.humanAmount || data.amountFormatted || data.amount;
|
||||
$('#payment-amount').text(displayAmount + ' ' + (data.currency || ''));
|
||||
$('#payment-address').val(data.address);
|
||||
$('#check-payment').data('payment-id', data.id);
|
||||
|
||||
if (data.reused) {
|
||||
$('#payment-status').html('<span style="color:#ff0">♻️ Using existing pending payment</span>');
|
||||
} else {
|
||||
$('#payment-status').text('Waiting for payment...');
|
||||
}
|
||||
},
|
||||
|
||||
show: function() {
|
||||
$('#payment-ui').show();
|
||||
$('.game-modes').show();
|
||||
$('#payment-details').hide();
|
||||
$('.payment-header strong').text('🎮 Game Mode Selection');
|
||||
}
|
||||
};
|
||||
|
||||
// Expose globally
|
||||
window.PaymentUI = PaymentUI;
|
||||
|
||||
// Initialize when DOM is ready
|
||||
$(document).ready(function() {
|
||||
PaymentUI.init();
|
||||
});
|
||||
+20
-2
@@ -33,7 +33,7 @@ const UI = {
|
||||
// Initialize teletype animation
|
||||
initTeletype: function() {
|
||||
$('#banner').teletype({
|
||||
text: ["Welcome traveler...", "You have arrived at...", "The Wowngeon"],
|
||||
text: ["Welcome traveler...", "You have arrived at...", "The Dungeon"],
|
||||
typeDelay: 100,
|
||||
backDelay: 50,
|
||||
pause: 1500
|
||||
@@ -42,11 +42,29 @@ const UI = {
|
||||
// After animations are complete, set static text
|
||||
setTimeout(function() {
|
||||
$('#banner, #bannercursor').fadeOut(500, function() {
|
||||
$('#staticbanner').text("WOWGUE - A Wownero Roguelike").fadeIn(500);
|
||||
const title = UI._gameTitleFull || "WOWNEROGUE - A Wownero Roguelike";
|
||||
$('#staticbanner').text(title).fadeIn(500);
|
||||
});
|
||||
}, 14000);
|
||||
},
|
||||
|
||||
_gameTitleFull: "WOWNEROGUE - A Wownero Roguelike",
|
||||
|
||||
updateGameTitle: function(cryptoType) {
|
||||
if (cryptoType === 'XMR') {
|
||||
document.title = "XMROGUE - A Monero Roguelike";
|
||||
this._gameTitleFull = "XMROGUE - A Monero Roguelike";
|
||||
} else {
|
||||
document.title = "Wownerogue - A Wownero Roguelike";
|
||||
this._gameTitleFull = "WOWNEROGUE - A Wownero Roguelike";
|
||||
}
|
||||
|
||||
// If the static banner is already visible (animation finished), update it immediately
|
||||
if ($('#staticbanner').is(':visible') && !$('#banner').is(':visible')) {
|
||||
$('#staticbanner').text(this._gameTitleFull);
|
||||
}
|
||||
},
|
||||
|
||||
// Initialize browser detection
|
||||
initBrowserDetection: function() {
|
||||
setTimeout(function() {
|
||||
|
||||
Reference in New Issue
Block a user