Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for existing asset configuration #28

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize, PartialEq)]
Expand All @@ -14,6 +16,11 @@ pub struct Creator {
pub id: u64,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ExistingAsset {
pub id: u64,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Config {
pub asset_dir: String,
Expand All @@ -22,4 +29,6 @@ pub struct Config {
pub output_name: Option<String>,
pub typescript: Option<bool>,
pub luau: Option<bool>,

pub existing: Option<HashMap<String, ExistingAsset>>,
}
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async fn main() -> anyhow::Result<()> {
toml::from_str(&file_contents).context("Failed to parse config")
}?;

let mut state = State::new(args, &config)
let mut state = State::new(args, config)
.await
.context("Failed to create state")?;

Expand Down Expand Up @@ -164,6 +164,19 @@ async fn main() -> anyhow::Result<()> {
.to_str()
.context("Failed to convert asset directory to string")?;

state
.new_lockfile
.entries
.extend(state.existing.into_iter().map(|(path, asset)| {
(
path,
FileEntry {
hash: "".to_string(),
asset_id: asset.id,
},
)
}));

let lua_filename = format!("{}.{}", state.output_name, state.lua_extension);
let lua_output = generate_lua(&state.new_lockfile, asset_dir_str);

Expand Down
12 changes: 8 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::{env, path::PathBuf};

use crate::{
args::Args,
config::{Config, CreatorType},
config::{Config, CreatorType, ExistingAsset},
LockFile,
};
use anyhow::Context;
use rbxcloud::rbx::v1::assets::{AssetCreator, AssetGroupCreator, AssetUserCreator};
use resvg::usvg::fontdb::Database;
use std::{collections::HashMap, env, path::PathBuf};
use tokio::fs::{create_dir_all, read_to_string};

fn add_trailing_slash(path: &str) -> String {
Expand Down Expand Up @@ -40,10 +39,12 @@ pub struct State {

pub existing_lockfile: LockFile,
pub new_lockfile: LockFile,

pub existing: HashMap<String, ExistingAsset>,
}

impl State {
pub async fn new(args: Args, config: &Config) -> anyhow::Result<Self> {
pub async fn new(args: Args, config: Config) -> anyhow::Result<Self> {
let api_key = get_api_key(args.api_key)?;

let creator: AssetCreator = match config.creator.creator_type {
Expand Down Expand Up @@ -90,6 +91,8 @@ impl State {

let new_lockfile: LockFile = Default::default();

let manual = config.existing.unwrap_or_default();

Ok(Self {
asset_dir,
write_dir,
Expand All @@ -101,6 +104,7 @@ impl State {
font_db,
existing_lockfile,
new_lockfile,
existing: manual,
})
}
}
Loading