Compare commits
29 Commits
b72e8f5ac8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fd0f6ddb21 | |||
| 75ca8c84ea | |||
| 2349d7365e | |||
| 1f231a8434 | |||
| ec06ab6585 | |||
| 7dae8f065f | |||
| c3ee95e31a | |||
| c962748797 | |||
| 4dd334d6a4 | |||
| 946f8b7826 | |||
| 751e3bb5f0 | |||
| 14ffe95f7d | |||
| 8ca5acc240 | |||
| 955645415d | |||
| c1be226956 | |||
| dc8fd68e32 | |||
| 4e69df12d1 | |||
| 1532700ea5 | |||
| 82c0f78177 | |||
| f323e0e841 | |||
| a5e5939fd5 | |||
| 68f5306283 | |||
| 0e5b0c4566 | |||
| 98288a4426 | |||
| d93f777b66 | |||
| 1a7d7c268a | |||
| c9c0942daf | |||
| a14cab8f41 | |||
| cc1015cc7a |
@@ -10,13 +10,15 @@ keywords = ["game-engine", "smallgames", "pixel-art", "tracker-music"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
eframe = "^0.12.0"
|
||||
egui = "^0.12.0"
|
||||
epi = "^0.12.0"
|
||||
env_logger = "0.8.3"
|
||||
hex = "^0.4.3"
|
||||
image = "0.23.14"
|
||||
log = "0.4.14"
|
||||
pixels = "0.3.0"
|
||||
rodio = "^0.11.0"
|
||||
rodio-xm = { git = "https://tinybird.dev/max/rodio-xm/", branch = "master" }
|
||||
rodio-xm = "^0.1.1"
|
||||
serde = "^1.0.114"
|
||||
serde_derive = "^1.0.114"
|
||||
toml = "^0.5.6"
|
||||
|
||||
5
LICENSE
5
LICENSE
@@ -1,6 +1,6 @@
|
||||
ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
|
||||
|
||||
Copyright © 2021 Max Bradbury
|
||||
Copyright © 2022 Max Bradbury
|
||||
|
||||
This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
|
||||
|
||||
@@ -11,8 +11,7 @@ Permission is hereby granted, free of charge, to any person or organization (the
|
||||
2. The User is one of the following:
|
||||
a. An individual person, laboring for themselves
|
||||
b. A non-profit organization
|
||||
c. An educational institution
|
||||
d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
|
||||
c. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labour
|
||||
|
||||
3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
|
||||
|
||||
|
||||
47
TODO.md
47
TODO.md
@@ -2,6 +2,22 @@
|
||||
|
||||
## game data structure
|
||||
|
||||
more colours? max 10? (0-9) max 16? (0-f)
|
||||
colours not in palette can use modulo
|
||||
background palette and foreground palette? would be good to make interactive stuff obvious
|
||||
|
||||
--
|
||||
|
||||
add "move" functions for entities
|
||||
e.g. move(direction), teleport
|
||||
|
||||
--
|
||||
|
||||
add "from_dir" functions for structs
|
||||
make that function generic?
|
||||
|
||||
--
|
||||
|
||||
what is the distinction between animate and inanimate objects?
|
||||
|
||||
idea:
|
||||
@@ -12,21 +28,7 @@ idea:
|
||||
* each position could have (optionally) a tile and (optionally) a thing
|
||||
* things have render priority
|
||||
|
||||
### colours
|
||||
|
||||
~convert colours to hex~
|
||||
* ~accept abcdef, #abcdef, 0xabcdef (inc. uppercase)~
|
||||
* ~export as #abcdef~
|
||||
|
||||
### palettes
|
||||
|
||||
### images
|
||||
|
||||
* ideally support gif/png...
|
||||
|
||||
### parser
|
||||
|
||||
* ~move tests into their respective modules where appropriate~
|
||||
* ideally support gif/png for images (are there other indexed colour formats?)
|
||||
|
||||
## players
|
||||
|
||||
@@ -34,10 +36,11 @@ idea:
|
||||
* re-use player avatar drawing function as generic image drawing function
|
||||
* text (how?)
|
||||
* support older graphics adaptors
|
||||
* player has some graphical tearing on non-integer window sizes
|
||||
|
||||
### linux
|
||||
|
||||
* ~get working~
|
||||
* show a help splash screen on first boot (with "do not show me this again" checkbox which saves to a local config)
|
||||
* what is peachy?
|
||||
* controls
|
||||
|
||||
### windows
|
||||
|
||||
@@ -62,3 +65,11 @@ will need:
|
||||
* build something in egui
|
||||
* can we do a web version that works with zip files?
|
||||
* investigate zip compression/decompression in rust
|
||||
|
||||
## documentation
|
||||
|
||||
where to find XMs?
|
||||
|
||||
https://modarchive.org/index.php?request=view_by_license&query=publicdomain etc.
|
||||
keygenmusic.org?
|
||||
pouet.net or something?
|
||||
|
||||
120
src/bin/editor.rs
Normal file
120
src/bin/editor.rs
Normal file
@@ -0,0 +1,120 @@
|
||||
use eframe::epi::Frame;
|
||||
use eframe::egui::CtxRef;
|
||||
use peachy::{Colour, Config, Game, Palette};
|
||||
|
||||
struct EditorState {
|
||||
game: Option<peachy::Game>,
|
||||
}
|
||||
|
||||
impl epi::App for EditorState {
|
||||
fn update(&mut self, ctx: &CtxRef, frame: &mut Frame<'_>) {
|
||||
egui::TopPanel::top("top_panel").show(ctx, |ui| {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
egui::menu::menu(ui, "File", |ui| {
|
||||
if ui.button("Quit").clicked() {
|
||||
frame.quit();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
egui::SidePanel::left("side_panel", 200.0).show(ctx, |ui| {
|
||||
ui.heading("Side Panel");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Blah blah…");
|
||||
});
|
||||
|
||||
// if let Some(game) = &mut self.game {
|
||||
// // todo colour picker
|
||||
// // todo tool picker
|
||||
// // todo collapsing panels for different things? buttons to launch browse windows?
|
||||
// }
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
// todo if game is none, add a "load project" window?
|
||||
|
||||
if let Some(game) = &mut self.game {
|
||||
egui::Window::new("palettes")
|
||||
.default_width(200.0)
|
||||
.collapsible(false)
|
||||
.show(ctx, |ui| {
|
||||
for palette in game.palettes.iter_mut() {
|
||||
ui.columns(2, |columns | {
|
||||
columns[0].label(&palette.name);
|
||||
|
||||
if columns[1].button("edit").clicked() {
|
||||
egui::Window::new(&palette.name)
|
||||
.default_width(200.0)
|
||||
.collapsible(true)
|
||||
.show(ctx, |ui| {
|
||||
for (i, colour) in palette.colours.iter().enumerate() {
|
||||
ui.columns(2, |row| {
|
||||
// todo edit each colour... this is broken
|
||||
row[0].color_edit_button_rgb(&mut [
|
||||
colour.red as f32,
|
||||
colour.green as f32,
|
||||
colour.blue as f32
|
||||
]);
|
||||
|
||||
if row[1].button("delete").clicked() {
|
||||
// can't alter palettes while iterating... what to do?
|
||||
// palette.colours.remove(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
// todo "add colour" button
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"peachy"
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// testing…
|
||||
let state = EditorState {
|
||||
game: Some(Game {
|
||||
config: Config {
|
||||
name: Some("example".into()),
|
||||
width: 16,
|
||||
height: 9,
|
||||
tick: 400,
|
||||
starting_room: None,
|
||||
version: (0, 1)
|
||||
},
|
||||
entities: vec![],
|
||||
images: vec![],
|
||||
palettes: vec![
|
||||
Palette { name: "example palette".into(), colours: vec![
|
||||
Colour { red: 79, green: 30, blue: 69 },
|
||||
Colour { red: 150, green: 48, blue: 87 },
|
||||
Colour { red: 215, green: 68, blue: 89 },
|
||||
Colour { red: 235, green: 112, blue: 96 },
|
||||
Colour { red: 255, green: 179, blue: 131 },
|
||||
Colour { red: 255, green: 255, blue: 255 },
|
||||
Colour { red: 127, green: 227, blue: 187 },
|
||||
Colour { red: 92, green: 187, blue: 196 },
|
||||
Colour { red: 69, green: 126, blue: 163 },
|
||||
Colour { red: 56, green: 66, blue: 118 },
|
||||
Colour { red: 50, green: 36, blue: 81 }
|
||||
]},
|
||||
],
|
||||
scenes: vec![],
|
||||
tiles: vec![],
|
||||
music: vec![]
|
||||
}),
|
||||
};
|
||||
|
||||
let native_options = eframe::NativeOptions::default();
|
||||
|
||||
eframe::run_native(Box::new(state), native_options);
|
||||
}
|
||||
@@ -1,22 +1,25 @@
|
||||
#[windows_subsystem = "windows"]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use log::error;
|
||||
use pixels::{Error, SurfaceTexture, PixelsBuilder};
|
||||
use pixels::wgpu::BackendBit;
|
||||
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
|
||||
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize, Size};
|
||||
use winit::event::{Event, VirtualKeyCode};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit_input_helper::WinitInputHelper;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use peachy::Game;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Image {
|
||||
pixels: [u8; 64]
|
||||
}
|
||||
|
||||
struct Game {
|
||||
width: usize,
|
||||
height: usize,
|
||||
struct State {
|
||||
game: Game,
|
||||
player_position: (u8, u8),
|
||||
player_avatar: Image,
|
||||
palette: [[u8; 4]; 4],
|
||||
@@ -24,7 +27,7 @@ struct Game {
|
||||
music: HashMap<String, rodio::Sink>,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
impl State {
|
||||
fn draw(&self, screen: &mut [u8]) {
|
||||
// clear screen
|
||||
for pixel in screen.chunks_exact_mut(4) {
|
||||
@@ -42,13 +45,13 @@ impl Game {
|
||||
screen[
|
||||
(
|
||||
// player vertical offset (number of lines above)
|
||||
(player_y as usize * 8 * (8 * self.width as usize))
|
||||
(player_y as usize * 8 * (8 * self.game.config.width as usize))
|
||||
+
|
||||
// player horizontal offset; number of pixels to the left
|
||||
(player_x as usize * 8)
|
||||
+
|
||||
// tile vertical offset; number of lines within tile
|
||||
(tile_y as usize * (8 * self.width as usize))
|
||||
(tile_y as usize * (8 * self.game.config.width as usize))
|
||||
+
|
||||
(tile_x as usize) // tile horizontal offset
|
||||
)
|
||||
@@ -68,9 +71,11 @@ impl Game {
|
||||
fn main() -> Result<(), Error> {
|
||||
env_logger::init();
|
||||
|
||||
let mut game = Game {
|
||||
width: 16,
|
||||
height: 9,
|
||||
let path = PathBuf::from("src/test-resources/basic");
|
||||
let game = peachy::Game::from_dir(path).unwrap();
|
||||
|
||||
let mut state = State {
|
||||
game,
|
||||
player_position: (8, 4),
|
||||
player_avatar: Image { pixels: [
|
||||
0,0,0,2,2,0,0,0,
|
||||
@@ -97,48 +102,50 @@ fn main() -> Result<(), Error> {
|
||||
|
||||
let (window, p_width, p_height, mut _hidpi_factor) = create_window(
|
||||
"pixels test",
|
||||
(game.width * 8) as f64,
|
||||
(game.height * 8) as f64,
|
||||
(state.game.config.width * 8) as f64,
|
||||
(state.game.config.height * 8) as f64,
|
||||
&event_loop
|
||||
);
|
||||
|
||||
let surface_texture = SurfaceTexture::new(p_width, p_height, &window);
|
||||
|
||||
let mut pixels = PixelsBuilder::new(
|
||||
(game.width * 8) as u32, (game.height * 8) as u32, surface_texture
|
||||
(state.game.config.width * 8) as u32,
|
||||
(state.game.config.height * 8) as u32,
|
||||
surface_texture
|
||||
)
|
||||
.wgpu_backend(BackendBit::GL | BackendBit::PRIMARY)
|
||||
.enable_vsync(false)
|
||||
.build()?;
|
||||
|
||||
let device = rodio::default_output_device().unwrap();
|
||||
// let device = rodio::default_output_device().unwrap();
|
||||
//
|
||||
// let source = rodio_xm::XMSource::from_bytes(
|
||||
// include_bytes!("../ninety degrees.xm")
|
||||
// );
|
||||
//
|
||||
// let sink = rodio::Sink::new(&device);
|
||||
// sink.append(source);
|
||||
// sink.pause();
|
||||
//
|
||||
// game.music.insert(":ninety degrees".into(), sink);
|
||||
//
|
||||
// let source = rodio_xm::XMSource::from_bytes(
|
||||
// include_bytes!("../orn_keygentheme2001.xm")
|
||||
// );
|
||||
//
|
||||
// let sink = rodio::Sink::new(&device);
|
||||
// sink.append(source);
|
||||
// sink.pause();
|
||||
//
|
||||
// game.music.insert("orn_keygentheme2001".into(), sink);
|
||||
|
||||
let source = rodio_xm::XMSource::from_bytes(
|
||||
include_bytes!("../ninety degrees.xm")
|
||||
);
|
||||
|
||||
let sink = rodio::Sink::new(&device);
|
||||
sink.append(source);
|
||||
sink.pause();
|
||||
|
||||
game.music.insert(":ninety degrees".into(), sink);
|
||||
|
||||
let source = rodio_xm::XMSource::from_bytes(
|
||||
include_bytes!("../orn_keygentheme2001.xm")
|
||||
);
|
||||
|
||||
let sink = rodio::Sink::new(&device);
|
||||
sink.append(source);
|
||||
sink.pause();
|
||||
|
||||
game.music.insert("orn_keygentheme2001".into(), sink);
|
||||
|
||||
game.current_music = None;
|
||||
state.current_music = None;
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
// The one and only event that winit_input_helper doesn't have for us...
|
||||
if let Event::RedrawRequested(_) = event {
|
||||
game.draw(pixels.get_frame());
|
||||
state.draw(pixels.get_frame());
|
||||
|
||||
if pixels
|
||||
.render()
|
||||
@@ -161,49 +168,65 @@ fn main() -> Result<(), Error> {
|
||||
|
||||
if input.key_pressed(VirtualKeyCode::M) {
|
||||
// pause the current tune
|
||||
if game.current_music.is_some() {
|
||||
game.music.get(game.current_music.as_ref().unwrap()).unwrap().pause();
|
||||
if state.current_music.is_some() {
|
||||
state.music.get(state.current_music.as_ref().unwrap()).unwrap().pause();
|
||||
}
|
||||
|
||||
if game.current_music.is_none() || game.current_music.as_ref().unwrap() == "orn_keygentheme2001" {
|
||||
if state.current_music.is_none() || state.current_music.as_ref().unwrap() == "orn_keygentheme2001" {
|
||||
// play the first tune
|
||||
game.current_music = Some(":ninety degrees".into());
|
||||
game.music.get(game.current_music.as_ref().unwrap()).unwrap().play();
|
||||
state.current_music = Some(":ninety degrees".into());
|
||||
state.music.get(state.current_music.as_ref().unwrap()).unwrap().play();
|
||||
} else {
|
||||
// play the second tune
|
||||
game.current_music = Some("orn_keygentheme2001".into());
|
||||
game.music.get(game.current_music.as_ref().unwrap()).unwrap().play();
|
||||
state.current_music = Some("orn_keygentheme2001".into());
|
||||
state.music.get(state.current_music.as_ref().unwrap()).unwrap().play();
|
||||
}
|
||||
}
|
||||
|
||||
if input.key_pressed(VirtualKeyCode::Left) {
|
||||
let (x, y) = game.player_position;
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Left)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::W)
|
||||
{
|
||||
let (x, y) = state.player_position;
|
||||
if x > 0 {
|
||||
game.player_position = (x - 1, y);
|
||||
state.player_position = (x - 1, y);
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
if input.key_pressed(VirtualKeyCode::Right) {
|
||||
let (x, y) = game.player_position;
|
||||
if x < game.width as u8 - 1 {
|
||||
game.player_position = (x + 1, y);
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Right)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::D)
|
||||
{
|
||||
let (x, y) = state.player_position;
|
||||
if x < state.game.config.width as u8 - 1 {
|
||||
state.player_position = (x + 1, y);
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
if input.key_pressed(VirtualKeyCode::Up) {
|
||||
let (x, y) = game.player_position;
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Up)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::W)
|
||||
{
|
||||
let (x, y) = state.player_position;
|
||||
if y > 0 {
|
||||
game.player_position = (x, y - 1);
|
||||
state.player_position = (x, y - 1);
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
if input.key_pressed(VirtualKeyCode::Down) {
|
||||
let (x, y) = game.player_position;
|
||||
if y < game.height as u8 - 1 {
|
||||
game.player_position = (x, y + 1);
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Down)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::S)
|
||||
{
|
||||
let (x, y) = state.player_position;
|
||||
if y < state.game.config.height as u8 - 1 {
|
||||
state.player_position = (x, y + 1);
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
@@ -229,6 +252,7 @@ fn main() -> Result<(), Error> {
|
||||
fn window_builder(title: &str, event_loop: &EventLoop<()>) -> winit::window::Window {
|
||||
winit::window::WindowBuilder::new()
|
||||
.with_visible(false)
|
||||
// .with_resizable(false)
|
||||
.with_title(title).build(&event_loop).unwrap()
|
||||
}
|
||||
|
||||
@@ -239,6 +263,7 @@ fn window_builder(title: &str, event_loop: &EventLoop<()>) -> winit::window::Win
|
||||
winit::window::WindowBuilder::new()
|
||||
.with_drag_and_drop(false)
|
||||
.with_visible(false)
|
||||
// .with_resizable(false)
|
||||
.with_title(title).build(&event_loop).unwrap()
|
||||
}
|
||||
|
||||
@@ -273,21 +298,21 @@ fn create_window(
|
||||
|
||||
let scale = (monitor_height / height * 2.0 / 3.0).round().max(1.0);
|
||||
|
||||
// Resize, center, and display the window
|
||||
let min_size: winit::dpi::LogicalSize<f64> =
|
||||
PhysicalSize::new(width, height).to_logical(hidpi_factor);
|
||||
// Resize, centre, and display the window
|
||||
// let min_size: winit::dpi::LogicalSize<f64> =
|
||||
// PhysicalSize::new(width, height).to_logical(hidpi_factor);
|
||||
|
||||
let default_size =
|
||||
LogicalSize::new(width * scale, height * scale);
|
||||
|
||||
let center = LogicalPosition::new(
|
||||
let centre = LogicalPosition::new(
|
||||
(monitor_width - width * scale) / 2.0,
|
||||
(monitor_height - height * scale) / 2.0,
|
||||
);
|
||||
|
||||
window.set_inner_size(default_size);
|
||||
window.set_min_inner_size(Some(min_size));
|
||||
window.set_outer_position(center);
|
||||
// window.set_min_inner_size(Some(min_size));
|
||||
window.set_outer_position(centre);
|
||||
window.set_visible(true);
|
||||
|
||||
let size = default_size.to_physical::<f64>(hidpi_factor);
|
||||
|
||||
88
src/bin/player2.rs
Normal file
88
src/bin/player2.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use raylib::prelude::*;
|
||||
use raylib::consts::KeyboardKey;
|
||||
use peachy::Colour;
|
||||
|
||||
// todo state
|
||||
|
||||
fn main() {
|
||||
// todo load game
|
||||
let game = peachy::mock::game::bitsy();
|
||||
|
||||
let (mut rl, thread) = raylib::init()
|
||||
.size((game.config.width * 4) as i32, (game.config.height * 4) as i32)
|
||||
.title("peachy")
|
||||
.build();
|
||||
|
||||
rl.set_target_fps(30); // appropriate?
|
||||
|
||||
let key_up: KeyboardKey = raylib::core::input::key_from_i32(87).unwrap();
|
||||
let key_left: KeyboardKey = raylib::core::input::key_from_i32(65).unwrap();
|
||||
let key_down: KeyboardKey = raylib::core::input::key_from_i32(83).unwrap();
|
||||
let key_right: KeyboardKey = raylib::core::input::key_from_i32(68).unwrap();
|
||||
|
||||
const SIZE: i32 = 32;
|
||||
|
||||
let mut x = SIZE;
|
||||
let mut y = SIZE;
|
||||
|
||||
let palette = game.palettes.get(0).unwrap();
|
||||
|
||||
let avatars = game.get_entities_by_tag(&"avatar".to_string());
|
||||
let avatar = avatars.get(0).unwrap();
|
||||
let image = game.get_image_by_name(&avatar.image).unwrap().clone().into_image(palette);
|
||||
|
||||
// todo how do I create a texture without a file?
|
||||
let mut texture = rl.load_texture(
|
||||
&thread, "src/test-resources/images/avatar.png"
|
||||
).unwrap();
|
||||
|
||||
texture.update_texture(image.as_bytes());
|
||||
|
||||
// let font = rl.load_font(&thread, "src/FuturaStd-Light.otf").unwrap();
|
||||
|
||||
let mut audio = audio::RaylibAudio::init_audio_device();
|
||||
|
||||
let mut music = raylib::audio::Music::load_music_stream(
|
||||
&thread, "src/test-resources/music/another-night.xm"
|
||||
).unwrap();
|
||||
|
||||
audio.play_music_stream(&mut music);
|
||||
|
||||
println!("{}", rl.window_should_close());
|
||||
|
||||
while !rl.window_should_close() {
|
||||
if rl.is_key_pressed(key_up) {
|
||||
y -= SIZE;
|
||||
} else if rl.is_key_pressed(key_left) {
|
||||
x -= SIZE;
|
||||
} else if rl.is_key_pressed(key_down) {
|
||||
y += SIZE;
|
||||
} else if rl.is_key_pressed(key_right) {
|
||||
x += SIZE;
|
||||
}
|
||||
|
||||
audio.update_music_stream(&mut music);
|
||||
|
||||
let mut d = rl.begin_drawing(&thread);
|
||||
|
||||
// d.clear_background(palette.get_colour_raylib(&0));
|
||||
d.clear_background(Color::WHITE);
|
||||
|
||||
d.draw_texture_ex(
|
||||
&texture,
|
||||
raylib::core::math::Vector2 { x: x as f32, y: y as f32 },
|
||||
0.0,
|
||||
4.0,
|
||||
Color::WHITE
|
||||
);
|
||||
|
||||
// d.draw_text_ex(
|
||||
// &font,
|
||||
// "hello",
|
||||
// raylib::core::math::Vector2 { x: 64.0, y: 64.0 },
|
||||
// 32.0,
|
||||
// 4.0,
|
||||
// Color::WHITE
|
||||
// );
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::fmt;
|
||||
|
||||
use image;
|
||||
use image::Rgba;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
@@ -37,6 +39,18 @@ impl Into<Vec<u8>> for Colour {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<image::Rgba<u8>> for Colour {
|
||||
fn into(self) -> Rgba<u8> {
|
||||
Rgba::from([self.red, self.green, self.blue, 255])
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[u8; 4]> for Colour {
|
||||
fn into(self) -> [u8; 4] {
|
||||
[self.red, self.green, self.blue, 255]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::Colour;
|
||||
|
||||
@@ -3,15 +3,15 @@ use serde_derive::{Serialize, Deserialize};
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
/// used in the window title bar
|
||||
name: Option<String>,
|
||||
width: u8,
|
||||
height: u8,
|
||||
pub name: Option<String>,
|
||||
pub width: u8,
|
||||
pub height: u8,
|
||||
/// animation rate in milliseconds
|
||||
tick: u64,
|
||||
pub tick: u64,
|
||||
/// if this is not specified, the game will pick the first room it finds
|
||||
starting_room: Option<String>,
|
||||
pub starting_room: Option<String>,
|
||||
/// major / minor
|
||||
version: (u8, u8),
|
||||
pub version: (u8, u8),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -4,9 +4,9 @@ use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Entity {
|
||||
name: String,
|
||||
image: String,
|
||||
tags: Vec<String>,
|
||||
pub name: String,
|
||||
pub image: String,
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
impl Entity {
|
||||
|
||||
26
src/image.rs
26
src/image.rs
@@ -1,8 +1,10 @@
|
||||
use std::path::PathBuf;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use std::fs::read_to_string;
|
||||
use image::{DynamicImage, ImageBuffer};
|
||||
use crate::Palette;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Image {
|
||||
pub name: String,
|
||||
/// colour indices - todo convert to [u8; 64]?
|
||||
@@ -21,6 +23,16 @@ impl Image {
|
||||
|
||||
Self { name, pixels }
|
||||
}
|
||||
|
||||
pub fn into_image(self, palette: &Palette) -> DynamicImage {
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
|
||||
for pixel in self.pixels {
|
||||
buffer.append(&mut palette.get_colour_rgba8(&pixel));
|
||||
}
|
||||
|
||||
DynamicImage::ImageRgba8(ImageBuffer::from_raw(8, 8, buffer).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -35,4 +47,16 @@ mod test {
|
||||
let expected = crate::mock::image::avatar();
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_to_dynamic_image() {
|
||||
let palette = &crate::mock::palette::default();
|
||||
let output = crate::mock::image::avatar().into_image(palette);
|
||||
|
||||
let expected = image::io::Reader::open(
|
||||
"src/test-resources/images/avatar.png"
|
||||
).unwrap().decode().unwrap();
|
||||
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
}
|
||||
|
||||
181
src/lib.rs
181
src/lib.rs
@@ -5,7 +5,7 @@ mod colour;
|
||||
mod config;
|
||||
mod entity;
|
||||
mod image;
|
||||
mod mock;
|
||||
pub mod mock;
|
||||
mod music;
|
||||
mod palette;
|
||||
mod scene;
|
||||
@@ -26,13 +26,11 @@ pub struct Position {
|
||||
y: u8,
|
||||
}
|
||||
|
||||
// #[derive(Serialize, Deserialize)]
|
||||
// pub struct Thing {
|
||||
// name: Option<String>,
|
||||
// /// image name
|
||||
// image: String,
|
||||
// }
|
||||
//
|
||||
impl Position {
|
||||
pub fn to_index(&self, width: u8) -> u16 {
|
||||
(self.y * width + self.x) as u16
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(Serialize, Deserialize)]
|
||||
// pub enum DataType {
|
||||
@@ -107,28 +105,47 @@ pub struct Position {
|
||||
// }
|
||||
|
||||
pub struct Game {
|
||||
config: Config,
|
||||
palettes: Vec<Palette>,
|
||||
images: Vec<Image>,
|
||||
tiles: Vec<Tile>,
|
||||
entities: Vec<Entity>,
|
||||
// variables: Vec<Variable>,
|
||||
// triggers: HashMap<String, ScriptCollection>,
|
||||
music: Vec<Music>,
|
||||
pub config: Config,
|
||||
pub entities: Vec<Entity>,
|
||||
pub images: Vec<Image>,
|
||||
pub palettes: Vec<Palette>,
|
||||
pub scenes: Vec<Scene>,
|
||||
pub tiles: Vec<Tile>,
|
||||
// pub variables: Vec<Variable>,
|
||||
// pub triggers: HashMap<String, ScriptCollection>,
|
||||
pub music: Vec<Music>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GameParseError;
|
||||
|
||||
impl Game {
|
||||
pub fn from(path: String) -> Result<Game, GameParseError> {
|
||||
let path = PathBuf::from(path);
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
config: Config {
|
||||
name: None,
|
||||
width: 16,
|
||||
height: 9,
|
||||
tick: 400,
|
||||
starting_room: None,
|
||||
version: (0, 1)
|
||||
},
|
||||
entities: vec![],
|
||||
images: vec![],
|
||||
palettes: vec![],
|
||||
scenes: vec![],
|
||||
tiles: vec![],
|
||||
music: vec![]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_dir(path: PathBuf) -> Result<Game, GameParseError> {
|
||||
let mut images = Vec::new();
|
||||
let mut tiles = Vec::new();
|
||||
let mut entities = Vec::new();
|
||||
let mut music = Vec::new();
|
||||
let mut palettes = Vec::new();
|
||||
let mut scenes = Vec::new();
|
||||
|
||||
let mut music_dir = path.clone();
|
||||
music_dir.push("music");
|
||||
@@ -139,7 +156,6 @@ impl Game {
|
||||
for file in music_files.unwrap() {
|
||||
let file = file.unwrap();
|
||||
music.push(Music::from_file(file.path()));
|
||||
println!("music found: {:?}", file.file_name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,11 +168,10 @@ impl Game {
|
||||
for file in palette_files {
|
||||
let file = file.unwrap();
|
||||
palettes.push(Palette::from_file(file.path()));
|
||||
println!("palette found: {:?}", file.file_name());
|
||||
}
|
||||
|
||||
let mut images_dir = path.clone();
|
||||
images_dir.push("palettes");
|
||||
images_dir.push("images");
|
||||
|
||||
let image_files = images_dir.read_dir()
|
||||
.expect("couldn't read image dir");
|
||||
@@ -164,11 +179,10 @@ impl Game {
|
||||
for file in image_files {
|
||||
let file = file.unwrap();
|
||||
images.push(Image::from_file(file.path()));
|
||||
println!("image found: {:?}", file.file_name());
|
||||
}
|
||||
|
||||
let mut tiles_dir = path.clone();
|
||||
tiles_dir.push("palettes");
|
||||
tiles_dir.push("tiles");
|
||||
|
||||
let tiles_files = tiles_dir.read_dir()
|
||||
.expect("couldn't read tile dir");
|
||||
@@ -176,11 +190,10 @@ impl Game {
|
||||
for file in tiles_files {
|
||||
let file = file.unwrap();
|
||||
tiles.push(Tile::from_file(file.path()));
|
||||
println!("tile found: {:?}", file.file_name());
|
||||
}
|
||||
|
||||
let mut entities_dir = path.clone();
|
||||
entities_dir.push("palettes");
|
||||
entities_dir.push("entities");
|
||||
|
||||
let entities_files = entities_dir.read_dir()
|
||||
.expect("couldn't read tile dir");
|
||||
@@ -188,7 +201,17 @@ impl Game {
|
||||
for file in entities_files {
|
||||
let file = file.unwrap();
|
||||
entities.push(Entity::from_file(file.path()));
|
||||
println!("entity found: {:?}", file.file_name());
|
||||
}
|
||||
|
||||
let mut scenes_dir = path.clone();
|
||||
scenes_dir.push("scenes");
|
||||
|
||||
let scenes_files = scenes_dir.read_dir()
|
||||
.expect("couldn't read scene dir");
|
||||
|
||||
for file in scenes_files {
|
||||
let file = file.unwrap();
|
||||
scenes.push(Scene::from_file(file.path()));
|
||||
}
|
||||
|
||||
let mut game_config = path.clone();
|
||||
@@ -198,6 +221,110 @@ impl Game {
|
||||
let config: Config = toml::from_str(&config)
|
||||
.expect("Couldn't parse game config");
|
||||
|
||||
Ok(Game { config, images, tiles, palettes, music, entities })
|
||||
Ok(Game { config, images, tiles, palettes, music, entities, scenes })
|
||||
}
|
||||
|
||||
pub fn get_image_by_name(&self, name: &String) -> Option<&Image> {
|
||||
for image in self.images.iter() {
|
||||
if &image.name == name {
|
||||
return Some(&image);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_entities_by_tag(&self, tag: &String) -> Vec<&Entity> {
|
||||
let mut entities = Vec::new();
|
||||
|
||||
for entity in self.entities.iter() {
|
||||
if entity.tags.contains(tag) {
|
||||
entities.push(entity);
|
||||
}
|
||||
}
|
||||
|
||||
entities
|
||||
}
|
||||
|
||||
// todo Result<&Entity>?
|
||||
pub fn get_entity_by_name(&self, name: String) -> Option<&Entity> {
|
||||
for entity in self.entities.iter() {
|
||||
if entity.name == name {
|
||||
return Some(entity);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
// todo Result<&Music>?
|
||||
pub fn get_music_by_name(&self, name: String) -> Option<&Music> {
|
||||
for music in self.music.iter() {
|
||||
if music.name == name {
|
||||
return Some(music);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
// todo Result<&Palette>?
|
||||
pub fn find_palette(&mut self, name: &str) -> Option<&mut Palette> {
|
||||
for palette in self.palettes.iter_mut() {
|
||||
if palette.name == name {
|
||||
return Some(palette);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
// todo Result<&Tile>?
|
||||
pub fn get_tile_by_name(&self, name: String) -> Option<&Tile> {
|
||||
for tile in self.tiles.iter() {
|
||||
if tile.name == name {
|
||||
return Some(tile);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_scene_by_name(&mut self, name: String) -> Option<&mut Scene> {
|
||||
for scene in self.scenes.iter_mut() {
|
||||
if scene.name == name {
|
||||
return Some(scene);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn remove_entity(&mut self, scene_name: String, position: Position) {
|
||||
let width = self.config.width.clone();
|
||||
self.get_scene_by_name(scene_name).unwrap()
|
||||
.foreground[position.to_index(width) as usize] = None;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{Position, Game};
|
||||
|
||||
#[test]
|
||||
fn position_to_index() {
|
||||
assert_eq!(Position { x: 1, y: 5 }.to_index(8), 41);
|
||||
assert_eq!(Position { x: 0, y: 0 }.to_index(8), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_entity() {
|
||||
let mut game = Game::new();
|
||||
|
||||
game.scenes.push(crate::mock::scenes::zero());
|
||||
|
||||
game.remove_entity("zero".into(), Position { x: 1, y: 1 });
|
||||
|
||||
assert_eq!(game.scenes[0].foreground[9], None);
|
||||
}
|
||||
}
|
||||
|
||||
85
src/mock.rs
85
src/mock.rs
@@ -1,7 +1,7 @@
|
||||
pub(crate) mod image {
|
||||
pub mod image {
|
||||
use crate::image::Image;
|
||||
|
||||
pub fn bg() -> Image {
|
||||
pub fn _bg() -> Image {
|
||||
Image {
|
||||
name: "bg".to_string(),
|
||||
pixels: vec![
|
||||
@@ -17,7 +17,7 @@ pub(crate) mod image {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn block() -> Image {
|
||||
pub fn _block() -> Image {
|
||||
Image {
|
||||
name: "block".to_string(),
|
||||
pixels: vec![
|
||||
@@ -49,7 +49,7 @@ pub(crate) mod image {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cat() -> Image {
|
||||
pub fn _cat() -> Image {
|
||||
Image {
|
||||
name: "cat".to_string(),
|
||||
pixels: vec![
|
||||
@@ -66,22 +66,21 @@ pub(crate) mod image {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod palette {
|
||||
pub mod palette {
|
||||
use crate::{Palette, Colour};
|
||||
|
||||
pub(crate) fn default() -> Palette {
|
||||
Palette {
|
||||
name: "blueprint".to_string(),
|
||||
colours: vec![
|
||||
Colour { red: 0, green: 0, blue: 0 },
|
||||
Colour { red: 0, green: 81, blue: 104 },
|
||||
Colour { red: 118, green: 159, blue: 155 },
|
||||
Colour { red: 155, green: 155, blue: 155 },
|
||||
Colour { red: 0, green: 82, blue: 204 },
|
||||
Colour { red: 128, green: 159, blue: 255 },
|
||||
Colour { red: 255, green: 255, blue: 255 },
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn soup11() -> Palette {
|
||||
pub fn soup11() -> Palette {
|
||||
Palette {
|
||||
name: "soup11".into(),
|
||||
colours: vec![
|
||||
@@ -101,10 +100,10 @@ pub(crate) mod palette {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod scenes {
|
||||
pub mod scenes {
|
||||
use crate::Scene;
|
||||
|
||||
pub(crate) fn zero() -> Scene {
|
||||
pub fn zero() -> Scene {
|
||||
Scene {
|
||||
name: "zero".into(),
|
||||
background: vec![
|
||||
@@ -146,3 +145,65 @@ pub(crate) mod scenes {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod entities {
|
||||
use crate::Entity;
|
||||
|
||||
pub fn bitsy_avatar() -> Entity {
|
||||
Entity {
|
||||
name: "".to_string(),
|
||||
image: "avatar".to_string(),
|
||||
tags: vec!["player".into()]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bitsy_cat() -> Entity {
|
||||
Entity {
|
||||
name: "cat".to_string(),
|
||||
image: "cat".to_string(),
|
||||
tags: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod tiles {
|
||||
use crate::Tile;
|
||||
|
||||
pub fn bitsy_block() -> Tile {
|
||||
Tile {
|
||||
name: "block".into(),
|
||||
images: vec!["block".into()],
|
||||
wall: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod game {
|
||||
use crate::{Config, Game};
|
||||
|
||||
pub fn bitsy() -> Game {
|
||||
Game {
|
||||
config: Config {
|
||||
name: Some("Write your game's title here".into()),
|
||||
width: 16,
|
||||
height: 16,
|
||||
tick: 400,
|
||||
starting_room: None,
|
||||
version: (0, 1)
|
||||
},
|
||||
entities: vec![
|
||||
crate::mock::entities::bitsy_avatar(),
|
||||
crate::mock::entities::bitsy_cat(),
|
||||
],
|
||||
images: vec![],
|
||||
palettes: vec![],
|
||||
scenes: vec![
|
||||
crate::mock::scenes::zero(),
|
||||
],
|
||||
tiles: vec![
|
||||
crate::mock::tiles::bitsy_block(),
|
||||
],
|
||||
music: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,24 @@ pub struct Palette {
|
||||
}
|
||||
|
||||
impl Palette {
|
||||
/// todo result
|
||||
/// if trying to get an out-of-bounds index, colours will wrap around
|
||||
/// so if palette has 8 colours (0-7) and index is 8, will return 0
|
||||
pub fn get_colour(&self, index: &u8) -> Option<&Colour> {
|
||||
self.colours.get((index % self.colours.len() as u8) as usize)
|
||||
}
|
||||
|
||||
/// colour 0 is transparent
|
||||
pub fn get_colour_rgba8(&self, index: &u8) -> Vec<u8> {
|
||||
match index {
|
||||
0 => vec![0,0,0,0],
|
||||
_ => {
|
||||
let colour = self.get_colour(index).unwrap();
|
||||
vec![colour.red, colour.green, colour.blue, 255]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// todo Result<Palette>
|
||||
pub fn from_file(path: PathBuf) -> Self {
|
||||
match path.extension().unwrap().to_str().unwrap() {
|
||||
"gpl" => Self::from_gpl(path),
|
||||
@@ -84,8 +101,11 @@ impl Palette {
|
||||
)
|
||||
}).collect();
|
||||
|
||||
// todo re-insert original comments
|
||||
format!("GIMP Palette\r\n{}\r\n", colours.join("\r\n"))
|
||||
// todo fix palette description? does it matter?
|
||||
format!(
|
||||
"GIMP Palette\r\n#Palette Name: {}\r\n#Colors: {}\r\n{}\r\n",
|
||||
self.name, colours.len(), colours.join("\r\n")
|
||||
)
|
||||
}
|
||||
|
||||
/// Paint.net .txt format
|
||||
@@ -157,6 +177,7 @@ impl Palette {
|
||||
Self { name, colours }
|
||||
}
|
||||
|
||||
/// todo maybe this should be Into<DynamicImage>
|
||||
pub fn to_png(&self) -> DynamicImage {
|
||||
let mut image = DynamicImage::new_rgb8(
|
||||
self.colours.len() as u32, 1 as u32
|
||||
@@ -174,29 +195,13 @@ impl Palette {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::path::PathBuf;
|
||||
use crate::{Colour, Palette};
|
||||
use crate::Palette;
|
||||
|
||||
#[test]
|
||||
fn palette_from_jasc() {
|
||||
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.pal");
|
||||
let path = PathBuf::from("src/test-resources/palettes/soup11.pal");
|
||||
let output = Palette::from_jasc(path);
|
||||
|
||||
let expected = Palette {
|
||||
name: "soup11".into(),
|
||||
colours: vec![
|
||||
Colour { red: 79, green: 30, blue: 69 },
|
||||
Colour { red: 150, green: 48, blue: 87 },
|
||||
Colour { red: 215, green: 68, blue: 89 },
|
||||
Colour { red: 235, green: 112, blue: 96 },
|
||||
Colour { red: 255, green: 179, blue: 131 },
|
||||
Colour { red: 255, green: 255, blue: 255 },
|
||||
Colour { red: 127, green: 227, blue: 187 },
|
||||
Colour { red: 92, green: 187, blue: 196 },
|
||||
Colour { red: 69, green: 126, blue: 163 },
|
||||
Colour { red: 56, green: 66, blue: 118 },
|
||||
Colour { red: 50, green: 36, blue: 81 }
|
||||
]
|
||||
};
|
||||
let expected = crate::mock::palette::soup11();
|
||||
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
@@ -210,7 +215,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn palette_from_gpl() {
|
||||
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.gpl");
|
||||
let path = PathBuf::from("src/test-resources/palettes/soup11.gpl");
|
||||
let output = Palette::from_gpl(path);
|
||||
let expected = crate::mock::palette::soup11();
|
||||
|
||||
@@ -227,7 +232,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn palette_from_txt() {
|
||||
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.txt");
|
||||
let path = PathBuf::from("src/test-resources/palettes/soup11.txt");
|
||||
let output = Palette::from_txt(path);
|
||||
let expected = crate::mock::palette::soup11();
|
||||
assert_eq!(output, expected);
|
||||
@@ -243,7 +248,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn palette_from_hex() {
|
||||
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.hex");
|
||||
let path = PathBuf::from("src/test-resources/palettes/soup11.hex");
|
||||
let output = Palette::from_hex(path);
|
||||
let expected = crate::mock::palette::soup11();
|
||||
assert_eq!(output, expected);
|
||||
@@ -258,7 +263,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn palette_from_png() {
|
||||
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.png");
|
||||
let path = PathBuf::from("src/test-resources/palettes/soup11.png");
|
||||
let output = Palette::from_png(path);
|
||||
let expected = crate::mock::palette::soup11();
|
||||
assert_eq!(output, expected);
|
||||
@@ -269,7 +274,7 @@ mod test {
|
||||
use image::io::Reader as ImageReader;
|
||||
|
||||
let output = crate::mock::palette::soup11().to_png();
|
||||
let path = PathBuf::from("src/test-resources/basic/palettes/soup11.png");
|
||||
let path = PathBuf::from("src/test-resources/palettes/soup11.png");
|
||||
let expected = ImageReader::open(path).unwrap().decode().unwrap();
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::fs::read_to_string;
|
||||
use std::path::PathBuf;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use crate::Position;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Scene {
|
||||
@@ -36,6 +37,10 @@ impl Scene {
|
||||
|
||||
Self { name, background, foreground }
|
||||
}
|
||||
|
||||
pub fn set_tile(_position: Position, _new: String) {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
/// scene name is derived from the filename,
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
image = "avatar"
|
||||
tags = []
|
||||
tags = ["player"]
|
||||
|
||||
2
src/test-resources/basic/entities/cat.toml
Normal file
2
src/test-resources/basic/entities/cat.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
image = "cat"
|
||||
tags = []
|
||||
2
src/test-resources/basic/entities/tea.toml
Normal file
2
src/test-resources/basic/entities/tea.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
image = "tea"
|
||||
tags = []
|
||||
8
src/test-resources/basic/images/tea.txt
Normal file
8
src/test-resources/basic/images/tea.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
00000000
|
||||
00000000
|
||||
00000000
|
||||
00111100
|
||||
01100100
|
||||
00100100
|
||||
00011000
|
||||
00000000
|
||||
BIN
src/test-resources/images/avatar.png
Normal file
BIN
src/test-resources/images/avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 126 B |
BIN
src/test-resources/music/another-night.xm
Normal file
BIN
src/test-resources/music/another-night.xm
Normal file
Binary file not shown.
Reference in New Issue
Block a user