Skip to content

Commit

Permalink
refactor create command into a subcommand, to allow for other types o…
Browse files Browse the repository at this point in the history
…f creations
  • Loading branch information
yeastplume committed Feb 21, 2020
1 parent 0a9a032 commit 7ca67d5
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 29 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/ex_001.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Now we're going to import this palette into a fresh Aloevera project with the `p
First, in the same directory as the palette file, we create a new Aloevera project file:

```.sh
aloevera create project.av
aloevera create project project.av
```

We now need to import the palette and give it an internal id that later commands can reference. Most Aloevera commands require the `-p` flag, which refers to the project file on which we're currently operating.
Expand Down Expand Up @@ -189,4 +189,4 @@ And running this in the x16 emulator, we get the same (if much slower) NES-ish t

Of course, making the boot screen more NES-ish isn't all that Aloevera can do. Aloevera really starts to become useful when you start to create and import Imagesets, introduced in the next example:

### [Example 2: Intro to Imagesets - Replacing the default font](./ex_002.md)
### [Example 2: Intro to Imagesets - Replacing the default font](./ex_002.md)
2 changes: 1 addition & 1 deletion docs/ex_002.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ I'm going to format this imageset for use in the X16's default Text 1BPP 16 colo
Let's create a project and do the initial import. As discussed earlier, we don't need to worry about target formats just yet, however since we know we're going to be using the imageset in 1BPP mode, we don't need to worry too much about palette data just now. It should suffice just to let Aloevera derive a (small) palette from the image itself.

```.sh
aloevera create project.av
aloevera create project project.av
aloevera -p project.av palette import palette_1 pixel-font.png
aloevera -p projevt.av imageset import text_set_1 8 8 pixel-font.png
```
Expand Down
2 changes: 1 addition & 1 deletion docs/ex_005.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here's our sample sprite image, taken from Best FF:
It's a simple walkcycle (with masterful pixel placement) consisting of three 16 by 32 frames. It's designed for 4 BPP colour and a small palette, so that's how we'll import it:

