mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 11:10:44 +00:00
improve code of new commands : do the parsing in parse and use destructuring
This commit is contained in:
parent
6c5a392b2b
commit
41811c79b5
1 changed files with 34 additions and 39 deletions
|
|
@ -278,18 +278,17 @@ function inject(serv, player) {
|
||||||
info: 'to play sound for yourself',
|
info: 'to play sound for yourself',
|
||||||
usage: '/playsound <sound_name> [volume] [pitch]',
|
usage: '/playsound <sound_name> [volume] [pitch]',
|
||||||
parse(str) {
|
parse(str) {
|
||||||
return str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
|
var results=str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
|
||||||
|
if(!results) return false;
|
||||||
|
return {
|
||||||
|
sound_name:results[1],
|
||||||
|
volume:results[2] ? parseFloat(results[2]) : 1.0,
|
||||||
|
pitch:results[3] ? parseFloat(results[3]) : 1.0
|
||||||
|
};
|
||||||
},
|
},
|
||||||
action(sound) {
|
action({sound_name,volume,pitch}) {
|
||||||
if (!sound) {
|
player.chat('Playing "'+sound_name+'" (volume: ' + volume + ', pitch: ' + pitch + ')');
|
||||||
player.chat('Usage: /playsound <sound_name> [volume] [pitch]');
|
player.playSound(sound_name, {volume: volume,pitch: pitch});
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.chat('Playing "'+sound[1]+'" (volume: ' + parseFloat((sound[2] || 1.0)) + ', pitch: ' + parseFloat((sound[3] || 1.0)) + ')');
|
|
||||||
player.playSound(sound[1], {
|
|
||||||
volume: parseFloat(sound[2]) || 1.0,
|
|
||||||
pitch: parseFloat(sound[3]) || 1.0
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -298,46 +297,42 @@ function inject(serv, player) {
|
||||||
info: 'to play sound for everyone',
|
info: 'to play sound for everyone',
|
||||||
usage: '/playsoundforall <sound_name> [volume] [pitch]',
|
usage: '/playsoundforall <sound_name> [volume] [pitch]',
|
||||||
parse(str) {
|
parse(str) {
|
||||||
return str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
|
var results=str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
|
||||||
|
if(!results) return false;
|
||||||
|
return {
|
||||||
|
sound_name:results[1],
|
||||||
|
volume:results[2] ? parseFloat(results[2]) : 1.0,
|
||||||
|
pitch:results[3] ? parseFloat(results[3]) : 1.0
|
||||||
|
};
|
||||||
},
|
},
|
||||||
action(sound) {
|
action({sound_name,volume,pitch}) {
|
||||||
if (!sound) {
|
player.chat('Playing "'+sound_name+'" (volume: ' + volume + ', pitch: ' + pitch + ')');
|
||||||
player.chat('Usage: /playsoundforall <sound_name> [volume] [pitch]');
|
serv.playSound(sound_name, player.world, player.entity.position.scaled(1/32), {volume: volume,pitch: pitch});
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.chat('Playing "'+sound[1]+'" (volume: ' + parseFloat((sound[2] || 1.0)) + ', pitch: ' + parseFloat((sound[3] || 1.0)) + ')');
|
|
||||||
serv.playSound(sound[1], player.world, player.entity.position.scaled(1/32), {
|
|
||||||
volume: parseFloat(sound[2]) || 1.0,
|
|
||||||
pitch: parseFloat(sound[3]) || 1.0
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
base.add({
|
base.add({
|
||||||
base: 'particle',
|
base: 'particle',
|
||||||
info: 'emit a particle at a position',
|
info: 'emit a particle at a position',
|
||||||
usage: '/particle <id> [amount] [<sizeX> <sizeY> <sizeZ>]',
|
usage: '/particle <id> [amount] [<sizeX> <sizeY> <sizeZ>]',
|
||||||
parse(str) {
|
parse(str) {
|
||||||
return str.match(/(\d+)(?: (\d+))?(?: (\d+))?(?: (\d+))?(?: (\d+))?(?: (\d+))?/);
|
var results=str.match(/(\d+)(?: (\d+))?(?: (\d+))?(?: (\d+))?(?: (\d+))?(?: (\d+))?/);
|
||||||
|
if(!results) return false;
|
||||||
|
return {
|
||||||
|
particle:parseInt(results[1]),
|
||||||
|
amount:results[2] ? parseInt(results[2]) : 1,
|
||||||
|
size:results[5] ? new Vec3(parseInt(results[3]), parseInt(results[4]), parseInt(results[5])) : new Vec3(1, 1, 1)
|
||||||
|
};
|
||||||
},
|
},
|
||||||
action(data) {
|
action({particle,amount,size}) {
|
||||||
if (!data) {
|
if (amount >= 100000) {
|
||||||
player.chat('Usage: /particle <id> [amount] [<sizeX> <sizeY> <sizeZ>]')
|
player.chat('You cannot emit more than 100,000 particles!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var particle = parseInt(data[1]);
|
player.chat('Emitting "' + particle + '" (count: ' + amount + ', size: ' + size.toString() + ')');
|
||||||
var amount = data[2] || 1;
|
serv.emitParticle(particle, player.world, player.entity.position.scaled(1/32), {count: amount,size: size});
|
||||||
if (amount >= 100000) {
|
|
||||||
chat('You cannot emit more than 100,000 particles!')
|
|
||||||
}
|
|
||||||
var size = data[5] ? Vec3(parseInt(data[3]), parseInt(data[4]), parseInt(data[5])) : Vec3(1, 1, 1);
|
|
||||||
player.chat('Emitting "' + data[1] + '" (count: ' + amount + ', size: ' + size.x + ',' + size.y + ',' + size.z + ')');
|
|
||||||
serv.emitParticle(particle, player.world, player.entity.position.scaled(1/32), {
|
|
||||||
count: amount,
|
|
||||||
size: size
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
serv.commands = base;
|
serv.commands = base;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue