First commit

This commit is contained in:
JP Stringham
2026-02-03 20:11:46 -05:00
commit f8ac1528dc
9 changed files with 7544 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.DS_Store
/target

4
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
}

5698
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

16
Cargo.toml Normal file
View File

@@ -0,0 +1,16 @@
[package]
name = "parsnip_plucker"
version = "0.1.0"
edition = "2024"
[dependencies]
bevy = { version = "0.18.0", features = ["dynamic_linking"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3

BIN
assets/parsnip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

1655
assets/test.ldtk Normal file

File diff suppressed because one or more lines are too long

BIN
assets/tilemap.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

62
src/ldtk/mod.rs Normal file
View File

@@ -0,0 +1,62 @@
use bevy::math::UVec2;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Project {
#[serde(alias = "bgColor")]
pub bg_color: String,
pub levels: Vec<Level>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Level {
pub uid: u32,
pub identifier: String,
#[serde(alias = "pxHei")]
pub px_height: u32,
#[serde(alias = "pxWid")]
pub px_width: u32,
#[serde(alias = "layerInstances")]
pub layer_instances: Vec<LayerInstance>,
#[serde(alias = "fieldInstances")]
pub field_instances: Vec<FieldInstance>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayerInstance {
#[serde(alias = "__type")]
pub ty: LayerType,
#[serde(alias = "__identifier")]
pub identifier: String,
#[serde(alias = "__cHei")]
pub height: u32,
#[serde(alias = "__cWid")]
pub width: u32,
#[serde(alias = "gridTiles")]
pub grid_tiles: Vec<Tile>,
#[serde(alias = "intGridCsv")]
pub int_grid_tiles: Vec<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldInstance {}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tile {
#[serde(alias = "t")]
pub ty: u32,
#[serde(alias = "a")]
pub alpha: f32,
#[serde(alias = "f")]
pub flip: u8,
#[serde(alias = "px")]
pub px_coords: UVec2,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum LayerType {
IntGrid,
Entities,
Tiles,
AutoLayer,
}

106
src/main.rs Normal file
View File

@@ -0,0 +1,106 @@
mod ldtk;
use bevy::{image::Image, prelude::*};
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, States)]
enum AppState {
#[default]
Preload,
Setup,
Main,
}
#[derive(Default, Resource)]
struct TilemapStuff {
img_handle: Option<Handle<Image>>,
img_id: Option<AssetId<Image>>,
}
fn main() {
let mut ldtk_proj: ldtk::Project =
serde_json::from_str(include_str!("../assets/test.ldtk")).unwrap();
println!("LDTK {ldtk_proj:?}");
return;
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.init_state::<AppState>()
.insert_resource(TilemapStuff::default())
.add_systems(Startup, init)
.add_systems(Update, loadloop.run_if(in_state(AppState::Preload)))
.add_systems(Update, gameloop.run_if(in_state(AppState::Main)));
app.run();
}
fn init(
assets: Res<AssetServer>,
mut commands: Commands,
mut state: ResMut<NextState<AppState>>,
mut tmap_stuff: ResMut<TilemapStuff>,
mut t_layouts: ResMut<Assets<TextureAtlasLayout>>,
) {
println!("Hello Bevy!");
let sprite = assets.load("tilemap.png");
tmap_stuff.img_id = Some(sprite.id());
tmap_stuff.img_handle = Some(sprite.clone());
let t_layout = TextureAtlasLayout::from_grid(uvec2(16, 16), 12, 8, Some(uvec2(1, 1)), None);
let t_handle = t_layouts.add(t_layout);
for i in 0..18 {
let x = i as f32 * 20.;
commands.spawn((
Sprite::from_atlas_image(
sprite.clone(),
TextureAtlas {
layout: t_handle.clone(),
index: i,
},
),
Transform::from_xyz(x, 0., 0.),
));
}
let mut orth_proj = OrthographicProjection::default_2d();
orth_proj.scale = 0.25;
commands.spawn((Camera2d, Projection::Orthographic(orth_proj)));
state.set(AppState::Preload);
}
fn loadloop(
mut evts: MessageReader<AssetEvent<Image>>,
images: Res<Assets<Image>>,
tmap_stuff: Res<TilemapStuff>,
mut next_state: ResMut<NextState<AppState>>,
) {
if evts.is_empty() {
return;
}
for evt in evts.read() {
// println!("{evt:?}");
match evt {
AssetEvent::LoadedWithDependencies { id } => {
let Some(_img) = images.get(*id) else {
continue;
};
if tmap_stuff.img_id.as_ref().unwrap() == id {
println!("Loaded tmap");
next_state.set(AppState::Main);
}
}
_ => (),
}
}
}
fn gameloop() {}