Skip to content

Commit

Permalink
Update characterCreator.js
Browse files Browse the repository at this point in the history
  • Loading branch information
davespser authored Dec 6, 2024
1 parent 6c8af6d commit 641aa08
Showing 1 changed file with 47 additions and 28 deletions.
75 changes: 47 additions & 28 deletions js/characterCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,53 @@ function renderQuestions() {
const questionDiv = document.createElement("div");
questionDiv.innerHTML = `
<label>${question}</label>
<input type="number" id="question-${index}" step="0.01" min="0" max="1" required>
<input type="number" id="question-${index}" step="0.01" min="0" max="5" required>
`;
container.appendChild(questionDiv);
});
container.appendChild(submitButton);
}

submitButton.addEventListener("click", async () => {
responses = questions.map((_, index) => {
const value = parseFloat(document.getElementById(`question-${index}`).value) || 0;
return Math.min(Math.max(value, 0), 1); // Asegurarse de que esté entre 0 y 1
function calculateCharacterData(r, g, b) {
const total = r + g + b;
return {
attack: (r / 255) * 100,
speed: ((r + g) / 510) * 100,
magic: (b / 255) * 100,
defense: ((r * 0.6 + g * 0.4) / 255) * 100,
precision: ((g + b) / 510) * 100,
vitality: (total / 765) * 100,
agility: (g / 255) * 100,
intelligence: (b / 255) * 100,
endurance: (r / 255) * 50 + (g / 255) * 50,
charisma: (b / 255) * 75,
perception: (g / 255) * 75,
creativity: (b / 255) * 100,
leadership: (r / 255) * 100,
stealth: (g / 255) * 100,
resilience: ((r + g) / 510) * 100,
bravery: (r / 255) * 100,
focus: (b / 255) * 100,
luck: ((g + b) / 510) * 50,
energy: (total / 765) * 100,
harmony: ((r + g + b) / (255 * 3)) * 100
};
}

submitButton.addEventListener("click", async (event) => {
event.preventDefault();

const answers = questions.map((_, index) => {
const value = parseInt(document.getElementById(`question-${index}`).value, 10) || 0;
return Math.min(Math.max(value, 0), 5);
});

const [strength, dexterity, intelligence] = responses;

// Calcular color base
const r = Math.round(strength * 255);
const g = Math.round(dexterity * 255);
const b = Math.round(intelligence * 255);
const color = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;

// Derivar estadísticas secundarias
const stats = {
ATK: (r + g) / (2 * 255) * 100,
SPD: (g / 255) * 100,
MAG: (b / 255) * 100,
DEF: (r / 255) * 100,
ACC: (g + b) / (2 * 255) * 100,
VIT: ((r + g + b) / 3 * 255) * 100
};
const red = Math.min(255, answers.slice(0, 1).reduce((acc, val) => acc + val * 50, 0));
const green = Math.min(255, answers.slice(1, 2).reduce((acc, val) => acc + val * 50, 0));
const blue = Math.min(255, answers.slice(2).reduce((acc, val) => acc + val * 50, 0));

const colorHex = `#${red.toString(16).padStart(2, "0")}${green.toString(16).padStart(2, "0")}${blue.toString(16).padStart(2, "0")}`;
const derivedStats = calculateCharacterData(red, green, blue);

// Obtener usuario actual
const auth = getAuth();
Expand All @@ -84,14 +101,14 @@ submitButton.addEventListener("click", async () => {
// Guardar datos en Firebase
await update(userRef, {
characterCreated: true,
stats: { strength, dexterity, intelligence },
color,
derivedStats: stats
stats: { red, green, blue },
color: colorHex,
derivedStats
});

// Cargar escena principal
container.remove();
loadThreeScene({ x: 0, y: 0, z: 0, color, stats });
loadThreeScene({ x: 0, y: 0, z: 0, color: colorHex, stats: derivedStats });
} else {
alert("No se encontró un usuario autenticado.");
}
Expand All @@ -100,6 +117,8 @@ submitButton.addEventListener("click", async () => {

// Renderizar el cuestionario al cargar la página
renderQuestions();

export function loadCharacterCreator(userId) {
// Código de la función
}
console.log("Cargando creador de personaje para usuario:", userId);
renderQuestions();
}

0 comments on commit 641aa08

Please sign in to comment.