2个版本
0.1.1 | 2020年5月23日 |
---|---|
0.1.0 | 2020年5月22日 |
#17 in #保存
125KB
538 行
TTB
这是什么?
一个用于保存和加载小镇构建文件的crate。
它在什么许可证下?
AGPLv3或更高版本
lib.rs
:
这是一个用于保存和加载.ttb文件的crate。
示例
基本用法
use {
std::{
io::{
Cursor,
},
},
ttb::{
Reader,
ReaderEvent,
Writer,
},
regenboog::{
RgbaU8,
},
};
let mut buf = [0; 1024];
let write_cursor = Cursor::new(&mut buf[..]);
let mut writer = Writer::new(write_cursor);
writer.write_header("Test", "This is a test. Meow.", &[
RgbaU8::WHITE,
RgbaU8::BLACK,
RgbaU8::RED,
RgbaU8::GREEN,
RgbaU8::BLUE,
]).unwrap();
writer.write_brick("1x1 Brick", 0, 0, 0, 0, 0).unwrap();
writer.write_brick("1x1 Brick", 0, 3, 0, 0, 1).unwrap();
writer.write_brick("1x1 Brick", 0, 6, 0, 0, 2).unwrap();
writer.write_brick("1x1 Brick", 0, 9, 0, 0, 3).unwrap();
writer.write_brick("1x1 Plate", 0, 10, 0, 0, 4).unwrap();
writer.finish().unwrap();
let read_cursor = Cursor::new(&buf[..]);
let mut reader = Reader::new(read_cursor);
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Meta {
build_name: "Test",
build_description: "This is a test. Meow.",
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Color {
id: 0,
color: RgbaU8::WHITE,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Color {
id: 1,
color: RgbaU8::BLACK,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Color {
id: 2,
color: RgbaU8::RED,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Color {
id: 3,
color: RgbaU8::GREEN,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Color {
id: 4,
color: RgbaU8::BLUE,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Brick {
brick_type: "1x1 Brick",
x: 0,
y: 0,
z: 0,
orientation: 0,
color_id: 0,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Brick {
brick_type: "1x1 Brick",
x: 0,
y: 3,
z: 0,
orientation: 0,
color_id: 1,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Brick {
brick_type: "1x1 Brick",
x: 0,
y: 6,
z: 0,
orientation: 0,
color_id: 2,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Brick {
brick_type: "1x1 Brick",
x: 0,
y: 9,
z: 0,
orientation: 0,
color_id: 3,
}));
assert_eq!(reader.next_event().unwrap(), Some(ReaderEvent::Brick {
brick_type: "1x1 Plate",
x: 0,
y: 10,
z: 0,
orientation: 0,
color_id: 4,
}));
依赖
~300–760KB
~18K SLoC