Git Product home page Git Product logo

bevy_common_assets's Introduction

Hi there 👋

bevy_common_assets's People

Contributors

boylede avatar brandon-reinhart avatar eerii avatar jredow avatar neeeoo avatar niklasei avatar sardap avatar seldom-se avatar striezel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bevy_common_assets's Issues

Getting `AssetServer does not exist` when using this with bevy_asset_loader

I could not get it to work with bevy_asset_loader

Is there some example code I can look at to be sure I'm using it correctly?
error:

thread 'main' panicked at 'Requested resource bevy_asset::asset_server::AssetServer does not exist in the `World`. 
                Did you forget to add it using `app.insert_resource` / `app.init_resource`? 
                Resources are also implicitly added via `app.add_event`,
                and can be added by plugins.', /home/pinkponk/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_asset-0.8.1/src/assets.rs:324:43

Usage:

...
.with_collection::<WorldAssets>()
...
.add_plugin(JsonAssetPlugin::<WorldConfigJson>::new(&["json.world"]))
#[derive(serde::Deserialize, bevy::reflect::TypeUuid)]
#[uuid = "413be529-bfeb-41b3-9db0-4b8b38022c46"]
pub struct WorldConfigJson {
    plants: Vec<String>,
    spawns: Vec<SpawnsJson>,
}

#[derive(serde::Deserialize)]
pub struct SpawnsJson {
    species: String,
    nr_creatures: u32,
    radius: f32,
    age_factor: f32,
    world_pos_factor: [f32; 2],
}
pub fn configure_world(
    mut commands: Commands,
    world_assets: Res<WorldAssets>,
    mut world_config_jsons: ResMut<Assets<WorldConfigJson>>,
) {
...}

file:

{
    "plants": [
        "mushroom",
        "grass",
        "tree",
        "bush",
        "carrot"
    ],
    "spawns": [
        {
            "species": "fox",
            "nr_creatures": 3,
            "radius": 10.0,
            "age_factor": 0.5,
            "world_pos_factor": [
                0.1,
                0.1
            ]
        }
    ]
}

bevy_sprite should be should be behind a feature flag, not a hard dependency

I'm trying to optimize my cargo build times for my project, and a major slow down I've noticed for recompiles is bevy_sprite. I'm making a 3d project, and I'd like to be able to remove bevy_sprite, since I don't need it, but this crate makes it a hard dependency.

A '2d' feature flag would let people who use this crate and bevy_asset_loader to remove bevy_sprite, and speed up re-compiles for 3d projects.

Create AssetSaver implementations for each format.

Bevy now has AssetSaver. This allows a cross-platform way of saving assets by:

  1. Getting an AssetWriter from an AssetSource (from AssetServer)
  2. Calling AssetWriter::write to get an AsyncWrite object.
  3. Calling AssetSaver::save with that AsyncWrite object.

In the future this will likely be streamlined but for now we should support AssetSaver to support this "canonical" workflow.

no `AssetLoader` found for the following extension: yaml

bevy 1.12.1
Currently figuring out how to use this crate, i added the plugin like so:

        .add_plugins((
            DefaultPlugins, 
            YamlAssetPlugin::<World>::new(&["world.yml"])
        ))
#[derive(Deserialize, Asset, TypePath, Debug)]
struct World {
    name: String,
    width: u8,
    height: u8,
}


fn load_world(
    server: Res<AssetServer>,
    mut images: ResMut<Assets<Image>>,
    mut worlds: ResMut<Assets<World>>,
    mut commands: Commands
) {
    let handle: Handle<World> = server.load("world.yaml");
    
    if let Some(x) = worlds.get_mut(handle.id()) {
        println!("{:?}", x);
    } else {
        println!("Did not find!")
    }
}

This comes up with "did not find!" and the error found in the title: ERROR bevy_asset::server: no 'AssetLoader' found for the following extension: yaml This error also occurs when changing everything to 'yml'.
The yaml file is very simple and as far as i know, this should work?

name: Cloob
width: 64
height: 32

What is going wrong?
Thanks in advance!

Edit: The example contains wrong code, worlds.get_mut(handle.id()) should be in a Update script. It still gives the error regardless.

Support CSV

It would be great if there was added support for CSV files, the csv crate already has support for serde!

Asset type for arbitrary json/toml/etc documents

TL;DR