```.sh
aloevera create project.av
aloevera create project project.av
aloevera -p project.av palette import terra_pal terra.png
aloevera -p project.av imageset import terra_imageset 16 32 terra.png
aloevera -p project.av imageset format terra_imageset terra_pal 4
Expand Down
2 changes: 1 addition & 1 deletion samples/bitmap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RESOURCES = kq5.png

project.av: $(RESOURCES)
rm -rf project.av ./output/
$(ALOEVERA) create project.av
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import kq5_pal kq5-halved.png
$(ALOEVERA) -p project.av imageset import kq5_screen 320 100 kq5-halved.png
$(ALOEVERA) -p project.av imageset format kq5_screen kq5_pal 8
Expand Down
2 changes: 1 addition & 1 deletion samples/palette/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NAME = poke_palette
RESOURCES = nes-palette.png

project.av: $(RESOURCES)
$(ALOEVERA) create project.av
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import palette_1 nes-palette.png
$(ALOEVERA) -p project.av asm ./output/
$(ALOEVERA) -p project.av asm -f basic ./output/
Expand Down
2 changes: 1 addition & 1 deletion samples/scratch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include ../Makefile.vars
NAME = scratch

project.av:
$(ALOEVERA) create project.av
$(ALOEVERA) create project project.av
# $(ALOEVERA) -p project.gx16 palette import palette_1 pixel-font.png
# $(ALOEVERA) -p project.gx16 imageset import text_set_1 8 8 pixel-font.png
# $(ALOEVERA) -p project.gx16 imageset format text_set_1 palette_1 1
Expand Down
2 changes: 1 addition & 1 deletion samples/sprites/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RESOURCES = terra.png

project.av: $(RESOURCES)
rm -rf project.av ./output/
$(ALOEVERA) create project.av
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import terra_pal terra.png
$(ALOEVERA) -p project.av imageset import terra_imageset 16 32 terra.png
$(ALOEVERA) -p project.av imageset format terra_imageset terra_pal 4
Expand Down
2 changes: 1 addition & 1 deletion samples/tile_text/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RESOURCES = pixel-font.png tilemap-banner-1bpp.png

project.av: $(RESOURCES)
rm -rf project.gx16 ./output/
$(ALOEVERA) create project.av
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import palette_1 pixel-font.png
$(ALOEVERA) -p project.av imageset import text_set_1 8 8 pixel-font.png
$(ALOEVERA) -p project.av imageset format text_set_1 palette_1 1
Expand Down
2 changes: 1 addition & 1 deletion samples/tile_wall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RESOURCES = tile_wall-map.png tile_wall-imageset-4bpp.png

project.av: $(RESOURCES)
rm -rf project.av ./output/
$(ALOEVERA) create project.av
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import tile_wall_pal tile_wall-imageset-4bpp.png
$(ALOEVERA) -p project.av imageset import wall_tiles 16 16 tile_wall-imageset-4bpp.png
$(ALOEVERA) -p project.av imageset format wall_tiles tile_wall_pal 4
Expand Down
29 changes: 19 additions & 10 deletions src/bin/aloevera.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ args:
takes_value: true
subcommands:
- create:
about: Create a new Aloevera project file
args:
- id:
help: Internal Id for the new project file
short: i
long: id
takes_value: true
- output_file:
help: Output file name
index: 1
about: Create Aloevera project files or target images
subcommands:
- project:
about: Create a new Aloevera project file
args:
- id:
help: Internal Id for the new project file
short: i
long: id
takes_value: true
- output_file:
help: Output file name
index: 1
- sdimage:
about: Create a new FAT32 SDCard Image in which to insert assembled binary assets
args:
- output_file:
help: Output image file name
index: 1
- asm:
about: Assembles all resources in the project file
args:
Expand Down
7 changes: 2 additions & 5 deletions src/cmd/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
use clap::ArgMatches;

use crate::cmd::common::{self, GlobalArgs};
use crate::cmd::{asm, bitmap, imageset, palette, project, sprite, tilemap};
use crate::cmd::{asm, bitmap, create, imageset, palette, sprite, tilemap};
use crate::{Error, ErrorKind};

fn parse_and_execute(g_args: &GlobalArgs, args: &ArgMatches) -> Result<(), Error> {
match args.subcommand() {
("create", Some(args)) => {
let a = arg_parse!(project::parse::parse_create_project_args(&args,));
project::command::create_project(&a)
}
("asm", Some(args)) => {
let a = arg_parse!(asm::parse::parse_asm_args(g_args, &args,));
asm::command::asm(g_args, &a)
}
("create", Some(args)) => create::parse::execute_create_command(&args),
("palette", Some(args)) => palette::parse::execute_palette_command(g_args, &args),
("sprite", Some(args)) => sprite::parse::execute_sprite_command(g_args, &args),
("bitmap", Some(args)) => bitmap::parse::execute_bitmap_command(g_args, &args),
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub mod common;

pub mod asm;
pub mod bitmap;
pub mod create;
pub mod imageset;
pub mod palette;
pub mod project;
pub mod sprite;
pub mod tilemap;

Expand Down
18 changes: 18 additions & 0 deletions src/cmd/project/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,21 @@ pub fn create_project(args: &CreateProjectArgs) -> Result<(), Error> {

Ok(())
}

/// Arguments for the initial create project command
pub struct CreateSDImageArgs {
pub output_file: String,
}

pub fn create_sd_image(args: &CreateSDImageArgs) -> Result<(), Error> {
info!(
"Creating new SDCard (FAT32 FS) image at: {}",
args.output_file
);

/*let proj = AloeVeraProject::new(id);
let json = proj.to_json()?;*/
//crate::cmd::common::output_to_file(&args.output_file, &json.as_bytes())?;

Ok(())
}
28 changes: 26 additions & 2 deletions src/cmd/project/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::command::CreateProjectArgs;
use super::command::{self, CreateProjectArgs, CreateSDImageArgs};
use crate::cmd::common;
use crate::Error;
use crate::{Error, ErrorKind};
use clap::ArgMatches;

pub fn parse_create_project_args(args: &ArgMatches) -> Result<CreateProjectArgs, Error> {
Expand All @@ -23,3 +23,27 @@ pub fn parse_create_project_args(args: &ArgMatches) -> Result<CreateProjectArgs,
output_file: output_file.into(),
})
}

pub fn parse_create_sd_image_args(args: &ArgMatches) -> Result<CreateSDImageArgs, Error> {
let output_file = common::parse_required(args, "output_file")?;
Ok(CreateSDImageArgs {
output_file: output_file.into(),
})
}

pub fn execute_create_command(args: &ArgMatches) -> Result<(), Error> {
match args.subcommand() {
("project", Some(args)) => {
let a = arg_parse!(parse_create_project_args(args));
command::create_project(&a)
}
("sdimage", Some(args)) => {
let a = arg_parse!(parse_create_sd_image_args(args));
command::create_sd_image(&a)
}
_ => {
let msg = format!("Unknown sub command, use 'aloevera create --help' for details");
return Err(ErrorKind::ArgumentError(msg).into());
}
}
}
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ log = "0.4"
walkdir = "2"
zip = { version = "0.5", default-features = false }
parking_lot = {version = "0.6"}

fatfs = "0.3"

0 comments on commit 7ca67d5

Please sign in to comment.