mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added make_sprite command
This commit is contained in:
parent
1e900e8c6a
commit
388a899a7f
@ -59,6 +59,7 @@ pub enum ChatCommand {
|
|||||||
Lantern,
|
Lantern,
|
||||||
Light,
|
Light,
|
||||||
MakeBlock,
|
MakeBlock,
|
||||||
|
MakeSprite,
|
||||||
Motd,
|
Motd,
|
||||||
Object,
|
Object,
|
||||||
Players,
|
Players,
|
||||||
@ -105,6 +106,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
|||||||
ChatCommand::Lantern,
|
ChatCommand::Lantern,
|
||||||
ChatCommand::Light,
|
ChatCommand::Light,
|
||||||
ChatCommand::MakeBlock,
|
ChatCommand::MakeBlock,
|
||||||
|
ChatCommand::MakeSprite,
|
||||||
ChatCommand::Motd,
|
ChatCommand::Motd,
|
||||||
ChatCommand::Object,
|
ChatCommand::Object,
|
||||||
ChatCommand::Players,
|
ChatCommand::Players,
|
||||||
@ -162,6 +164,11 @@ lazy_static! {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
static ref SPRITE_KINDS: Vec<String> = terrain::sprite::SPRITE_KINDS
|
||||||
|
.keys()
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
/// List of item specifiers. Useful for tab completing
|
/// List of item specifiers. Useful for tab completing
|
||||||
static ref ITEM_SPECS: Vec<String> = {
|
static ref ITEM_SPECS: Vec<String> = {
|
||||||
let path = assets::ASSETS_PATH.join("common").join("items");
|
let path = assets::ASSETS_PATH.join("common").join("items");
|
||||||
@ -306,7 +313,12 @@ impl ChatCommand {
|
|||||||
),
|
),
|
||||||
ChatCommand::MakeBlock => cmd(
|
ChatCommand::MakeBlock => cmd(
|
||||||
vec![Enum("block", BLOCK_KINDS.clone(), Required)],
|
vec![Enum("block", BLOCK_KINDS.clone(), Required)],
|
||||||
"Make a block",
|
"Make a block at your location",
|
||||||
|
Admin,
|
||||||
|
),
|
||||||
|
ChatCommand::MakeSprite => cmd(
|
||||||
|
vec![Enum("sprite", SPRITE_KINDS.clone(), Required)],
|
||||||
|
"Make a sprite at your location",
|
||||||
Admin,
|
Admin,
|
||||||
),
|
),
|
||||||
ChatCommand::Motd => cmd(
|
ChatCommand::Motd => cmd(
|
||||||
@ -422,6 +434,7 @@ impl ChatCommand {
|
|||||||
ChatCommand::Lantern => "lantern",
|
ChatCommand::Lantern => "lantern",
|
||||||
ChatCommand::Light => "light",
|
ChatCommand::Light => "light",
|
||||||
ChatCommand::MakeBlock => "make_block",
|
ChatCommand::MakeBlock => "make_block",
|
||||||
|
ChatCommand::MakeSprite => "make_sprite",
|
||||||
ChatCommand::Motd => "motd",
|
ChatCommand::Motd => "motd",
|
||||||
ChatCommand::Object => "object",
|
ChatCommand::Object => "object",
|
||||||
ChatCommand::Players => "players",
|
ChatCommand::Players => "players",
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
sys,
|
sys,
|
||||||
terrain::{Block, TerrainChunk, TerrainGrid},
|
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||||
time::DayPeriod,
|
time::DayPeriod,
|
||||||
vol::WriteVol,
|
vol::{ReadVol, WriteVol},
|
||||||
};
|
};
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
use rayon::{ThreadPool, ThreadPoolBuilder};
|
use rayon::{ThreadPool, ThreadPoolBuilder};
|
||||||
@ -264,6 +264,11 @@ impl State {
|
|||||||
/// Get a writable reference to this state's terrain.
|
/// Get a writable reference to this state's terrain.
|
||||||
pub fn terrain_mut(&self) -> FetchMut<TerrainGrid> { self.ecs.write_resource() }
|
pub fn terrain_mut(&self) -> FetchMut<TerrainGrid> { self.ecs.write_resource() }
|
||||||
|
|
||||||
|
/// Get a block in this state's terrain.
|
||||||
|
pub fn get_block(&self, pos: Vec3<i32>) -> Option<Block> {
|
||||||
|
self.terrain().get(pos).ok().copied()
|
||||||
|
}
|
||||||
|
|
||||||
/// Set a block in this state's terrain.
|
/// Set a block in this state's terrain.
|
||||||
pub fn set_block(&mut self, pos: Vec3<i32>, block: Block) {
|
pub fn set_block(&mut self, pos: Vec3<i32>, block: Block) {
|
||||||
self.ecs.write_resource::<BlockChange>().set(pos, block);
|
self.ecs.write_resource::<BlockChange>().set(pos, block);
|
||||||
|
@ -12,9 +12,9 @@ use common::{
|
|||||||
npc::{self, get_npc_name},
|
npc::{self, get_npc_name},
|
||||||
state::TimeOfDay,
|
state::TimeOfDay,
|
||||||
sync::{Uid, WorldSyncExt},
|
sync::{Uid, WorldSyncExt},
|
||||||
terrain::{Block, BlockKind, TerrainChunkSize},
|
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
||||||
util::Dir,
|
util::Dir,
|
||||||
vol::RectVolSize,
|
vol::{RectVolSize, Vox},
|
||||||
LoadoutBuilder,
|
LoadoutBuilder,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
@ -87,6 +87,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
|||||||
ChatCommand::Lantern => handle_lantern,
|
ChatCommand::Lantern => handle_lantern,
|
||||||
ChatCommand::Light => handle_light,
|
ChatCommand::Light => handle_light,
|
||||||
ChatCommand::MakeBlock => handle_make_block,
|
ChatCommand::MakeBlock => handle_make_block,
|
||||||
|
ChatCommand::MakeSprite => handle_make_sprite,
|
||||||
ChatCommand::Motd => handle_motd,
|
ChatCommand::Motd => handle_motd,
|
||||||
ChatCommand::Object => handle_object,
|
ChatCommand::Object => handle_object,
|
||||||
ChatCommand::Players => handle_players,
|
ChatCommand::Players => handle_players,
|
||||||
@ -217,6 +218,44 @@ fn handle_make_block(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_make_sprite(
|
||||||
|
server: &mut Server,
|
||||||
|
client: EcsEntity,
|
||||||
|
target: EcsEntity,
|
||||||
|
args: String,
|
||||||
|
action: &ChatCommand,
|
||||||
|
) {
|
||||||
|
if let Some(sprite_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
||||||
|
if let Ok(sk) = SpriteKind::try_from(sprite_name.as_str()) {
|
||||||
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
||||||
|
Some(pos) => {
|
||||||
|
let pos = pos.0.map(|e| e.floor() as i32);
|
||||||
|
let new_block = server
|
||||||
|
.state
|
||||||
|
.get_block(pos)
|
||||||
|
.unwrap_or_else(Block::empty)
|
||||||
|
.with_sprite(sk);
|
||||||
|
server.state.set_block(pos, new_block);
|
||||||
|
},
|
||||||
|
None => server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandError.server_msg(String::from("You have no position.")),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandError.server_msg(format!("Invalid sprite kind: {}", sprite_name)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandError.server_msg(action.help_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_motd(
|
fn handle_motd(
|
||||||
server: &mut Server,
|
server: &mut Server,
|
||||||
client: EcsEntity,
|
client: EcsEntity,
|
||||||
|
@ -44,7 +44,6 @@ impl Animation for AlphaAnimation {
|
|||||||
/ 10.0;
|
/ 10.0;
|
||||||
|
|
||||||
let switch = if random > 0.5 { 1.0 } else { -1.0 };
|
let switch = if random > 0.5 { 1.0 } else { -1.0 };
|
||||||
println!("{:?}", random);
|
|
||||||
if switch > 0.0 {
|
if switch > 0.0 {
|
||||||
next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1) * 1.02;
|
next.head.position = Vec3::new(0.0, skeleton_attr.head.0, skeleton_attr.head.1) * 1.02;
|
||||||
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(-0.2);
|
next.head.orientation = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(-0.2);
|
||||||
|
Loading…
Reference in New Issue
Block a user