File size: 7,207 Bytes
a902964
2b188f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9a99f1d
a902964
2b188f0
 
 
 
 
92ff83d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0f7d41
0c4aaca
 
 
 
 
 
 
9a99f1d
 
 
 
 
7d1349c
0c4aaca
9a99f1d
 
 
 
 
 
 
 
 
 
 
 
 
 
0c4aaca
9a99f1d
0c4aaca
9a99f1d
7d1349c
9a99f1d
 
7d1349c
0c4aaca
9a99f1d
 
0c4aaca
9a99f1d
 
 
0c4aaca
9a99f1d
 
 
0045c57
9a99f1d
 
 
 
 
 
 
 
 
 
 
0045c57
9a99f1d
 
 
 
0045c57
9a99f1d
 
 
 
 
a902964
9a99f1d
7d1349c
9a99f1d
 
 
 
 
 
 
 
8f9670e
 
 
9a99f1d
8f9670e
 
 
 
9a99f1d
 
8f9670e
9a99f1d
 
 
8f9670e
 
 
 
 
 
 
 
 
 
9a99f1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

// Tier List Maker Drag & Drop
function initializeDragDrop() {
    document.addEventListener('dragstart', function(ev) {
        if (ev.target.classList.contains('char-card')) {
            ev.dataTransfer.setData("text", ev.target.id);
        }
    });

    document.addEventListener('dragover', function(ev) {
        if (ev.target.classList.contains('tier-drop-zone') || 
            ev.target.classList.contains('character-pool') ||
            ev.target.closest('.tier-drop-zone') || 
            ev.target.closest('.character-pool')) {
            ev.preventDefault();
        }
    });

    document.addEventListener('drop', function(ev) {
        if (ev.target.classList.contains('tier-drop-zone') || 
            ev.target.classList.contains('character-pool')) {
            ev.preventDefault();
            var data = ev.dataTransfer.getData("text");
            var draggedElement = document.getElementById(data);
            ev.target.appendChild(draggedElement);
        } else {
            var targetZone = ev.target.closest('.tier-drop-zone') || 
                            ev.target.closest('.character-pool');
            if (targetZone) {
                ev.preventDefault();
                var data = ev.dataTransfer.getData("text");
                var draggedElement = document.getElementById(data);
                targetZone.appendChild(draggedElement);
            }
        }
    });
}

// Build Calculator and Utility Handling
document.addEventListener('DOMContentLoaded', function() {
    // Initialize drag and drop if on tier list maker page
    if (document.getElementById('tier-list')) {
        initializeDragDrop();
    }

// Star Rating Functionality
document.addEventListener('click', function(e) {
    if (e.target.classList.contains('star')) {
        const stars = e.target.parentElement.querySelectorAll('.star');
        const rating = parseInt(e.target.getAttribute('data-value'));
        const hiddenInput = e.target.parentElement.nextElementSibling;
        
        stars.forEach((star, index) => {
            if (index < rating) {
                star.classList.add('active');
            } else {
                star.classList.remove('active');
            }
        });
        
        hiddenInput.value = rating;
    }
});
const buildForm = document.getElementById('build-form');
const previewElements = {
        toon: document.getElementById('preview-toon'),
        buildName: document.getElementById('preview-build-name'),
        trinkets: document.getElementById('preview-trinkets'),
        rationale: document.getElementById('preview-rationale'),
        ratingSection: document.getElementById('build-rating')
    };

    // --- Configuration Maps ---
    const config = {
        toonNames: { 'vee': 'Vee', 'pebble': 'Pebble', 'sprout': 'Sprout', 'shelly': 'Shelly' },
        goalNames: { 'ichor': 'Ichor Farming', 'survival': 'Solo Survival', 'research': 'Research Farming', 'support': 'Team Support' },
        trinketNames: { 'remote': "Vee's Remote", 'magnifying': 'Magnifying Glass', 'plush': 'Dandy Plush', 'bow': 'Pink Bow' }
    };

    if (buildForm) {
        // --- Real-time Preview Update ---
        buildForm.addEventListener('input', function() {
            const formData = new FormData(buildForm);
            const data = Object.fromEntries(formData.entries());

            // Toon and Goal Display
            const toonDisplay = config.toonNames[data.toon] || 'Select a Toon';
            previewElements.toon.textContent = toonDisplay;
            
            // Build Name and Goal
            let buildNameDisplay = data.buildName || 'No build name yet';
            if (data.goal && config.goalNames[data.goal]) {
                buildNameDisplay = `${buildNameDisplay} - ${config.goalNames[data.goal]}`;
            }
            previewElements.buildName.textContent = buildNameDisplay;

            // Trinket Display
            const trinkets = [];
            if (data.trinket1 && config.trinketNames[data.trinket1]) trinkets.push(config.trinketNames[data.trinket1]);
            if (data.trinket2 && config.trinketNames[data.trinket2]) trinkets.push(config.trinketNames[data.trinket2]);
            previewElements.trinkets.textContent = trinkets.join(' + ') || 'No trinkets selected';

            // Rationale Display
            previewElements.rationale.textContent = data.rationale || 'Add your strategic rationale to see it here';

            // Show rating section when key fields are filled
            const isComplete = data.toon && data.goal && data.trinket1 && data.trinket2 && data.buildName;
            previewElements.ratingSection.classList.toggle('hidden', !isComplete);

            // Re-render Feather icons if used in the preview
            feather.replace();
        });

        // --- Form Submission and Local Storage Save ---
        buildForm.addEventListener('submit', function(e) {
            e.preventDefault();
            const formData = new FormData(buildForm);
            const data = Object.fromEntries(formData.entries());
            
            // Simple validation check (assuming select fields have default value="")
            if (!data.toon || !data.goal || !data.trinket1 || !data.trinket2 || !data.buildName || !data.rationale) {
                alert('Please fill all required fields, including the rationale!');
                return;
            }

            // Save to localStorage
            const builds = JSON.parse(localStorage.getItem('builds') || '[]');
            builds.push({ ...data, date: new Date().toISOString() }); // Use spread syntax for efficiency
            localStorage.setItem('builds', JSON.stringify(builds));

            alert('Build saved successfully!');
            buildForm.reset();
            
            // Re-render Feather icons after reset
            feather.replace(); 
        });
    }

    // --- Smooth Scrolling for Anchor Links ---
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href'));
            if (target) {
                target.scrollIntoView({ behavior: 'smooth' });
            }
        });
    });

    // --- Initialize Tooltips ---
    const tooltipTriggers = document.querySelectorAll('[data-tooltip]');
    
    tooltipTriggers.forEach(trigger => {
        const tooltip = document.createElement('div');
        // Use consistent classes for styling
        tooltip.className = 'tooltip hidden md:block bg-gray-800 text-white px-3 py-1 rounded text-xs absolute z-40 whitespace-nowrap opacity-95 transition-opacity duration-200';
        tooltip.textContent = trigger.getAttribute('data-tooltip');
        
        // Use a relative container for better positioning
        trigger.style.position = 'relative'; 
        trigger.appendChild(tooltip);
        
        trigger.addEventListener('mouseenter', () => {
            tooltip.classList.remove('hidden');
        });
        
        trigger.addEventListener('mouseleave', () => {
            tooltip.classList.add('hidden');
        });
    });
});