STATS - EricEisaman/cs1-ide GitHub Wiki
.env
DATABASE_API_PROPERTIES="cheese"
src/stats/stats.js
CS1.stats.cheeseDial = new RingDial({
container: containers.top,
labelText: 'Cheese',
labelColor: '#ccc',
gradientColor1: 'white',
gradientColor2: 'orange',
max: 1000
});
CS1.stats.cheeseDial.setValue(500);
src/core/components/vrui/page3.html
<button onclick='CS1.ui.controls.addCheeseBall()'>
🧀Cheese Ball🧀
</button>
<button onclick='CS1.ui.controls.saveAndExitGame()'>
👋Save Exit Game👋
</button>
src/core/components/vrui/controls.js
CS1.ui.controls.addCheeseBall = e => {
const sphere = document.createElement("a-sphere");
sphere.setAttribute("color", "orange");
sphere.setAttribute("scale", "0.3 0.3 0.3");
sphere.setAttribute("collectible", "affects:cheeseDial ; value:10; threshold:1.7");
sphere.setAttribute("grabbable", "");
sphere.classList = "cheeseball";
const pp = CS1.myPlayer.object3D.position;
sphere.object3D.position.set(pp.x, pp.y + 4, pp.z);
CS1.scene.appendChild(sphere);
};
CS1.ui.controls.saveAndExitGame = e => {
function onCheeseSaved(result){
if(result.success){
location.reload();
}else{
alert('Your Cheese was not saved to the server. 😭');
location.reload();
}
}
CS1.db.set({cheese : CS1.stats.cheeseDial.value} , onCheeseSaved);
console.log('request to exit');
}
src/core/components/my-components.js
document.addEventListener('gameStart',e=>{
function onCheeseRetrieved(result){
if(result.success){
CS1.stats.cheeseDial.setValue(result.value);
}else{
CS1.log('Your cheese could not be retrieved from the server.');
}
}
CS1.db.get( 'cheese' , onCheeseRetrieved);
});