Skip to content

Commit

Permalink
Merge pull request #1 from jeparlefrancais/local-sync
Browse files Browse the repository at this point in the history
implement sync to local content folder
  • Loading branch information
jeparlefrancais authored Dec 3, 2020
2 parents 4b691a9 + cea7422 commit a4b303e
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ name: CI
on:
push:
branches:
- main
- master

pull_request:
branches:
- main
- master

jobs:
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/clabot.yml

This file was deleted.

79 changes: 79 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ fs-err = "2.3.0"
globset = "0.4.4"
lazy_static = "1.4.0"
log = "0.4.8"
path-slash = "0.1.3"
png = "0.15.3"
regex = "1.3.3"
reqwest = "0.9.20"
roblox_install = "0.3.0"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
structopt = { version = "0.3", default-features = false }
Expand Down
22 changes: 10 additions & 12 deletions src/alpha_bleed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ pub(crate) fn alpha_bleed(image: &mut Image) {

// An iterator of in-bounds positions adjacent to the given one.
let adjacent_positions = |x, y| {
DIRECTIONS
.into_iter()
.filter_map(move |(x_offset, y_offset)| {
let x_source = (x as i32) + x_offset;
let y_source = (y as i32) + y_offset;

if x_source < 0 || y_source < 0 || x_source >= w as i32 || y_source >= h as i32 {
return None;
}

Some((x_source as u32, y_source as u32))
})
DIRECTIONS.iter().filter_map(move |(x_offset, y_offset)| {
let x_source = (x as i32) + x_offset;
let y_source = (y as i32) + y_offset;

if x_source < 0 || y_source < 0 || x_source >= w as i32 || y_source >= h as i32 {
return None;
}

Some((x_source as u32, y_source as u32))
})
};

// Populate the set of initial positions to visit as well as positions that
Expand Down
16 changes: 8 additions & 8 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fs_err::File;

use crate::{
data::ImageSlice,
data::SyncInput,
data::{AssetId, SyncInput},
lua_ast::{Block, Expression, Function, IfBlock, Statement, Table},
};

Expand Down Expand Up @@ -143,7 +143,7 @@ fn codegen_grouped(output_path: &Path, inputs: &[&SyncInput]) -> io::Result<()>

let input = inputs_by_dpi_scale.values().next().unwrap();

match (input.id, input.slice) {
match (&input.id, input.slice) {
(Some(id), Some(slice)) => Some(codegen_url_and_slice(id, slice)),
(Some(id), None) => Some(codegen_just_asset_url(id)),
_ => None,
Expand Down Expand Up @@ -175,7 +175,7 @@ fn codegen_grouped(output_path: &Path, inputs: &[&SyncInput]) -> io::Result<()>
/// defined, and so generate individual files.
fn codegen_individual(inputs: &[&SyncInput]) -> io::Result<()> {
for input in inputs {
let expression = match (input.id, input.slice) {
let expression = match (&input.id, input.slice) {
(Some(id), Some(slice)) => codegen_url_and_slice(id, slice),
(Some(id), None) => codegen_just_asset_url(id),
_ => continue,
Expand All @@ -193,12 +193,12 @@ fn codegen_individual(inputs: &[&SyncInput]) -> io::Result<()> {
Ok(())
}

fn codegen_url_and_slice(id: u64, slice: ImageSlice) -> Expression {
fn codegen_url_and_slice(id: &AssetId, slice: ImageSlice) -> Expression {
let offset = slice.min();
let size = slice.size();

let mut table = Table::new();
table.add_entry("Image", format!("rbxassetid://{}", id));
table.add_entry("Image", id.to_string());
table.add_entry(
"ImageRectOffset",
Expression::Raw(format!("Vector2.new({}, {})", offset.0, offset.1)),
Expand All @@ -212,16 +212,16 @@ fn codegen_url_and_slice(id: u64, slice: ImageSlice) -> Expression {
Expression::Table(table)
}

fn codegen_just_asset_url(id: u64) -> Expression {
Expression::String(format!("rbxassetid://{}", id))
fn codegen_just_asset_url(id: &AssetId) -> Expression {
Expression::String(id.to_string())
}

fn codegen_dpi_option(input: &SyncInput) -> (Expression, Block) {
let condition = Expression::Raw(format!("dpiScale >= {}", input.dpi_scale));

// FIXME: We should probably pull data out of SyncInput at the start of
// codegen so that we can handle invariants like this.
let id = input.id.unwrap();
let id = input.id.as_ref().unwrap();

let value = match input.slice {
Some(slice) => codegen_url_and_slice(id, slice),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/create_cache_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn create_cache_map(
let mut api_client = RobloxApiClient::new(global.auth);

let project_path = match options.project_path {
Some(path) => path.clone(),
Some(path) => path,
None => env::current_dir()?,
};

Expand Down
Loading

0 comments on commit a4b303e

Please sign in to comment.