Could this repository include a common asset type and loader for loading generic serde_json::Value, toml_edit::Document, etc. types from files with the generic format extension like .json/.toml rather than a specific extension?

Background

I built something closely related to this for loading plugin settings from specific configuration files: https://github.com/devnev/bevy_settings_loader

But in my plugin, the settings are resource singletons and not identified by file extensions but by the full path to the file. So I add a generic .json / .toml loader and then deserialise from the loaded value into the destination type for the asset matching the settings path.

For that I've added generic JsonAsset and TomlAsset types that wrap serde_json::Value and toml_edit::Document loaded from arbitrary files with the corresponding extension. However, my repository/package/plugin is too specific for something that generic, whereas this repository seems more suitable and has most of the code for it already.

The main missing pieces is a wrapper implementing Asset for serde_json::Value etc, which would allow other plugins to avoid duplicate registration of loaders for the corresponding extension.

Support XML

This would allow for all xml file types (custom, html, etc.) to be used as assets.

I would be happy to code it up myself with a little guidance if needed!

Make loaders public

I'm trying to app.register_asset_processor::<LoadTransformAndSave<RonAssetLoader<MyAsset>, _, _>>(LoadTransformAndSave::new(..., ...), but I cannot, bc RonAssetLoader is private

Try to load JSON-File: "Could not parse the JSON: invalid type: map"

Hello,

I try to load this JSON file:

[
    {
        "name": "Foyer",
        "x": 0,
        "y": 0,
        "width": 3,
        "height": 3,
        "color": "lightgray",
        "description": "Ein großes, einladendes Foyer mit Marmorboden, hohen Decken und einem majestätischen Kronleuchter. An den Wänden hängen alte Gemälde der Familie Blackwood.",
        "image": "foyer.jpg"
    },
    {
        "name": "Bibliothek",
        "x": 3,
        "y": 0,
        "width": 3,
        "height": 3,
        "color": "lightblue",
        "description": "Eine ruhige Bibliothek mit hohen Bücherregalen, vollgestopft mit alten Büchern. In der Mitte steht ein massiver Eichentisch, auf dem noch geöffnete Bücher und ein Glas Whiskey stehen.",
        "image": "bibliothek.jpg"
    }
] 

Part of my program:

#[derive(Debug, serde::Deserialize, Asset, TypePath)]
struct Room {
    name: String,
    x: i32,
    y: i32,
    width: u32,
    height: u32,
    color: String,
    description: String,
    image: String,
}
#[derive(serde::Deserialize, Asset, TypePath)]
struct Rooms {
    rooms: Vec<Room>,
}

#[derive(Resource)]
struct RoomsHandle(Handle<Rooms>);

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            JsonAssetPlugin::<Rooms>::new(&["rooms.json"]),
        ))
        .insert_resource(Msaa::Off)
        .init_state::<AppState>()
        .add_systems(Startup, setup)
        .add_systems(Update, spawn_plane.run_if(in_state(AppState::Loading)))
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>
) {
    let rooms = RoomsHandle(asset_server.load("cases/Mord im Herrenhaus/data/rooms.json"));
    commands.insert_resource(rooms);
...
}

fn spawn_plane(
    mut commands: Commands,
    room: Res<RoomsHandle>,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
    mut rooms: ResMut<Assets<Rooms>>,
    mut state: ResMut<NextState<AppState>>,
) {

    if let Some(room) = rooms.remove(room.0.id()) {
        for r in room.rooms  {
            println!("{:?}",r);
        }

        state.set(AppState::Running);
    }
}

There I get the message " Failed to load asset 'cases/Mord im Herrenhaus/data/rooms.json' with asset loader 'bevy_common_assets::json::JsonAssetLoader<rust_bevy_murder_mystery_game::Rooms>': Could not parse the JSON: invalid type: map, expected a sequence at line 2 column 4
"

Whats wrong?

Best regards Gerhard

Could not find `json`.

Just trying to use the JsonAssetPlugin:

use bevy_common_assets::json::JsonAssetPlugin;

But this won't compile. Here's the error I get:

image

Am I doing something wrong? Btw I'm fairly new to Rust.

Example using `Map`

Could you please add an example of how to read a struct in addition to the vector?

View the Keep A Changelog spec

First and foremost, thanks for having a changelog at all!

I wanted to suggest to look at Keep A Changelog, because I really like that spec for Changelogs and I think it might further improve this projects log.

If desired, I could try creating the PR for that too :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.