|
|
|
|
|
|
|
const personalityConfig = { |
|
normal: { |
|
color: '#227c9d', |
|
name: 'normal', |
|
icon: 'mdi:account-circle', |
|
backgroundColor: 'cerulean', |
|
borderColor: 'border-blue-600' |
|
}, |
|
genuine_friend: { |
|
color: '#17c3b2', |
|
name: 'genuine friend', |
|
icon: 'mdi:account-heart', |
|
backgroundColor: 'light-sea-green', |
|
borderColor: 'border-teal-600' |
|
}, |
|
sensitive_to_compliments: { |
|
color: '#ffcb77', |
|
name: 'sensitive to compliments', |
|
icon: 'mdi:account-star', |
|
backgroundColor: 'sunset', |
|
borderColor: 'border-yellow-600' |
|
}, |
|
rebellious: { |
|
color: '#fe6d73', |
|
name: 'rebellious', |
|
icon: 'mdi:account-alert', |
|
backgroundColor: 'light-red', |
|
borderColor: 'border-red-600' |
|
} |
|
}; |
|
|
|
|
|
function getRandomPersonality() { |
|
const personalities = Object.keys(personalityConfig); |
|
const randomIndex = Math.floor(Math.random() * personalities.length); |
|
return personalities[randomIndex]; |
|
} |
|
|
|
|
|
function createPlayerSquare(personality) { |
|
const config = personalityConfig[personality]; |
|
|
|
|
|
const square = document.createElement('div'); |
|
square.className = `w-16 h-16 rounded-md shadow-lg flex flex-col items-center justify-center text-white font-medium pop-in ${config.backgroundColor}`; |
|
|
|
|
|
square.innerHTML = ` |
|
<span class="iconify mb-1" data-icon="${config.icon}" data-width="24" data-height="24"></span> |
|
<span class="text-xs">You</span> |
|
`; |
|
|
|
return square; |
|
} |
|
|
|
|
|
function initializePersonalitySystem() { |
|
|
|
const personalitySelect = document.getElementById('personality-select'); |
|
const gridContainer = document.getElementById('grid-container'); |
|
const gameInfo = document.getElementById('game-info'); |
|
|
|
|
|
const selectedPersonality = getRandomPersonality(); |
|
const config = personalityConfig[selectedPersonality]; |
|
|
|
|
|
personalitySelect.value = selectedPersonality; |
|
|
|
|
|
const personalityDisplay = document.createElement('div'); |
|
personalityDisplay.className = 'bg-white rounded-lg p-4 shadow-md mb-4'; |
|
personalityDisplay.innerHTML = ` |
|
<div class="text-sm text-gray-600 mb-2">Your Personality:</div> |
|
<div class="flex items-center gap-2"> |
|
<div class="w-3 h-3 rounded-full" style="background-color: ${config.color}"></div> |
|
<span class="font-medium capitalize">${config.name.replace(/_/g, ' ')}</span> |
|
</div> |
|
`; |
|
|
|
|
|
if (gameInfo) { |
|
gameInfo.insertBefore(personalityDisplay, gameInfo.firstChild); |
|
} |
|
|
|
|
|
const playerSquare = createPlayerSquare(selectedPersonality); |
|
if (gridContainer) { |
|
|
|
gridContainer.innerHTML = ''; |
|
gridContainer.appendChild(playerSquare); |
|
} |
|
|
|
|
|
window.playerPersonality = selectedPersonality; |
|
|
|
|
|
const chatContent = document.getElementById('chat-content'); |
|
if (chatContent) { |
|
const personalityMessage = document.createElement('div'); |
|
personalityMessage.className = 'text-gray-600 text-sm italic mb-4'; |
|
personalityMessage.textContent = `You joined as a ${config.name.replace(/_/g, ' ')}`; |
|
chatContent.appendChild(personalityMessage); |
|
} |
|
} |
|
|
|
|
|
window.personalitySystem = { |
|
config: personalityConfig, |
|
getRandomPersonality, |
|
createPlayerSquare, |
|
initialize: initializePersonalitySystem |
|
}; |
|
|
|
|
|
document.addEventListener('DOMContentLoaded', initializePersonalitySystem); |
|
|
|
|
|
document.addEventListener('personalityUpdated', (event) => { |
|
const newPersonality = event.detail.personality; |
|
const config = personalityConfig[newPersonality]; |
|
|
|
|
|
const playerSquare = document.querySelector('#grid-container > div'); |
|
if (playerSquare) { |
|
Object.keys(personalityConfig).forEach(personality => { |
|
const pConfig = personalityConfig[personality]; |
|
playerSquare.classList.remove(pConfig.backgroundColor); |
|
}); |
|
playerSquare.classList.add(config.backgroundColor); |
|
playerSquare.querySelector('.iconify').setAttribute('data-icon', config.icon); |
|
} |
|
}); |