SandGame/config.js

79 lines
2.3 KiB
JavaScript

export const defaultConfig = {
global: { gravity: 0.5, drag: 0.9 },
time: { paused: false, speed: 1 },
brush: { size: 4 },
explosive: {
radius: 15,
force: 2.0,
destroy: {
rock: true,
wood: true,
dirt: true,
sand: true,
plant: true,
grass: true,
water: false,
acid: true,
ice: true,
lava: false,
oil: true
}
},
acid: {
dissolveChance: 0.05,
sinkChance: 0.2,
dispersion: 4,
explodeTNT: false,
dissolve: {
rock: false,
wood: true,
dirt: true,
sand: false,
plant: true,
grass: true,
water: false,
ice: true,
oil: true
}
},
fire: { burnChance: 0.015 },
water: { flowChance: 1.0, dispersion: 5 },
lava: { flowChance: 0.4, dispersion: 2, coolingChance: 0.04, sinkChance: 0.7 },
oil: { flowChance: 0.85, dispersion: 4, burnChance: 0.04, sinkChance: 0.25, floatChance: 0.25 },
ice: { meltChance: 0.02, freezeChance: 0.01 },
steam: { condenseChance: 0.01 },
smoke: { dissipateChance: 0.02 },
plant: { growChance: 0.02, woodificationChance: 0.01, burnChance: 0.4 },
grass: { growChance: 0.03, burnChance: 0.5 },
wood: { burnChance: 0.05 },
visual: { style: 'blocky', colorNoise: true }
};
export let config = JSON.parse(JSON.stringify(defaultConfig));
export function setConfig(newConfig) {
config = newConfig;
}
export function saveSettings() {
localStorage.setItem('sandGameSettings', JSON.stringify(config));
}
export function loadSettings() {
if (localStorage.getItem('sandGameSettings')) {
try {
const saved = JSON.parse(localStorage.getItem('sandGameSettings'));
for (const key in saved) {
if (config[key]) {
if (typeof config[key] === 'object' && !Array.isArray(config[key])) {
Object.assign(config[key], saved[key]);
} else {
config[key] = saved[key];
}
}
}
} catch (e) {
console.error('Error loading settings:', e);
}
}
}