Skip to content

Commit

Permalink
Merge pull request #28 from kb10uy/flatten-arbittach
Browse files Browse the repository at this point in the history
Attachment Group を廃止する
  • Loading branch information
kb10uy authored Feb 9, 2024
2 parents 2e97501 + 9265dee commit 9a92c48
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 87 deletions.
6 changes: 0 additions & 6 deletions declavatar/src/avatar_v2/data/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ use std::collections::HashMap;

use serde::Serialize;

#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct AttachmentGroup {
pub target: String,
pub attachments: Vec<Attachment>,
}

#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct Attachment {
pub name: String,
Expand Down
7 changes: 3 additions & 4 deletions declavatar/src/avatar_v2/data/avatar.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::avatar_v2::data::{
asset::Asset, export::ExportItem, layer::Layer, menu::MenuItem, parameter::Parameter,
asset::Asset, attachment::Attachment, export::ExportItem, layer::Layer, menu::MenuItem,
parameter::Parameter,
};

use serde::Serialize;

use super::attachment::AttachmentGroup;

#[derive(Debug, Clone, Serialize)]
pub struct Avatar {
pub name: String,
pub exports: Vec<ExportItem>,
pub attachments: Vec<AttachmentGroup>,
pub attachments: Vec<Attachment>,
pub parameters: Vec<Parameter>,
pub assets: Vec<Asset>,
pub fx_controller: Vec<Layer>,
Expand Down
35 changes: 6 additions & 29 deletions declavatar/src/avatar_v2/transformer/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ use crate::{
avatar_v2::{
data::attachment::{
schema::{Attachment as AttachmentSchema, Property as PropertySchema, ValueType},
Attachment, AttachmentGroup, Property, Value,
Attachment, Property, Value,
},
log::{ArbittachError, Log},
transformer::{failure, success, Compiled},
},
decl_v2::data::arbittach::{
DeclAttachment, DeclAttachmentGroup, DeclAttachmentProperty, DeclAttachmentValue,
DeclAttachments,
decl_v2::data::attachment::{
DeclAttachment, DeclAttachmentProperty, DeclAttachmentValue, DeclAttachments,
},
log::Logger,
};
Expand All @@ -20,12 +19,12 @@ pub fn compile_attachment_blocks(
logger: &Logger<Log>,
schemas: &HashMap<String, AttachmentSchema>,
attachment_blocks: Vec<DeclAttachments>,
) -> Compiled<Vec<AttachmentGroup>> {
) -> Compiled<Vec<Attachment>> {
let mut attachment_groups = vec![];
for (index, decl_attachments) in attachment_blocks.into_iter().enumerate() {
let logger = logger.with_context(format!("attachments block {index}"));
for decl_group in decl_attachments.targets {
let Some(group) = compile_group(&logger, schemas, decl_group) else {
for decl_attachment in decl_attachments.attachments {
let Some(group) = compile_attachment(&logger, schemas, decl_attachment) else {
continue;
};
attachment_groups.push(group);
Expand All @@ -35,28 +34,6 @@ pub fn compile_attachment_blocks(
success(attachment_groups)
}

fn compile_group(
logger: &Logger<Log>,
schemas: &HashMap<String, AttachmentSchema>,
decl_group: DeclAttachmentGroup,
) -> Compiled<AttachmentGroup> {
let target = decl_group.target;
let mut attachments = vec![];

let logger = logger.with_context(format!("target {target}"));
for decl_attachment in decl_group.attachments {
let Some(attachment) = compile_attachment(&logger, schemas, decl_attachment) else {
continue;
};
attachments.push(attachment);
}

success(AttachmentGroup {
target,
attachments,
})
}

fn compile_attachment(
logger: &Logger<Log>,
schemas: &HashMap<String, AttachmentSchema>,
Expand Down
2 changes: 1 addition & 1 deletion declavatar/src/decl_v2/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod arbittach;
pub mod asset;
pub mod attachment;
pub mod avatar;
pub mod controller;
pub mod driver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@ use ketos::{ForeignValue, FromValue, FromValueRef, IntoValue};

#[derive(Debug, Clone, PartialEq, ForeignValue, FromValue, FromValueRef, IntoValue)]
pub struct DeclAttachments {
pub targets: Vec<DeclAttachmentGroup>,
}
static_type_name_impl!(DeclAttachments);

#[derive(Debug, Clone, PartialEq, ForeignValue, FromValue, FromValueRef, IntoValue)]
pub struct DeclAttachmentGroup {
pub target: String,
pub attachments: Vec<DeclAttachment>,
}
static_type_name_impl!(DeclAttachmentGroup);
static_type_name_impl!(DeclAttachments);

#[derive(Debug, Clone, PartialEq, ForeignValue, FromValue, FromValueRef, IntoValue)]
pub struct DeclAttachment {
Expand Down
2 changes: 1 addition & 1 deletion declavatar/src/decl_v2/data/avatar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
decl_v2::data::{
arbittach::DeclAttachments, asset::DeclAssets, controller::DeclFxController,
asset::DeclAssets, attachment::DeclAttachments, controller::DeclFxController,
export::DeclExports, menu::DeclSubMenu, parameter::DeclParameters,
},
static_type_name_impl,
Expand Down
2 changes: 1 addition & 1 deletion declavatar/src/decl_v2/sexpr/da/avatar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::decl_v2::{
data::{
arbittach::DeclAttachments, asset::DeclAssets, avatar::DeclAvatar,
asset::DeclAssets, attachment::DeclAttachments, avatar::DeclAvatar,
controller::DeclFxController, export::DeclExports, menu::DeclSubMenu,
parameter::DeclParameters, StaticTypeName,
},
Expand Down
44 changes: 13 additions & 31 deletions declavatar/src/decl_v2/sexpr/da3/attachment.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::decl_v2::{
data::{
arbittach::{
DeclAttachment, DeclAttachmentGroup, DeclAttachmentProperty, DeclAttachmentValue,
DeclAttachments,
attachment::{
DeclAttachment, DeclAttachmentProperty, DeclAttachmentValue, DeclAttachments,
},
StaticTypeName,
},
Expand All @@ -19,8 +18,13 @@ pub fn register_attachment_function(scope: &Scope) {
Arity::Min(0),
Some(&[]),
);
register_function(scope, "for", define_target, Arity::Min(1), Some(&[]));
register_function(scope, "attach", define_attachment, Arity::Min(1), Some(&[]));
register_function(
scope,
"attachment",
define_attachment,
Arity::Min(1),
Some(&[]),
);
register_function(scope, "property", define_property, Arity::Min(1), None);
}

Expand All @@ -29,37 +33,15 @@ fn declare_attachments(
function_name: Name,
args: SeparateArguments,
) -> KetosResult<Value> {
let mut targets = vec![];
for decl_target in args.args_after_recursive(function_name, 0)? {
targets.push(
decl_target
.downcast_foreign_ref::<&DeclAttachmentGroup>()
.cloned()?,
);
}
Ok(DeclAttachments { targets }.into())
}

fn define_target(
_name_store: &NameStore,
function_name: Name,
args: SeparateArguments,
) -> KetosResult<Value> {
let name: &str = args.exact_arg(function_name, 0)?;

let mut attachments = vec![];
for decl_attachment in args.args_after_recursive(function_name, 1)? {
for decl_attachment in args.args_after_recursive(function_name, 0)? {
attachments.push(
decl_attachment
.downcast_foreign_ref::<&DeclAttachment>()?
.clone(),
.downcast_foreign_ref::<&DeclAttachment>()
.cloned()?,
);
}
Ok(DeclAttachmentGroup {
target: name.to_string(),
attachments,
}
.into())
Ok(DeclAttachments { attachments }.into())
}

fn define_attachment(
Expand Down
2 changes: 1 addition & 1 deletion declavatar/src/decl_v2/sexpr/da3/value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::decl_v2::{
data::arbittach::DeclAttachmentValue,
data::attachment::DeclAttachmentValue,
sexpr::{argument::SeparateArguments, error::KetosResult, register_function},
};

Expand Down
8 changes: 3 additions & 5 deletions examples/sexpr/arbittach.declisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

(da/avatar "arbitrary-attachment"
(da3/attachments
(da3/for "NewObject"
(da3/attach "GameObject"
(da3/property "Transform" (da3/vector3 0.0 0.0 0.0))
(da3/property "Parent" (da3/game-object "Armature/Hips/Upper_Leg.L"))
)
(da3/attachment "GameObject"
(da3/property "Transform" (da3/vector3 0.0 0.0 0.0))
(da3/property "Parent" (da3/game-object "Armature/Hips/Upper_Leg.L"))
)
)
)

0 comments on commit 9a92c48

Please sign in to comment.