From 5bf5b1ff6795df3b6616fa22ed19b8e28cc67404 Mon Sep 17 00:00:00 2001 From: "remy.baranx@gmail.com" Date: Mon, 8 Jul 2024 16:20:00 +0200 Subject: [PATCH] feat: add get_[field_name] and set_[field_name] to models --- ._target | Bin 0 -> 4096 bytes crates/dojo-core/src/base_test.cairo | 2 +- crates/dojo-core/src/model.cairo | 39 +- crates/dojo-core/src/model_test.cairo | 174 +- crates/dojo-core/src/resource_metadata.cairo | 64 +- crates/dojo-core/src/utils.cairo | 29 + crates/dojo-core/src/world.cairo | 333 +- crates/dojo-core/src/world_test.cairo | 146 +- crates/dojo-lang/src/inline_macros/delete.rs | 9 +- crates/dojo-lang/src/inline_macros/get.rs | 4 +- crates/dojo-lang/src/inline_macros/set.rs | 8 +- crates/dojo-lang/src/introspect/layout.rs | 2 +- .../manifests/dev/base/abis/dojo-world.json | 108 +- .../manifests/dev/base/dojo-world.toml | 4 +- crates/dojo-lang/src/model.rs | 345 +- crates/dojo-lang/src/plugin_test_data/model | 6360 +++++++++++++---- crates/dojo-lang/src/semantics/test_data/get | 22 +- crates/dojo-lang/src/semantics/test_data/set | 92 +- crates/dojo-world/src/contracts/abi/world.rs | 108 +- crates/dojo-world/src/contracts/model.rs | 9 +- crates/dojo-world/src/contracts/naming.rs | 4 +- crates/torii/types-test/src/contracts.cairo | 2 +- examples/spawn-and-move/._target | Bin 0 -> 4096 bytes examples/spawn-and-move/Scarb.toml | 5 +- .../dojo_examples-actions-40b6994c.json | 24 + .../manifests/dev/base/abis/dojo-world.json | 108 +- .../dojo_examples-actions-40b6994c.toml | 4 +- .../dojo_examples-mock_token-31599eb2.toml | 4 +- .../manifests/dev/base/dojo-world.toml | 4 +- .../dojo_examples-actions-40b6994c.json | 36 + .../dev/deployment/abis/dojo-world.json | 108 +- .../manifests/dev/deployment/manifest.json | 403 +- .../manifests/dev/deployment/manifest.toml | 36 +- .../dojo_examples-actions-40b6994c.json | 24 + .../release/base/abis/dojo-world.json | 108 +- .../dojo_examples-actions-40b6994c.toml | 4 +- .../dojo_examples-mock_token-31599eb2.toml | 4 +- .../manifests/release/base/dojo-world.toml | 4 +- examples/spawn-and-move/src/actions.cairo | 46 +- examples/spawn-and-move/src/mock_token.cairo | 1 - 40 files changed, 6428 insertions(+), 2359 deletions(-) create mode 100644 ._target create mode 100644 examples/spawn-and-move/._target diff --git a/._target b/._target new file mode 100644 index 0000000000000000000000000000000000000000..dc27ea21b83aa811079476f17dfcb4aab9d7105e GIT binary patch literal 4096 zcmeH~y$ZrW498PJ)J1f0D&?L)ilZRnC@6wY*0{y@t)gaym7NXuLx3(`Dd hVWKcmVVZC$PfTK>0kICV0_;Hy2u2ps%{hBJWBuo literal 0 HcmV?d00001 diff --git a/crates/dojo-core/src/base_test.cairo b/crates/dojo-core/src/base_test.cairo index f42db54184..c3213716a2 100644 --- a/crates/dojo-core/src/base_test.cairo +++ b/crates/dojo-core/src/base_test.cairo @@ -178,7 +178,7 @@ mod invalid_model { fn selector(self: @ContractState) -> felt252 { // NOTE: Need to update this value if address changes // Pre-computed address of a contract deployed through the world. - 0x562c876783650ced854d9571abba1259cc28b5256fa0994f3d1c4cd2b6c4488 + 0x3f18f40f6d815f380d1ea8278289b58f076abf6e396d7a88eed5d152da8190b } fn namespace(self: @ContractState) -> ByteArray { diff --git a/crates/dojo-core/src/model.cairo b/crates/dojo-core/src/model.cairo index 918576fd94..3ebbd5e0bc 100644 --- a/crates/dojo-core/src/model.cairo +++ b/crates/dojo-core/src/model.cairo @@ -1,31 +1,32 @@ -use dojo::world::IWorldDispatcher; +use dojo::world::{IWorldDispatcher, ModelIndex}; use starknet::SyscallResult; /// Trait that is implemented at Cairo level for each struct that is a model. -trait ModelValues { +trait ModelEntity { + fn id(self: @T) -> felt252; fn values(self: @T) -> Span; - fn from_values(values: Span) -> T; - fn get(world: IWorldDispatcher, id: felt252) -> T; - fn update(self: @T, world: IWorldDispatcher, id: felt252); - fn delete(self: @T, world: IWorldDispatcher, id: felt252); + fn from_values(entity_id: felt252, values: Span) -> T; + fn get(world: IWorldDispatcher, entity_id: felt252) -> T; + fn update(self: @T, world: IWorldDispatcher); + fn delete(self: @T, world: IWorldDispatcher); + fn get_member( + world: IWorldDispatcher, entity_id: felt252, member_id: felt252, + ) -> Span; + fn set_member(self: @T, world: IWorldDispatcher, member_id: felt252, values: Span,); } trait Model { - fn entity( - world: IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout - ) -> T; + fn get(world: IWorldDispatcher, keys: Span) -> T; + // Note: `get` is implemented with a generated trait because it takes + // the list of model keys as separated parameters. + fn set(self: @T, world: IWorldDispatcher); + fn delete(self: @T, world: IWorldDispatcher); - fn set_entity( - world: IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout - ); - - fn delete_entity( - world: IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout - ); + fn get_member( + world: IWorldDispatcher, keys: Span, member_id: felt252, + ) -> Span; + fn set_member(self: @T, world: IWorldDispatcher, member_id: felt252, values: Span,); /// Returns the name of the model as it was written in Cairo code. fn name() -> ByteArray; diff --git a/crates/dojo-core/src/model_test.cairo b/crates/dojo-core/src/model_test.cairo index c61e15f9f0..68a17d604d 100644 --- a/crates/dojo-core/src/model_test.cairo +++ b/crates/dojo-core/src/model_test.cairo @@ -17,12 +17,18 @@ struct Foo { v2: u32 } +#[test] +fn test_id() { + let mvalues = FooEntity { __id: 1, v1: 3, v2: 4 }; + assert!(mvalues.id() == 1); +} + #[test] fn test_values() { - let mvalues = FooValues { v1: 3, v2: 4 }; + let mvalues = FooEntity { __id: 1, v1: 3, v2: 4 }; let expected_values = array![3, 4].span(); - let values = FooModelValues::values(@mvalues); + let values = dojo::model::ModelEntity::::values(@mvalues); assert!(expected_values == values); } @@ -30,97 +36,163 @@ fn test_values() { fn test_from_values() { let values = array![3, 4].span(); - let model_values = FooModelValues::from_values(values); - assert!(model_values.v1 == 3 && model_values.v2 == 4); + let model_entity = dojo::model::ModelEntity::::from_values(1, values); + assert!(model_entity.__id == 1 && model_entity.v1 == 3 && model_entity.v2 == 4); } #[test] -#[should_panic(expected: "ModelValues `FooValues`: deserialization failed.")] +#[should_panic(expected: "ModelEntity `FooEntity`: deserialization failed.")] fn test_from_values_bad_data() { let values = array![3].span(); - let _ = FooModelValues::from_values(values); + let _ = dojo::model::ModelEntity::::from_values(1, values); } #[test] -fn test_get_and_update_values() { +fn test_get_and_update_entity() { let world = deploy_world(); world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); - let entity = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; - let entity_id = entity.entity_id(); - dojo::model::Model::< - Foo - >::set_entity(world, entity.keys(), entity.values(), entity.instance_layout()); + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); - let mut entity_values = FooModelValues::get(world, entity_id); - assert!(entity.v1 == entity_values.v1 && entity.v2 == entity_values.v2); + let entity_id = foo.entity_id(); + let mut entity = FooEntityTrait::get(world, entity_id); + assert!(entity.__id == entity_id && entity.v1 == entity.v1 && entity.v2 == entity.v2); - entity_values.v1 = 12; - entity_values.v2 = 18; + entity.v1 = 12; + entity.v2 = 18; - entity_values.update(world, entity_id); + entity.update(world); - let read_values = FooModelValues::get(world, entity_id); - assert!(read_values.v1 == entity_values.v1 && read_values.v2 == entity_values.v2); + let read_values = FooEntityTrait::get(world, entity_id); + assert!(read_values.v1 == entity.v1 && read_values.v2 == entity.v2); } #[test] -fn test_delete_values() { +fn test_delete_entity() { let world = deploy_world(); world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); - let entity = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; - let entity_id = entity.entity_id(); - dojo::model::Model::< - Foo - >::set_entity(world, entity.keys(), entity.values(), entity.instance_layout()); + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); - let mut entity_values = FooModelValues::get(world, entity_id); - entity_values.delete(world, entity_id); + let entity_id = foo.entity_id(); + let mut entity = FooEntityTrait::get(world, entity_id); + entity.delete(world); - let read_values = FooModelValues::get(world, entity_id); + let read_values = FooEntityTrait::get(world, entity_id); assert!(read_values.v1 == 0 && read_values.v2 == 0); } #[test] -fn test_entity_and_set_entity() { +fn test_get_and_set_member_from_entity() { + let world = deploy_world(); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); + + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); + + let v1_raw_value: Span = dojo::model::ModelEntity::< + FooEntity + >::get_member(world, foo.entity_id(), selector!("v1")); + + assert!(v1_raw_value.len() == 1); + assert!(*v1_raw_value.at(0) == 3); + + let entity = FooEntityTrait::get(world, foo.entity_id()); + entity.set_member(world, selector!("v1"), array![42].span()); + + let entity = FooEntityTrait::get(world, foo.entity_id()); + assert!(entity.v1 == 42); +} + +#[test] +fn test_get_and_set_field_name() { + let world = deploy_world(); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); + + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); + + let v1 = FooEntityTrait::get_v1(world, foo.entity_id()); + assert!(foo.v1 == v1); + + let entity = FooEntityTrait::get(world, foo.entity_id()); + entity.set_v1(world, 42); + + let v1 = FooEntityTrait::get_v1(world, foo.entity_id()); + assert!(v1 == 42); +} + +#[test] +fn test_get_and_set_from_model() { let world = deploy_world(); world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); - let entity = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; - dojo::model::Model::< - Foo - >::set_entity(world, entity.keys(), entity.values(), entity.instance_layout()); - let read_entity = dojo::model::Model::< - Foo - >::entity(world, entity.keys(), entity.instance_layout()); + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); + + let read_entity = FooTrait::get(world, foo.k1, foo.k2); assert!( - entity.k1 == read_entity.k1 - && entity.k2 == read_entity.k2 - && entity.v1 == read_entity.v1 - && entity.v2 == read_entity.v2 + foo.k1 == read_entity.k1 + && foo.k2 == read_entity.k2 + && foo.v1 == read_entity.v1 + && foo.v2 == read_entity.v2 ); } #[test] -fn test_delete_entity() { +fn test_delete_from_model() { let world = deploy_world(); world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); - let entity = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; - dojo::model::Model::< - Foo - >::set_entity(world, entity.keys(), entity.values(), entity.instance_layout()); - dojo::model::Model::::delete_entity(world, entity.keys(), entity.instance_layout()); + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); + foo.delete(world); - let read_entity = dojo::model::Model::< - Foo - >::entity(world, entity.keys(), entity.instance_layout()); + let read_entity = FooTrait::get(world, foo.k1, foo.k2); assert!( - read_entity.k1 == entity.k1 - && read_entity.k2 == entity.k2 + read_entity.k1 == foo.k1 + && read_entity.k2 == foo.k2 && read_entity.v1 == 0 && read_entity.v2 == 0 ); } + +#[test] +fn test_get_and_set_member_from_model() { + let world = deploy_world(); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); + + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + let keys = array![foo.k1.into(), foo.k2.into()].span(); + foo.set(world); + + let v1_raw_value = dojo::model::Model::::get_member(world, keys, selector!("v1")); + + assert!(v1_raw_value.len() == 1); + assert!(*v1_raw_value.at(0) == 3); + + foo.set_member(world, selector!("v1"), array![42].span()); + let foo = FooTrait::get(world, foo.k1, foo.k2); + assert!(foo.v1 == 42); +} + +#[test] +fn test_get_and_set_field_name_from_model() { + let world = deploy_world(); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); + + let foo = Foo { k1: 1, k2: 2, v1: 3, v2: 4 }; + foo.set(world); + + let v1 = FooTrait::get_v1(world, foo.k1, foo.k2); + assert!(v1 == 3); + + foo.set_v1(world, 42); + + let v1 = FooTrait::get_v1(world, foo.k1, foo.k2); + assert!(v1 == 42); +} + diff --git a/crates/dojo-core/src/resource_metadata.cairo b/crates/dojo-core/src/resource_metadata.cairo index 82b52487ed..dde35752e1 100644 --- a/crates/dojo-core/src/resource_metadata.cairo +++ b/crates/dojo-core/src/resource_metadata.cairo @@ -3,8 +3,9 @@ //! Manually expand to ensure that dojo-core //! does not depend on dojo plugin to be built. //! -use dojo::world::{IWorldDispatcherTrait}; +use dojo::world::{IWorldDispatcherTrait, ModelIndex}; use dojo::model::Model; +use dojo::utils; fn initial_address() -> starknet::ContractAddress { starknet::contract_address_const::<0>() @@ -24,12 +25,8 @@ struct ResourceMetadata { } impl ResourceMetadataModel of dojo::model::Model { - fn entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout - ) -> ResourceMetadata { - let values = world.entity(Self::selector(), keys, layout); + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ResourceMetadata { + let values = world.entity(Self::selector(), ModelIndex::Keys(keys), Self::layout()); let mut serialized = core::array::ArrayTrait::new(); core::array::serialize_array_helper(keys, ref serialized); core::array::serialize_array_helper(values, ref serialized); @@ -45,26 +42,51 @@ impl ResourceMetadataModel of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout - ) { + fn set(self: @ResourceMetadata, world: dojo::world::IWorldDispatcher,) { dojo::world::IWorldDispatcherTrait::set_entity( - world, Self::selector(), keys, values, layout + world, Self::selector(), ModelIndex::Keys(self.keys()), self.values(), Self::layout() ); } - fn delete_entity( + fn delete(self: @ResourceMetadata, world: dojo::world::IWorldDispatcher,) { + world.delete_entity(Self::selector(), ModelIndex::Keys(self.keys()), Self::layout()); + } + + fn get_member( + world: dojo::world::IWorldDispatcher, keys: Span, member_id: felt252 + ) -> Span { + match utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = utils::entity_id_from_keys(keys); + world + .entity( + Self::selector(), ModelIndex::MemberId((entity_id, member_id)), field_layout + ) + }, + Option::None => panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ResourceMetadata, world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + member_id: felt252, + values: Span ) { - dojo::world::IWorldDispatcherTrait::delete_entity(world, Self::selector(), keys, layout); + match utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + world + .set_entity( + Self::selector(), + ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => panic_with_felt252('bad member id') + } } - #[inline(always)] fn name() -> ByteArray { "ResourceMetadata" @@ -94,11 +116,11 @@ impl ResourceMetadataModel of dojo::model::Model { } fn name_hash() -> felt252 { - dojo::utils::hash(@Self::name()) + utils::hash(@Self::name()) } fn namespace_hash() -> felt252 { - dojo::utils::hash(@Self::namespace()) + utils::hash(@Self::namespace()) } #[inline(always)] diff --git a/crates/dojo-core/src/utils.cairo b/crates/dojo-core/src/utils.cairo index 80e318194b..f7dacaacf8 100644 --- a/crates/dojo-core/src/utils.cairo +++ b/crates/dojo-core/src/utils.cairo @@ -17,3 +17,32 @@ fn hash(data: @ByteArray) -> felt252 { fn entity_id_from_keys(keys: Span) -> felt252 { poseidon::poseidon_hash_span(keys) } + +/// TODO +fn find_model_field_layout( + model_layout: dojo::database::introspect::Layout, member_id: felt252 +) -> Option { + match model_layout { + dojo::database::introspect::Layout::Struct(struct_layout) => { + let mut i = 0; + let layout = loop { + if i >= struct_layout.len() { + break Option::None; + } + + let field_layout = *struct_layout.at(i); + if field_layout.selector == member_id { + break Option::Some(field_layout.layout); + } + i += 1; + }; + + layout + }, + _ => { + // should never happen as model layouts are always struct layouts. + panic_with_felt252('Unexpected model layout'); + Option::None + } + } +} diff --git a/crates/dojo-core/src/world.cairo b/crates/dojo-core/src/world.cairo index d17b0706be..bef44334d7 100644 --- a/crates/dojo-core/src/world.cairo +++ b/crates/dojo-core/src/world.cairo @@ -3,6 +3,14 @@ use traits::{Into, TryInto}; use option::OptionTrait; use dojo::resource_metadata::ResourceMetadata; +#[derive(Copy, Drop, Serde, Debug, PartialEq)] +enum ModelIndex { + Keys: Span, + Id: felt252, + // (entity_id, member_id) + MemberId: (felt252, felt252) +} + #[starknet::interface] trait IWorld { fn metadata(self: @T, resource_id: felt252) -> ResourceMetadata; @@ -16,35 +24,27 @@ trait IWorld { fn upgrade_contract(ref self: T, address: ContractAddress, class_hash: ClassHash) -> ClassHash; fn uuid(ref self: T) -> usize; fn emit(self: @T, keys: Array, values: Span); + fn entity( - self: @T, model: felt252, keys: Span, layout: dojo::database::introspect::Layout - ) -> Span; - fn entity_by_id( - self: @T, model_id: felt252, entity_id: felt252, layout: dojo::database::introspect::Layout + self: @T, + model_selector: felt252, + index: ModelIndex, + layout: dojo::database::introspect::Layout ) -> Span; fn set_entity( ref self: T, - model: felt252, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout - ); - fn set_entity_by_id( - ref self: T, - model_id: felt252, - entity_id: felt252, + model_selector: felt252, + index: ModelIndex, values: Span, layout: dojo::database::introspect::Layout ); fn delete_entity( - ref self: T, model: felt252, keys: Span, layout: dojo::database::introspect::Layout - ); - fn delete_entity_by_id( ref self: T, - model_id: felt252, - entity_id: felt252, + model_selector: felt252, + index: ModelIndex, layout: dojo::database::introspect::Layout ); + fn base(self: @T) -> ClassHash; /// In Dojo, there are 2 levels of authorization: `owner` and `writer`. @@ -59,7 +59,7 @@ trait IWorld { fn revoke_writer(ref self: T, resource: felt252, contract: ContractAddress); fn can_write_resource(self: @T, resource_id: felt252, contract: ContractAddress) -> bool; - fn can_write_model(self: @T, model_id: felt252, contract: ContractAddress) -> bool; + fn can_write_model(self: @T, model_selector: felt252, contract: ContractAddress) -> bool; fn can_write_namespace(self: @T, namespace_id: felt252, contract: ContractAddress) -> bool; } @@ -88,6 +88,9 @@ mod Errors { const OWNER_ONLY_UPGRADE: felt252 = 'only owner can upgrade'; const OWNER_ONLY_UPDATE: felt252 = 'only owner can update'; const NAMESPACE_ALREADY_REGISTERED: felt252 = 'namespace already registered'; + const NO_ACCESS_TO_MEMBERS: felt252 = 'cannot access to model members'; + const INVALID_MEMBER_ID: felt252 = 'invalid member id'; + const DELETE_ENTITY_MEMBER: felt252 = 'cannot delete entity member'; const UNEXPECTED_ERROR: felt252 = 'unexpected error'; } @@ -126,7 +129,7 @@ mod world { use dojo::resource_metadata::ResourceMetadata; use dojo::utils::entity_id_from_keys; - use super::Errors; + use super::{Errors, ModelIndex}; const WORLD: felt252 = 0; @@ -222,7 +225,7 @@ mod world { #[derive(Drop, starknet::Event)] struct StoreUpdateRecord { - model_id: felt252, + table: felt252, entity_id: felt252, values: Span, } @@ -499,20 +502,20 @@ mod world { /// /// # Arguments /// - /// * `model_id` - The model selector. + /// * `model_selector` - The model selector. /// * `contract` - The name of the contract. /// /// # Returns /// /// * `bool` - True if the contract can write to the model, false otherwise fn can_write_model( - self: @ContractState, model_id: felt252, contract: ContractAddress + self: @ContractState, model_selector: felt252, contract: ContractAddress ) -> bool { // TODO: use match self.resources... directly when https://github.com/starkware-libs/cairo/pull/5743 fixed - let resource: ResourceData = self.resources.read(model_id); + let resource: ResourceData = self.resources.read(model_selector); match resource { ResourceData::Model((_, model_address)) => self - ._check_model_write_access(model_id, model_address, contract), + ._check_model_write_access(model_selector, model_address, contract), _ => panic_with_felt252(Errors::INVALID_RESOURCE_SELECTOR) } } @@ -747,140 +750,87 @@ mod world { emit_event_syscall(keys.span(), values).unwrap_syscall(); } - /// Sets the model value for an entity. - /// - /// # Arguments - /// - /// * `model` - The selector of the model to be set. - /// * `keys` - The key to be used to find the entity. - /// * `value_names` - The name of model fields which are not a key. - /// * `values` - The value to be set. - /// * `layout` - The memory layout of the entity. - fn set_entity( - ref self: ContractState, - model: felt252, - keys: Span, - values: Span, + fn entity( + self: @ContractState, + model_selector: felt252, + index: ModelIndex, layout: dojo::database::introspect::Layout - ) { - assert( - self.can_write_model(model, get_caller_address()), Errors::NO_MODEL_WRITE_ACCESS - ); - - let entity_id = entity_id_from_keys(keys); - self._write_model_entity(model, entity_id, values, layout); - EventEmitter::emit(ref self, StoreSetRecord { table: model, keys, values }); + ) -> Span { + match index { + ModelIndex::Keys(keys) => { + let entity_id = entity_id_from_keys(keys); + self._read_model_entity(model_selector, entity_id, layout) + }, + ModelIndex::Id(entity_id) => { + self._read_model_entity(model_selector, entity_id, layout) + }, + ModelIndex::MemberId(( + entity_id, member_id + )) => { self._read_model_member(model_selector, entity_id, member_id, layout) } + } } - /// Sets the model value for an entity. - /// - /// # Arguments - /// - /// * `model` - The selector of the model to be set. - /// * `entity_id` - The id of the entity to set. - /// * `value_names` - The name of model fields which are not a key. - /// * `values` - The value to be set. - /// * `layout` - The memory layout of the entity. - fn set_entity_by_id( + fn set_entity( ref self: ContractState, - model_id: felt252, - entity_id: felt252, + model_selector: felt252, + index: ModelIndex, values: Span, layout: dojo::database::introspect::Layout ) { assert( - self.can_write_model(model_id, get_caller_address()), Errors::NO_MODEL_WRITE_ACCESS + self.can_write_model(model_selector, get_caller_address()), + Errors::NO_MODEL_WRITE_ACCESS ); - self._write_model_entity(model_id, entity_id, values, layout); - EventEmitter::emit(ref self, StoreUpdateRecord { model_id, entity_id, values }); + match index { + ModelIndex::Keys(keys) => { + let entity_id = entity_id_from_keys(keys); + self._write_model_entity(model_selector, entity_id, values, layout); + EventEmitter::emit( + ref self, StoreSetRecord { table: model_selector, keys, values } + ); + }, + ModelIndex::Id(entity_id) => { + self._write_model_entity(model_selector, entity_id, values, layout); + EventEmitter::emit( + ref self, StoreUpdateRecord { table: model_selector, entity_id, values } + ); + }, + ModelIndex::MemberId(( + entity_id, member_id + )) => { + self._write_model_member(model_selector, entity_id, member_id, values, layout) + } + } } - /// Deletes an existing entity. - /// Deleting is setting all the values to 0 in the given layout. - /// - /// # Arguments - /// - /// * `model` - The selector of the model to be deleted. - /// * `keys` - The key to be used to find the entity. - /// * `value_names` - The name of model fields which are not a key. - /// * `layout` - The memory layout of the entity. fn delete_entity( ref self: ContractState, - model: felt252, - keys: Span, - layout: dojo::database::introspect::Layout - ) { - let entity_id = entity_id_from_keys(keys); - self.delete_entity_by_id(model, entity_id, layout); - } - - /// Deletes an existing entity. - /// Deleting is setting all the values to 0 in the given layout. - /// - /// # Arguments - /// - /// * `model_id` - The selector of the model to be deleted. - /// * `entity_id` - The id to be used to find the entity. - /// * `value_names` - The name of model fields which are not a key. - /// * `layout` - The memory layout of the entity. - fn delete_entity_by_id( - ref self: ContractState, - model_id: felt252, - entity_id: felt252, + model_selector: felt252, + index: ModelIndex, layout: dojo::database::introspect::Layout ) { assert( - self.can_write_model(model_id, get_caller_address()), Errors::NO_MODEL_WRITE_ACCESS + self.can_write_model(model_selector, get_caller_address()), + Errors::NO_MODEL_WRITE_ACCESS ); - self._delete_model_entity(model_id, entity_id, layout); - EventEmitter::emit(ref self, StoreDelRecord { table: model_id, entity_id }); - } - - /// Gets the model value for an entity. Returns a zero initialized - /// model value if the entity has not been set. - /// - /// # Arguments - /// - /// * `model` - The selector of the model to be retrieved. - /// * `keys` - The keys used to find the entity. - /// * `value_names` - The name of model fields which are not a key. - /// * `layout` - The memory layout of the entity. - /// - /// # Returns - /// - /// * `Span` - The serialized value of the model, zero initialized if not set. - fn entity( - self: @ContractState, - model: felt252, - keys: Span, - layout: dojo::database::introspect::Layout - ) -> Span { - let entity_id = entity_id_from_keys(keys); - self._read_model_entity(model, entity_id, layout) - } - - /// Gets the model value for an entity. Returns a zero initialized - /// model value if the entity has not been set. - /// - /// # Arguments - /// - /// * `model` - The selector of the model to be retrieved. - /// * `entity_id` - The id used to find the entity. - /// * `value_names` - The name of model fields which are not a key. - /// * `layout` - The memory layout of the entity. - /// - /// # Returns - /// - /// * `Span` - The serialized value of the model, zero initialized if not set. - fn entity_by_id( - self: @ContractState, - model_id: felt252, - entity_id: felt252, - layout: dojo::database::introspect::Layout - ) -> Span { - self._read_model_entity(model_id, entity_id, layout) + match index { + ModelIndex::Keys(keys) => { + let entity_id = entity_id_from_keys(keys); + self._delete_model_entity(model_selector, entity_id, layout); + EventEmitter::emit( + ref self, StoreDelRecord { table: model_selector, entity_id } + ); + }, + ModelIndex::Id(entity_id) => { + self._delete_model_entity(model_selector, entity_id, layout); + EventEmitter::emit( + ref self, StoreDelRecord { table: model_selector, entity_id } + ); + }, + ModelIndex::MemberId(_) => { panic_with_felt252(Errors::DELETE_ENTITY_MEMBER); } + } } /// Gets the base contract class hash. @@ -1037,7 +987,7 @@ mod world { /// - the calling account has the owner and/or writer role for the model namespace. /// /// # Arguments - /// * `model_id` - the model selector to check. + /// * `model_selector` - the model selector to check. /// * `model_address` - the model contract address. /// * `contract` - the calling contract. /// @@ -1046,13 +996,13 @@ mod world { /// fn _check_model_write_access( self: @ContractState, - model_id: felt252, + model_selector: felt252, model_address: ContractAddress, contract: ContractAddress ) -> bool { - if !self.is_writer(model_id, contract) - && !self.is_account_owner(model_id) - && !self.is_account_writer(model_id) { + if !self.is_writer(model_selector, contract) + && !self.is_account_owner(model_selector) + && !self.is_account_writer(model_selector) { let model = IModelDispatcher { contract_address: model_address }; self._check_basic_write_access(model.namespace_hash(), contract) } else { @@ -1080,16 +1030,26 @@ mod world { || self.is_account_writer(resource_id) } + /// + fn _can_access_model_members( + self: @ContractState, layout: dojo::database::introspect::Layout + ) -> bool { + match layout { + dojo::database::introspect::Layout::Struct(_) => true, + _ => false + } + } + /// Write a new entity. /// /// # Arguments - /// * `model_id` - the model selector + /// * `model_selector` - the model selector /// * `entity_id` - the id used to identify the record /// * `values` - the field values of the record /// * `layout` - the model layout fn _write_model_entity( ref self: ContractState, - model_id: felt252, + model_selector: felt252, entity_id: felt252, values: Span, layout: dojo::database::introspect::Layout @@ -1098,10 +1058,14 @@ mod world { match layout { Layout::Fixed(layout) => { - Self::_write_fixed_layout(model_id, entity_id, values, ref offset, layout); + Self::_write_fixed_layout( + model_selector, entity_id, values, ref offset, layout + ); }, Layout::Struct(layout) => { - Self::_write_struct_layout(model_id, entity_id, values, ref offset, layout); + Self::_write_struct_layout( + model_selector, entity_id, values, ref offset, layout + ); }, _ => { panic!("Unexpected layout type for a model."); } }; @@ -1115,16 +1079,16 @@ mod world { /// * `layout` - the model layout fn _delete_model_entity( ref self: ContractState, - model_id: felt252, + model_selector: felt252, entity_id: felt252, layout: dojo::database::introspect::Layout ) { match layout { Layout::Fixed(layout) => { - Self::_delete_fixed_layout(model_id, entity_id, layout); + Self::_delete_fixed_layout(model_selector, entity_id, layout); }, Layout::Struct(layout) => { - Self::_delete_struct_layout(model_id, entity_id, layout); + Self::_delete_struct_layout(model_selector, entity_id, layout); }, _ => { panic!("Unexpected layout type for a model."); } }; @@ -1138,7 +1102,7 @@ mod world { /// * `layout` - the model layout fn _read_model_entity( self: @ContractState, - model_id: felt252, + model_selector: felt252, entity_id: felt252, layout: dojo::database::introspect::Layout ) -> Span { @@ -1146,10 +1110,10 @@ mod world { match layout { Layout::Fixed(layout) => { - Self::_read_fixed_layout(model_id, entity_id, ref read_data, layout); + Self::_read_fixed_layout(model_selector, entity_id, ref read_data, layout); }, Layout::Struct(layout) => { - Self::_read_struct_layout(model_id, entity_id, ref read_data, layout); + Self::_read_struct_layout(model_selector, entity_id, ref read_data, layout); }, _ => { panic!("Unexpected layout type for a model."); } }; @@ -1157,9 +1121,40 @@ mod world { read_data.span() } - /// Compute the full field key from parent key and current field key. - fn _field_key(parent_key: felt252, field_key: felt252) -> felt252 { - poseidon::poseidon_hash_span(array![parent_key, field_key].span()) + /// + fn _read_model_member( + self: @ContractState, + model_selector: felt252, + entity_id: felt252, + member_id: felt252, + layout: dojo::database::introspect::Layout + ) -> Span { + let mut read_data = ArrayTrait::::new(); + Self::_read_layout( + model_selector, Self::_combine_key(entity_id, member_id), ref read_data, layout + ); + + read_data.span() + } + + /// + fn _write_model_member( + self: @ContractState, + model_selector: felt252, + entity_id: felt252, + member_id: felt252, + values: Span, + layout: dojo::database::introspect::Layout + ) { + let mut offset = 0; + Self::_write_layout( + model_selector, Self::_combine_key(entity_id, member_id), values, ref offset, layout + ) + } + + /// Combine parent and child keys to build one full key. + fn _combine_key(parent_key: felt252, child_key: felt252) -> felt252 { + poseidon::poseidon_hash_span(array![parent_key, child_key].span()) } /// Append some values to an array. @@ -1280,7 +1275,7 @@ mod world { if i >= array_len { break; } - let key = Self::_field_key(key, i.into()); + let key = Self::_combine_key(key, i.into()); Self::_write_layout(model, key, values, ref offset, item_layout); @@ -1338,7 +1333,7 @@ mod world { } let field_layout = *layout.at(i); - let field_key = Self::_field_key(key, field_layout.selector); + let field_key = Self::_combine_key(key, field_layout.selector); Self::_write_layout(model, field_key, values, ref offset, field_layout.layout); @@ -1368,7 +1363,7 @@ mod world { } let field_layout = *layout.at(i); - let key = Self::_field_key(key, i.into()); + let key = Self::_combine_key(key, i.into()); Self::_write_layout(model, key, values, ref offset, field_layout); @@ -1392,7 +1387,7 @@ mod world { offset += 1; // find the corresponding layout and then write the full variant - let variant_data_key = Self::_field_key(key, variant); + let variant_data_key = Self::_combine_key(key, variant); match Self::_find_variant_layout(variant, variant_layouts) { Option::Some(layout) => Self::_write_layout( @@ -1467,7 +1462,7 @@ mod world { } let field_layout = *layout.at(i); - let key = Self::_field_key(key, field_layout.selector); + let key = Self::_combine_key(key, field_layout.selector); Self::_delete_layout(model, key, field_layout.layout); @@ -1489,7 +1484,7 @@ mod world { } let field_layout = *layout.at(i); - let key = Self::_field_key(key, i.into()); + let key = Self::_combine_key(key, i.into()); Self::_delete_layout(model, key, field_layout); @@ -1509,7 +1504,7 @@ mod world { database::delete(model, key, array![251].span()); // find the corresponding layout and the delete the full variant - let variant_data_key = Self::_field_key(key, variant); + let variant_data_key = Self::_combine_key(key, variant); match Self::_find_variant_layout(variant, variant_layouts) { Option::Some(layout) => Self::_delete_layout(model, variant_data_key, layout), @@ -1587,7 +1582,7 @@ mod world { break; } - let field_key = Self::_field_key(key, i.into()); + let field_key = Self::_combine_key(key, i.into()); Self::_read_layout(model, field_key, ref read_data, item_layout); i += 1; @@ -1638,7 +1633,7 @@ mod world { } let field_layout = *layout.at(i); - let field_key = Self::_field_key(key, field_layout.selector); + let field_key = Self::_combine_key(key, field_layout.selector); Self::_read_layout(model, field_key, ref read_data, field_layout.layout); @@ -1663,7 +1658,7 @@ mod world { } let field_layout = *layout.at(i); - let field_key = Self::_field_key(key, i.into()); + let field_key = Self::_combine_key(key, i.into()); Self::_read_layout(model, field_key, ref read_data, field_layout); i += 1; @@ -1686,7 +1681,7 @@ mod world { read_data.append(variant); // find the corresponding layout and the read the variant data - let variant_data_key = Self::_field_key(key, variant); + let variant_data_key = Self::_combine_key(key, variant); match Self::_find_variant_layout(variant, variant_layouts) { Option::Some(layout) => Self::_read_layout( diff --git a/crates/dojo-core/src/world_test.cairo b/crates/dojo-core/src/world_test.cairo index dd3f2cb2d3..ed3f4e45b9 100644 --- a/crates/dojo-core/src/world_test.cairo +++ b/crates/dojo-core/src/world_test.cairo @@ -325,7 +325,7 @@ mod bar { .read() .delete_entity( dojo::model::Model::::selector(), - array![get_caller_address().into()].span(), + dojo::model::ModelIndex::Keys(array![get_caller_address().into()].span()), dojo::model::Model::::layout() ); } @@ -967,8 +967,8 @@ fn test_set_entity_by_id() { let values = create_foo(); let layout = dojo::model::Model::::layout(); - world.set_entity_by_id(selector, entity_id, values, layout); - let read_values = world.entity_by_id(selector, entity_id, layout); + world.set_entity(selector, dojo::model::ModelIndex::Id(entity_id), values, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Id(entity_id), layout); assert_array(read_values, values); } @@ -981,8 +981,8 @@ fn test_set_entity_with_fixed_layout() { let values = create_foo(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, get_key_test(), values, layout); - let read_values = world.entity(selector, keys, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(get_key_test()), values, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -996,9 +996,9 @@ fn test_set_entity_with_struct_layout() { let values = create_struct_simple_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1012,9 +1012,9 @@ fn test_set_entity_with_struct_tuple_layout() { let values = create_struct_with_tuple(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1029,16 +1029,16 @@ fn test_set_entity_with_struct_enum_layout() { let layout = dojo::model::Model::::layout(); // test with the first variant - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); // then override with the second variant let values = create_struct_with_enum_second_variant(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1052,9 +1052,9 @@ fn test_set_entity_with_struct_simple_array_layout() { let values = create_struct_simple_array_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1068,9 +1068,9 @@ fn test_set_entity_with_struct_complex_array_layout() { let values = create_struct_complex_array_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1084,9 +1084,9 @@ fn test_set_entity_with_struct_layout_and_byte_array() { let values = create_struct_byte_array_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1100,9 +1100,9 @@ fn test_set_entity_with_nested_elements() { let values = create_struct_nested_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1128,16 +1128,16 @@ fn test_set_entity_with_struct_generics_enum_layout() { let layout = dojo::model::Model::::layout(); // test with the first variant - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); // then override with the second variant let values = create_struct_generic_second_variant(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert_array(read_values, values); } @@ -1150,11 +1150,11 @@ fn test_delete_entity_by_id() { let values = create_foo(); let layout = dojo::model::Model::::layout(); - world.set_entity_by_id(selector, entity_id, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Id(entity_id), values, layout); - world.delete_entity_by_id(selector, entity_id, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Id(entity_id), layout); - let read_values = world.entity_by_id(selector, entity_id, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Id(entity_id), layout); assert!(read_values.len() == values.len()); assert_empty_array(read_values); @@ -1169,11 +1169,11 @@ fn test_delete_entity_with_fixed_layout() { let values = create_foo(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, get_key_test(), values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(get_key_test()), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == values.len()); assert_empty_array(read_values); @@ -1189,11 +1189,11 @@ fn test_delete_entity_with_simple_struct_layout() { let values = create_struct_simple_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == values.len()); assert_empty_array(read_values); @@ -1209,11 +1209,11 @@ fn test_delete_entity_with_struct_simple_array_layout() { let values = create_struct_simple_array_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); // array length set to 0, so the expected value span is shorter than the initial values let expected_values = array![0, 0, 0].span(); @@ -1233,11 +1233,11 @@ fn test_delete_entity_with_complex_array_struct_layout() { let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); // array length set to 0, so the expected value span is shorter than the initial values let expected_values = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); @@ -1256,12 +1256,12 @@ fn test_delete_entity_with_struct_tuple_layout() { let values = create_struct_with_tuple(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); let expected_values = array![0, 0].span(); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == expected_values.len()); assert_empty_array(read_values); @@ -1278,12 +1278,12 @@ fn test_delete_entity_with_struct_enum_layout() { let layout = dojo::model::Model::::layout(); // test with the first variant - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); let expected_values = array![0, 0, 0].span(); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == expected_values.len()); assert_empty_array(read_values); @@ -1299,12 +1299,12 @@ fn test_delete_entity_with_struct_layout_and_byte_array() { let values = create_struct_byte_array_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); let expected_values = array![0, 0, 0, 0].span(); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == expected_values.len()); assert_empty_array(read_values); @@ -1320,12 +1320,12 @@ fn test_delete_entity_with_nested_elements() { let values = create_struct_nested_model(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); let expected_values = array![0, 0, 0, 0, 0, 0, 0, 0, 0].span(); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == expected_values.len()); assert_empty_array(read_values); @@ -1341,12 +1341,12 @@ fn test_delete_entity_with_struct_generics_enum_layout() { let values = create_struct_generic_first_variant(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); - world.delete_entity(selector, keys, layout); + world.delete_entity(selector, dojo::model::ModelIndex::Keys(keys), layout); let expected_values = array![0, 0].span(); - let read_values = world.entity(selector, keys, layout); + let read_values = world.entity(selector, dojo::model::ModelIndex::Keys(keys), layout); assert!(read_values.len() == expected_values.len()); assert_empty_array(read_values); @@ -1365,7 +1365,7 @@ fn test_set_entity_with_unexpected_array_model_layout() { world .set_entity( dojo::model::Model::::selector(), - array![].span(), + dojo::model::ModelIndex::Keys(array![].span()), array![].span(), layout ); @@ -1384,7 +1384,7 @@ fn test_set_entity_with_unexpected_tuple_model_layout() { world .set_entity( dojo::model::Model::::selector(), - array![].span(), + dojo::model::ModelIndex::Keys(array![].span()), array![].span(), layout ); @@ -1402,7 +1402,9 @@ fn test_delete_entity_with_unexpected_array_model_layout() { world .delete_entity( - dojo::model::Model::::selector(), array![].span(), layout + dojo::model::Model::::selector(), + dojo::model::ModelIndex::Keys(array![].span()), + layout ); } @@ -1418,7 +1420,9 @@ fn test_delete_entity_with_unexpected_tuple_model_layout() { world .delete_entity( - dojo::model::Model::::selector(), array![].span(), layout + dojo::model::Model::::selector(), + dojo::model::ModelIndex::Keys(array![].span()), + layout ); } @@ -1432,7 +1436,12 @@ fn test_get_entity_with_unexpected_array_model_layout() { array![dojo::database::introspect::Introspect::::layout()].span() ); - world.entity(dojo::model::Model::::selector(), array![].span(), layout); + world + .entity( + dojo::model::Model::::selector(), + dojo::model::ModelIndex::Keys(array![].span()), + layout + ); } #[test] @@ -1445,7 +1454,12 @@ fn test_get_entity_with_unexpected_tuple_model_layout() { array![dojo::database::introspect::Introspect::::layout()].span() ); - world.entity(dojo::model::Model::::selector(), array![].span(), layout); + world + .entity( + dojo::model::Model::::selector(), + dojo::model::ModelIndex::Keys(array![].span()), + layout + ); } @@ -1459,7 +1473,7 @@ fn test_set_entity_with_bad_values_length_error_for_array_layout() { let keys = get_key_test(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, array![1].span(), layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), array![1].span(), layout); } #[test] @@ -1476,7 +1490,7 @@ fn test_set_entity_with_too_big_array_length() { .span(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); } #[test] @@ -1493,7 +1507,7 @@ fn test_set_entity_with_struct_layout_and_bad_byte_array_length() { .span(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); } #[test] @@ -1507,7 +1521,7 @@ fn test_set_entity_with_struct_layout_and_bad_value_length_for_byte_array() { let values: Span = array![1, 3, 'first', 'second', 'third', 'pending'].span(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, keys, values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(keys), values, layout); } fn write_foo_record(world: dojo::world::IWorldDispatcher) { @@ -1515,7 +1529,7 @@ fn write_foo_record(world: dojo::world::IWorldDispatcher) { let values = create_foo(); let layout = dojo::model::Model::::layout(); - world.set_entity(selector, get_key_test(), values, layout); + world.set_entity(selector, dojo::model::ModelIndex::Keys(get_key_test()), values, layout); } #[test] diff --git a/crates/dojo-lang/src/inline_macros/delete.rs b/crates/dojo-lang/src/inline_macros/delete.rs index 51b3e56229..efbcc543c4 100644 --- a/crates/dojo-lang/src/inline_macros/delete.rs +++ b/crates/dojo-lang/src/inline_macros/delete.rs @@ -145,12 +145,9 @@ impl InlineMacroExprPlugin for DeleteMacro { builder.add_str(&format!( " - let __delete_macro_value__ = {}; - {}.delete_entity( - dojo::model::Model::instance_selector(@__delete_macro_value__), - dojo::model::Model::keys(@__delete_macro_value__), - dojo::model::Model::instance_layout(@__delete_macro_value__) - );", + let __delete_model_instance__ = {}; + dojo::model::Model::delete(@__delete_model_instance__, {}); + ", entity, world.as_syntax_node().get_text(db), )); diff --git a/crates/dojo-lang/src/inline_macros/get.rs b/crates/dojo-lang/src/inline_macros/get.rs index 91cba669fd..e37c9dc83e 100644 --- a/crates/dojo-lang/src/inline_macros/get.rs +++ b/crates/dojo-lang/src/inline_macros/get.rs @@ -109,9 +109,7 @@ impl InlineMacroExprPlugin for GetMacro { builder.add_str(&format!( "\n - let __{model}_layout__ = dojo::model::Model::<{model}>::layout(); - let __{model}: {model} = dojo::model::Model::entity({}, __get_macro_keys__, \ - __{model}_layout__);\n", + let __{model}: {model} = dojo::model::Model::get({}, __get_macro_keys__);\n", world.as_syntax_node().get_text(db), )); } diff --git a/crates/dojo-lang/src/inline_macros/set.rs b/crates/dojo-lang/src/inline_macros/set.rs index 493384644e..7c7c5d3925 100644 --- a/crates/dojo-lang/src/inline_macros/set.rs +++ b/crates/dojo-lang/src/inline_macros/set.rs @@ -160,12 +160,8 @@ impl InlineMacroExprPlugin for SetMacro { builder.add_str(&format!( " let __set_model_instance__ = {}; - {}.set_entity( - dojo::model::Model::instance_selector(@__set_model_instance__), - dojo::model::Model::keys(@__set_model_instance__), - dojo::model::Model::values(@__set_model_instance__), - dojo::model::Model::instance_layout(@__set_model_instance__), - );", + dojo::model::Model::set(@__set_model_instance__, {}); + ", entity, world.as_syntax_node().get_text(db), )); diff --git a/crates/dojo-lang/src/introspect/layout.rs b/crates/dojo-lang/src/introspect/layout.rs index 216b00678c..9a8b929965 100644 --- a/crates/dojo-lang/src/introspect/layout.rs +++ b/crates/dojo-lang/src/introspect/layout.rs @@ -27,7 +27,7 @@ pub fn build_field_layouts( } let field_name = m.name(db).text(db); - let field_selector = get_selector_from_name(field_name.as_str()).unwrap().to_string(); + let field_selector = get_selector_from_name(&field_name.to_string()).unwrap(); let field_layout = get_layout_from_type_clause(db, diagnostics, &m.type_clause(db)); Some(format!( "dojo::database::introspect::FieldLayout {{ diff --git a/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/abis/dojo-world.json b/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/abis/dojo-world.json index 38a76d87cb..6dd9a18e1a 100644 --- a/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/abis/dojo-world.json +++ b/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/abis/dojo-world.json @@ -46,6 +46,24 @@ } ] }, + { + "type": "enum", + "name": "dojo::world::ModelIndex", + "variants": [ + { + "name": "Keys", + "type": "core::array::Span::" + }, + { + "name": "Id", + "type": "core::felt252" + }, + { + "name": "MemberId", + "type": "(core::felt252, core::felt252)" + } + ] + }, { "type": "struct", "name": "core::array::Span::", @@ -282,36 +300,12 @@ "name": "entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [ - { - "type": "core::array::Span::" - } - ], - "state_mutability": "view" - }, - { - "type": "function", - "name": "entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -330,36 +324,12 @@ "name": "set_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "values", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "set_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "values", @@ -378,32 +348,12 @@ "name": "delete_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "delete_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -553,7 +503,7 @@ "name": "can_write_model", "inputs": [ { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { @@ -973,7 +923,7 @@ "kind": "struct", "members": [ { - "name": "model_id", + "name": "table", "type": "core::felt252", "kind": "data" }, diff --git a/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/dojo-world.toml b/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/dojo-world.toml index bf10b52348..03f06ebea5 100644 --- a/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/dojo-world.toml +++ b/crates/dojo-lang/src/manifest_test_data/compiler_cairo/manifests/dev/base/dojo-world.toml @@ -1,6 +1,6 @@ kind = "Class" -class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" -original_class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" +class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" +original_class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" abi = "manifests/dev/base/abis/dojo-world.json" tag = "dojo-world" manifest_name = "dojo-world" diff --git a/crates/dojo-lang/src/model.rs b/crates/dojo-lang/src/model.rs index 77795a2e5a..7a10d554e4 100644 --- a/crates/dojo-lang/src/model.rs +++ b/crates/dojo-lang/src/model.rs @@ -13,6 +13,7 @@ use cairo_lang_utils::unordered_hash_map::UnorderedHashMap; use convert_case::{Case, Casing}; use dojo_world::contracts::naming; use dojo_world::manifest::Member; +use starknet::core::utils::get_selector_from_name; use crate::plugin::{DojoAuxData, Model, DOJO_MODEL_ATTR}; use crate::utils::is_name_valid; @@ -244,6 +245,8 @@ pub fn handle_model_struct( let mut serialized_keys: Vec = vec![]; let mut serialized_param_keys: Vec = vec![]; let mut serialized_values: Vec = vec![]; + let mut field_accessors: Vec = vec![]; + let mut field_value_accessors: Vec = vec![]; let elements = struct_ast.members(db).elements(db); elements.iter().for_each(|member_ast| { @@ -265,6 +268,17 @@ pub fn handle_model_struct( members.push(member); }); + let param_keys = param_keys.join(", "); + + members.iter().filter(|m| !m.key).for_each(|member| { + field_accessors.push(generate_field_accessors( + model_name.clone(), + param_keys.clone(), + serialized_param_keys.clone(), + member, + )); + field_value_accessors.push(generate_field_value_accessors(model_name.clone(), member)); + }); if serialized_keys.is_empty() { diagnostics.push(PluginDiagnostic { @@ -293,92 +307,145 @@ pub fn handle_model_struct( RewriteNode::interpolate_patched( " #[derive(Drop, Serde)] -pub struct $type_name$Values { +pub struct $type_name$Entity { + __id: felt252, // private field $members_values$ } + +#[generate_trait] +impl $type_name$EntityImpl of $type_name$EntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> $type_name$Entity { + $type_name$ModelEntityImpl::get(world, entity_id) + } + + $field_value_accessors$ +} + #[generate_trait] -impl $type_name$Model of $type_name$Trait { +impl $type_name$Impl of $type_name$Trait { fn entity_id_from_keys($param_keys$) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); $serialized_param_keys$ core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, $param_keys$) -> $type_name$ { let mut serialized = core::array::ArrayTrait::new(); $serialized_param_keys$ - dojo::model::Model::<$type_name$>::entity( - world, - serialized.span(), - dojo::model::Model::<$type_name$>::layout() - ) - } - fn set(self: @$type_name$, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::<$type_name$>::set_entity( - world, - dojo::model::Model::<$type_name$>::keys(self), - dojo::model::Model::<$type_name$>::values(self), - dojo::model::Model::<$type_name$>::layout() - ) - } - fn delete(self: @$type_name$, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::<$type_name$>::delete_entity( - world, - dojo::model::Model::<$type_name$>::keys(self), - dojo::model::Model::<$type_name$>::layout() - ) + + dojo::model::Model::<$type_name$>::get(world, serialized.span()) } + + $field_accessors$ } -impl $type_name$ModelValues of dojo::model::ModelValues<$type_name$Values> { - fn values(self: @$type_name$Values) -> Span { + +impl $type_name$ModelEntityImpl of dojo::model::ModelEntity<$type_name$Entity> { + fn id(self: @$type_name$Entity) -> felt252 { + *self.__id + } + + fn values(self: @$type_name$Entity) -> Span { let mut serialized = core::array::ArrayTrait::new(); $serialized_values$ core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> $type_name$Values { - let mut serialized = values; - let entity_values = core::serde::Serde::<$type_name$Values>::deserialize(ref serialized); - if core::option::OptionTrait::<$type_name$Values>::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> $type_name$Entity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::<$type_name$Entity>::deserialize(ref serialized); + if core::option::OptionTrait::<$type_name$Entity>::is_none(@entity_values) { panic!( - \"ModelValues `$type_name$Values`: deserialization failed.\" + \"ModelEntity `$type_name$Entity`: deserialization failed.\" ); } - core::option::OptionTrait::<$type_name$Values>::unwrap(entity_values) + core::option::OptionTrait::<$type_name$Entity>::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> $type_name$Values { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> $type_name$Entity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::<$type_name$>::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::<$type_name$>::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @$type_name$Values, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::<$type_name$>::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::<$type_name$>::layout() ); } - fn delete(self: @$type_name$Values, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::<$type_name$>::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::<$type_name$>::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::<$type_name$>::layout(), \ + member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::<$type_name$>::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @$type_name$Entity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::<$type_name$>::layout(), \ + member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::<$type_name$>::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl $type_name$Impl of dojo::model::Model<$type_name$> { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: \ - dojo::database::introspect::Layout) -> $type_name$ { + +impl $type_name$ModelImpl of dojo::model::Model<$type_name$> { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> $type_name$ { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -400,34 +467,70 @@ impl $type_name$Impl of dojo::model::Model<$type_name$> { core::option::OptionTrait::<$type_name$>::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @$type_name$, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @$type_name$, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @$type_name$, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { \"$type_name$\" @@ -467,7 +570,7 @@ impl $type_name$Impl of dojo::model::Model<$type_name$> { fn namespace_hash() -> felt252 { $model_namespace_hash$ } - + #[inline(always)] fn entity_id(self: @$type_name$) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -598,11 +701,16 @@ mod $contract_name$ { ), ("model_tag".to_string(), RewriteNode::Text(model_tag.clone())), ("members_values".to_string(), RewriteNode::new_modified(members_values)), - ("param_keys".to_string(), RewriteNode::Text(param_keys.join(", "))), + ("param_keys".to_string(), RewriteNode::Text(param_keys)), ( "serialized_param_keys".to_string(), RewriteNode::new_modified(serialized_param_keys), ), + ("field_accessors".to_string(), RewriteNode::new_modified(field_accessors)), + ( + "field_value_accessors".to_string(), + RewriteNode::new_modified(field_value_accessors), + ), ]), ), diagnostics, @@ -650,3 +758,118 @@ fn serialize_member_ty(member: &Member, with_self: bool) -> RewriteNode { )), } } + +/// TODO +fn generate_field_accessors( + type_name: String, + param_keys: String, + serialized_param_keys: Vec, + member: &Member, +) -> RewriteNode { + RewriteNode::interpolate_patched( + " + fn get_$field_name$(world: dojo::world::IWorldDispatcher, $param_keys$) -> $field_type$ { + let mut serialized = core::array::ArrayTrait::new(); + $serialized_param_keys$ + + let values = dojo::model::Model::<$type_name$>::get_member( + world, + serialized.span(), + $field_selector$ + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::<$field_type$>::deserialize(ref serialized); + + if core::option::OptionTrait::<$field_type$>::is_none(@field_value) { + panic!( + \"Field `$type_name$::$field_name$`: deserialization failed.\" + ); + } + + core::option::OptionTrait::<$field_type$>::unwrap(field_value) + } + + fn set_$field_name$(self: @$type_name$, world: dojo::world::IWorldDispatcher, value: \ + $field_type$) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + $field_selector$, + serialized.span() + ); + } + ", + &UnorderedHashMap::from([ + ("type_name".to_string(), RewriteNode::Text(type_name)), + ( + "field_selector".to_string(), + RewriteNode::Text( + get_selector_from_name(&member.name).expect("invalid member name").to_string(), + ), + ), + ("field_name".to_string(), RewriteNode::Text(member.name.clone())), + ("field_type".to_string(), RewriteNode::Text(member.ty.clone())), + ("param_keys".to_string(), RewriteNode::Text(param_keys)), + ("serialized_param_keys".to_string(), RewriteNode::new_modified(serialized_param_keys)), + ]), + ) +} + +/// TODO +fn generate_field_value_accessors(type_name: String, member: &Member) -> RewriteNode { + RewriteNode::interpolate_patched( + " + fn get_$field_name$(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> $field_type$ \ + { + let values = dojo::model::ModelEntity::<$type_name$Entity>::get_member( + world, + entity_id, + $field_selector$ + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::<$field_type$>::deserialize(ref serialized); + + if core::option::OptionTrait::<$field_type$>::is_none(@field_value) { + panic!( + \"Field `$type_name$::$field_name$`: deserialization failed.\" + ); + } + + core::option::OptionTrait::<$field_type$>::unwrap(field_value) + } + + fn set_$field_name$(self: @$type_name$Entity, world: dojo::world::IWorldDispatcher, value: \ + $field_type$) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + $field_selector$, + serialized.span() + ); + } +", + &UnorderedHashMap::from([ + ("type_name".to_string(), RewriteNode::Text(type_name)), + ( + "field_selector".to_string(), + RewriteNode::Text( + get_selector_from_name(&member.name).expect("invalid member name").to_string(), + ), + ), + ("field_name".to_string(), RewriteNode::Text(member.name.clone())), + ("field_type".to_string(), RewriteNode::Text(member.ty.clone())), + ]), + ) +} diff --git a/crates/dojo-lang/src/plugin_test_data/model b/crates/dojo-lang/src/plugin_test_data/model index 5c5dd11b8f..5aa4788092 100644 --- a/crates/dojo-lang/src/plugin_test_data/model +++ b/crates/dojo-lang/src/plugin_test_data/model @@ -396,95 +396,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct BadModelMultipleVersionsValues { +pub struct BadModelMultipleVersionsEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl BadModelMultipleVersionsEntityImpl of BadModelMultipleVersionsEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelMultipleVersionsEntity { + BadModelMultipleVersionsModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelMultipleVersions::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelMultipleVersionsEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl BadModelMultipleVersionsModel of BadModelMultipleVersionsTrait { +impl BadModelMultipleVersionsImpl of BadModelMultipleVersionsTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelMultipleVersions { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @BadModelMultipleVersions, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelMultipleVersions::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @BadModelMultipleVersions, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @BadModelMultipleVersions, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl BadModelMultipleVersionsModelValues of dojo::model::ModelValues { - fn values(self: @BadModelMultipleVersionsValues) -> Span { + +impl BadModelMultipleVersionsModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @BadModelMultipleVersionsEntity) -> felt252 { + *self.__id + } + + fn values(self: @BadModelMultipleVersionsEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> BadModelMultipleVersionsValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> BadModelMultipleVersionsEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `BadModelMultipleVersionsValues`: deserialization failed." + "ModelEntity `BadModelMultipleVersionsEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelMultipleVersionsValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelMultipleVersionsEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @BadModelMultipleVersionsValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @BadModelMultipleVersionsEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @BadModelMultipleVersionsValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @BadModelMultipleVersionsEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelMultipleVersionsEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl BadModelMultipleVersionsImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> BadModelMultipleVersions { + +impl BadModelMultipleVersionsModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> BadModelMultipleVersions { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -505,34 +627,70 @@ impl BadModelMultipleVersionsImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @BadModelMultipleVersions, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @BadModelMultipleVersions, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelMultipleVersions, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "BadModelMultipleVersions" @@ -572,7 +730,7 @@ impl BadModelMultipleVersionsImpl of dojo::model::Model felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @BadModelMultipleVersions) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -731,95 +889,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct BadModelBadVersionTypeValues { +pub struct BadModelBadVersionTypeEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl BadModelBadVersionTypeEntityImpl of BadModelBadVersionTypeEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelBadVersionTypeEntity { + BadModelBadVersionTypeModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelBadVersionType::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelBadVersionTypeEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl BadModelBadVersionTypeModel of BadModelBadVersionTypeTrait { +impl BadModelBadVersionTypeImpl of BadModelBadVersionTypeTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelBadVersionType { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @BadModelBadVersionType, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelBadVersionType::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @BadModelBadVersionType, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @BadModelBadVersionType, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl BadModelBadVersionTypeModelValues of dojo::model::ModelValues { - fn values(self: @BadModelBadVersionTypeValues) -> Span { + +impl BadModelBadVersionTypeModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @BadModelBadVersionTypeEntity) -> felt252 { + *self.__id + } + + fn values(self: @BadModelBadVersionTypeEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> BadModelBadVersionTypeValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> BadModelBadVersionTypeEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `BadModelBadVersionTypeValues`: deserialization failed." + "ModelEntity `BadModelBadVersionTypeEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelBadVersionTypeValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelBadVersionTypeEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @BadModelBadVersionTypeValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @BadModelBadVersionTypeEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @BadModelBadVersionTypeValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @BadModelBadVersionTypeEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelBadVersionTypeEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl BadModelBadVersionTypeImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> BadModelBadVersionType { + +impl BadModelBadVersionTypeModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> BadModelBadVersionType { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -840,34 +1120,70 @@ impl BadModelBadVersionTypeImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @BadModelBadVersionType, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @BadModelBadVersionType, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelBadVersionType, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "BadModelBadVersionType" @@ -907,7 +1223,7 @@ impl BadModelBadVersionTypeImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @BadModelBadVersionType) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -1066,95 +1382,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct BadModelNoVersionValueValues { +pub struct BadModelNoVersionValueEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl BadModelNoVersionValueEntityImpl of BadModelNoVersionValueEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelNoVersionValueEntity { + BadModelNoVersionValueModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelNoVersionValue::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelNoVersionValueEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl BadModelNoVersionValueModel of BadModelNoVersionValueTrait { +impl BadModelNoVersionValueImpl of BadModelNoVersionValueTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelNoVersionValue { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) - } - fn set(self: @BadModelNoVersionValue, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) - } - fn delete(self: @BadModelNoVersionValue, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } -} -impl BadModelNoVersionValueModelValues of dojo::model::ModelValues { - fn values(self: @BadModelNoVersionValueValues) -> Span { + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { let mut serialized = core::array::ArrayTrait::new(); - core::serde::Serde::serialize(self.v, ref serialized); + core::array::ArrayTrait::append(ref serialized, id); - core::array::ArrayTrait::span(@serialized) - } - fn from_values(values: Span) -> BadModelNoVersionValueValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + let values = dojo::model::Model::::get_member( + world, + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelNoVersionValue::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelNoVersionValue, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + +impl BadModelNoVersionValueModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @BadModelNoVersionValueEntity) -> felt252 { + *self.__id + } + + fn values(self: @BadModelNoVersionValueEntity) -> Span { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(self.v, ref serialized); + + core::array::ArrayTrait::span(@serialized) + } + + fn from_values(entity_id: felt252, values: Span) -> BadModelNoVersionValueEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `BadModelNoVersionValueValues`: deserialization failed." + "ModelEntity `BadModelNoVersionValueEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelNoVersionValueValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelNoVersionValueEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @BadModelNoVersionValueValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @BadModelNoVersionValueEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @BadModelNoVersionValueValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @BadModelNoVersionValueEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelNoVersionValueEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl BadModelNoVersionValueImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> BadModelNoVersionValue { + +impl BadModelNoVersionValueModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> BadModelNoVersionValue { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -1175,34 +1613,70 @@ impl BadModelNoVersionValueImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @BadModelNoVersionValue, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @BadModelNoVersionValue, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelNoVersionValue, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "BadModelNoVersionValue" @@ -1242,7 +1716,7 @@ impl BadModelNoVersionValueImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @BadModelNoVersionValue) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -1401,95 +1875,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct BadModelUnexpectedArgWithValueValues { +pub struct BadModelUnexpectedArgWithValueEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl BadModelUnexpectedArgWithValueEntityImpl of BadModelUnexpectedArgWithValueEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelUnexpectedArgWithValueEntity { + BadModelUnexpectedArgWithValueModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelUnexpectedArgWithValue::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelUnexpectedArgWithValueEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl BadModelUnexpectedArgWithValueModel of BadModelUnexpectedArgWithValueTrait { +impl BadModelUnexpectedArgWithValueImpl of BadModelUnexpectedArgWithValueTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelUnexpectedArgWithValue { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @BadModelUnexpectedArgWithValue, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelUnexpectedArgWithValue::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @BadModelUnexpectedArgWithValue, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @BadModelUnexpectedArgWithValue, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl BadModelUnexpectedArgWithValueModelValues of dojo::model::ModelValues { - fn values(self: @BadModelUnexpectedArgWithValueValues) -> Span { + +impl BadModelUnexpectedArgWithValueModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @BadModelUnexpectedArgWithValueEntity) -> felt252 { + *self.__id + } + + fn values(self: @BadModelUnexpectedArgWithValueEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> BadModelUnexpectedArgWithValueValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> BadModelUnexpectedArgWithValueEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `BadModelUnexpectedArgWithValueValues`: deserialization failed." + "ModelEntity `BadModelUnexpectedArgWithValueEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelUnexpectedArgWithValueValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelUnexpectedArgWithValueEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @BadModelUnexpectedArgWithValueValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @BadModelUnexpectedArgWithValueEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @BadModelUnexpectedArgWithValueValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @BadModelUnexpectedArgWithValueEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelUnexpectedArgWithValueEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl BadModelUnexpectedArgWithValueImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> BadModelUnexpectedArgWithValue { + +impl BadModelUnexpectedArgWithValueModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> BadModelUnexpectedArgWithValue { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -1510,34 +2106,70 @@ impl BadModelUnexpectedArgWithValueImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @BadModelUnexpectedArgWithValue, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @BadModelUnexpectedArgWithValue, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelUnexpectedArgWithValue, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "BadModelUnexpectedArgWithValue" @@ -1577,7 +2209,7 @@ impl BadModelUnexpectedArgWithValueImpl of dojo::model::Model felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @BadModelUnexpectedArgWithValue) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -1736,100 +2368,222 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct BadModelUnexpectedArgValues { +pub struct BadModelUnexpectedArgEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl BadModelUnexpectedArgEntityImpl of BadModelUnexpectedArgEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelUnexpectedArgEntity { + BadModelUnexpectedArgModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelUnexpectedArg::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelUnexpectedArgEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl BadModelUnexpectedArgModel of BadModelUnexpectedArgTrait { +impl BadModelUnexpectedArgImpl of BadModelUnexpectedArgTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelUnexpectedArg { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @BadModelUnexpectedArg, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelUnexpectedArg::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @BadModelUnexpectedArg, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @BadModelUnexpectedArg, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl BadModelUnexpectedArgModelValues of dojo::model::ModelValues { - fn values(self: @BadModelUnexpectedArgValues) -> Span { + +impl BadModelUnexpectedArgModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @BadModelUnexpectedArgEntity) -> felt252 { + *self.__id + } + + fn values(self: @BadModelUnexpectedArgEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> BadModelUnexpectedArgValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> BadModelUnexpectedArgEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `BadModelUnexpectedArgValues`: deserialization failed." + "ModelEntity `BadModelUnexpectedArgEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelUnexpectedArgValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelUnexpectedArgEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @BadModelUnexpectedArgValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @BadModelUnexpectedArgEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @BadModelUnexpectedArgValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @BadModelUnexpectedArgEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } -} -impl BadModelUnexpectedArgImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> BadModelUnexpectedArg { - let values = dojo::world::IWorldDispatcherTrait::entity( - world, - Self::selector(), - keys, - layout - ); - // TODO: Generate method to deserialize from keys / values directly to avoid - // serializing to intermediate array. - let mut serialized = core::array::ArrayTrait::new(); + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelUnexpectedArgEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } +} + +impl BadModelUnexpectedArgModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> BadModelUnexpectedArg { + let values = dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::Keys(keys), + Self::layout() + ); + + // TODO: Generate method to deserialize from keys / values directly to avoid + // serializing to intermediate array. + let mut serialized = core::array::ArrayTrait::new(); core::array::serialize_array_helper(keys, ref serialized); core::array::serialize_array_helper(values, ref serialized); let mut serialized = core::array::ArrayTrait::span(@serialized); @@ -1845,34 +2599,70 @@ impl BadModelUnexpectedArgImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @BadModelUnexpectedArg, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @BadModelUnexpectedArg, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelUnexpectedArg, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "BadModelUnexpectedArg" @@ -1912,7 +2702,7 @@ impl BadModelUnexpectedArgImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @BadModelUnexpectedArg) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -2071,95 +2861,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct BadModelNotSupportedVersionValues { +pub struct BadModelNotSupportedVersionEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl BadModelNotSupportedVersionEntityImpl of BadModelNotSupportedVersionEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelNotSupportedVersionEntity { + BadModelNotSupportedVersionModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelNotSupportedVersion::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @BadModelNotSupportedVersionEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl BadModelNotSupportedVersionModel of BadModelNotSupportedVersionTrait { +impl BadModelNotSupportedVersionImpl of BadModelNotSupportedVersionTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelNotSupportedVersion { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @BadModelNotSupportedVersion, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `BadModelNotSupportedVersion::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @BadModelNotSupportedVersion, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @BadModelNotSupportedVersion, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl BadModelNotSupportedVersionModelValues of dojo::model::ModelValues { - fn values(self: @BadModelNotSupportedVersionValues) -> Span { + +impl BadModelNotSupportedVersionModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @BadModelNotSupportedVersionEntity) -> felt252 { + *self.__id + } + + fn values(self: @BadModelNotSupportedVersionEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> BadModelNotSupportedVersionValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> BadModelNotSupportedVersionEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `BadModelNotSupportedVersionValues`: deserialization failed." + "ModelEntity `BadModelNotSupportedVersionEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelNotSupportedVersionValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelNotSupportedVersionEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @BadModelNotSupportedVersionValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @BadModelNotSupportedVersionEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @BadModelNotSupportedVersionValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @BadModelNotSupportedVersionEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelNotSupportedVersionEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl BadModelNotSupportedVersionImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> BadModelNotSupportedVersion { + +impl BadModelNotSupportedVersionModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> BadModelNotSupportedVersion { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -2180,34 +3092,70 @@ impl BadModelNotSupportedVersionImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @BadModelNotSupportedVersion, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @BadModelNotSupportedVersion, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @BadModelNotSupportedVersion, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "BadModelNotSupportedVersion" @@ -2247,7 +3195,7 @@ impl BadModelNotSupportedVersionImpl of dojo::model::Model felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @BadModelNotSupportedVersion) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -2406,95 +3354,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct Modelv0Values { +pub struct Modelv0Entity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl Modelv0EntityImpl of Modelv0EntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Modelv0Entity { + Modelv0ModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `Modelv0::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @Modelv0Entity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl Modelv0Model of Modelv0Trait { +impl Modelv0Impl of Modelv0Trait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> Modelv0 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @Modelv0, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `Modelv0::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @Modelv0, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @Modelv0, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl Modelv0ModelValues of dojo::model::ModelValues { - fn values(self: @Modelv0Values) -> Span { + +impl Modelv0ModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @Modelv0Entity) -> felt252 { + *self.__id + } + + fn values(self: @Modelv0Entity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> Modelv0Values { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> Modelv0Entity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `Modelv0Values`: deserialization failed." + "ModelEntity `Modelv0Entity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> Modelv0Values { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Modelv0Entity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @Modelv0Values, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @Modelv0Entity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @Modelv0Values, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @Modelv0Entity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @Modelv0Entity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl Modelv0Impl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> Modelv0 { + +impl Modelv0ModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> Modelv0 { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -2515,34 +3585,70 @@ impl Modelv0Impl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @Modelv0, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @Modelv0, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @Modelv0, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "Modelv0" @@ -2582,7 +3688,7 @@ impl Modelv0Impl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @Modelv0) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -2741,95 +3847,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct ModelWithBadNamespaceFormatValues { +pub struct ModelWithBadNamespaceFormatEntity { + __id: felt252, // private field v: Vec3, } -#[generate_trait] -impl ModelWithBadNamespaceFormatModel of ModelWithBadNamespaceFormatTrait { - fn entity_id_from_keys(id: felt252) -> felt252 { - let mut serialized = core::array::ArrayTrait::new(); - core::array::ArrayTrait::append(ref serialized, id); - core::poseidon::poseidon_hash_span(serialized.span()) +#[generate_trait] +impl ModelWithBadNamespaceFormatEntityImpl of ModelWithBadNamespaceFormatEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithBadNamespaceFormatEntity { + ModelWithBadNamespaceFormatModelEntityImpl::get(world, entity_id) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithBadNamespaceFormat { - let mut serialized = core::array::ArrayTrait::new(); - core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( world, - serialized.span(), - dojo::model::Model::::layout() - ) + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithBadNamespaceFormat::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn set(self: @ModelWithBadNamespaceFormat, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn set_v(self: @ModelWithBadNamespaceFormatEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + +#[generate_trait] +impl ModelWithBadNamespaceFormatImpl of ModelWithBadNamespaceFormatTrait { + fn entity_id_from_keys(id: felt252) -> felt252 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + core::poseidon::poseidon_hash_span(serialized.span()) } - fn delete(self: @ModelWithBadNamespaceFormat, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithBadNamespaceFormat { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithBadNamespaceFormat::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @ModelWithBadNamespaceFormat, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl ModelWithBadNamespaceFormatModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithBadNamespaceFormatValues) -> Span { + +impl ModelWithBadNamespaceFormatModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithBadNamespaceFormatEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithBadNamespaceFormatEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> ModelWithBadNamespaceFormatValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> ModelWithBadNamespaceFormatEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithBadNamespaceFormatValues`: deserialization failed." + "ModelEntity `ModelWithBadNamespaceFormatEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithBadNamespaceFormatValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithBadNamespaceFormatEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithBadNamespaceFormatValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithBadNamespaceFormatEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithBadNamespaceFormatValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithBadNamespaceFormatEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithBadNamespaceFormatEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithBadNamespaceFormatImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithBadNamespaceFormat { + +impl ModelWithBadNamespaceFormatModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithBadNamespaceFormat { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -2850,34 +4078,70 @@ impl ModelWithBadNamespaceFormatImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithBadNamespaceFormat, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithBadNamespaceFormat, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithBadNamespaceFormat, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithBadNamespaceFormat" @@ -2917,7 +4181,7 @@ impl ModelWithBadNamespaceFormatImpl of dojo::model::Model felt252 { 2518247443458975119180817677753479732439290689944304814934908400279022945373 } - + #[inline(always)] fn entity_id(self: @ModelWithBadNamespaceFormat) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -3076,95 +4340,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct ModelWithShortStringNamespaceValues { +pub struct ModelWithShortStringNamespaceEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl ModelWithShortStringNamespaceEntityImpl of ModelWithShortStringNamespaceEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithShortStringNamespaceEntity { + ModelWithShortStringNamespaceModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithShortStringNamespace::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @ModelWithShortStringNamespaceEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl ModelWithShortStringNamespaceModel of ModelWithShortStringNamespaceTrait { +impl ModelWithShortStringNamespaceImpl of ModelWithShortStringNamespaceTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithShortStringNamespace { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @ModelWithShortStringNamespace, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithShortStringNamespace::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @ModelWithShortStringNamespace, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @ModelWithShortStringNamespace, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl ModelWithShortStringNamespaceModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithShortStringNamespaceValues) -> Span { + +impl ModelWithShortStringNamespaceModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithShortStringNamespaceEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithShortStringNamespaceEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> ModelWithShortStringNamespaceValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> ModelWithShortStringNamespaceEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithShortStringNamespaceValues`: deserialization failed." + "ModelEntity `ModelWithShortStringNamespaceEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithShortStringNamespaceValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithShortStringNamespaceEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithShortStringNamespaceValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithShortStringNamespaceEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithShortStringNamespaceValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithShortStringNamespaceEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithShortStringNamespaceEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithShortStringNamespaceImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithShortStringNamespace { + +impl ModelWithShortStringNamespaceModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithShortStringNamespace { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -3185,34 +4571,70 @@ impl ModelWithShortStringNamespaceImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithShortStringNamespace, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithShortStringNamespace, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithShortStringNamespace, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithShortStringNamespace" @@ -3252,7 +4674,7 @@ impl ModelWithShortStringNamespaceImpl of dojo::model::Model felt252 { 1685136890688416384941629523783652800960468745356230625531475538826800548713 } - + #[inline(always)] fn entity_id(self: @ModelWithShortStringNamespace) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -3411,95 +4833,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct ModelWithStringNamespaceValues { +pub struct ModelWithStringNamespaceEntity { + __id: felt252, // private field v: Vec3, } -#[generate_trait] -impl ModelWithStringNamespaceModel of ModelWithStringNamespaceTrait { - fn entity_id_from_keys(id: felt252) -> felt252 { - let mut serialized = core::array::ArrayTrait::new(); - core::array::ArrayTrait::append(ref serialized, id); - core::poseidon::poseidon_hash_span(serialized.span()) +#[generate_trait] +impl ModelWithStringNamespaceEntityImpl of ModelWithStringNamespaceEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithStringNamespaceEntity { + ModelWithStringNamespaceModelEntityImpl::get(world, entity_id) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithStringNamespace { - let mut serialized = core::array::ArrayTrait::new(); - core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) - } - fn set(self: @ModelWithStringNamespace, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) - } - fn delete(self: @ModelWithStringNamespace, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) - } -} -impl ModelWithStringNamespaceModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithStringNamespaceValues) -> Span { + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + let mut serialized = core::array::ArrayTrait::new(); - core::serde::Serde::serialize(self.v, ref serialized); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); - core::array::ArrayTrait::span(@serialized) - } - fn from_values(values: Span) -> ModelWithStringNamespaceValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { panic!( - "ModelValues `ModelWithStringNamespaceValues`: deserialization failed." + "Field `ModelWithStringNamespace::v`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + + core::option::OptionTrait::::unwrap(field_value) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithStringNamespaceValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn set_v(self: @ModelWithStringNamespaceEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::selector(), - id, - dojo::model::Model::::layout() + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() ); - Self::from_values(values) } - fn update(self: @ModelWithStringNamespaceValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( - world, - dojo::model::Model::::selector(), - id, - self.values(), - dojo::model::Model::::layout() - ); + +} + +#[generate_trait] +impl ModelWithStringNamespaceImpl of ModelWithStringNamespaceTrait { + fn entity_id_from_keys(id: felt252) -> felt252 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + core::poseidon::poseidon_hash_span(serialized.span()) + } + + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithStringNamespace { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( + world, + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithStringNamespace::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @ModelWithStringNamespace, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + +impl ModelWithStringNamespaceModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithStringNamespaceEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithStringNamespaceEntity) -> Span { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(self.v, ref serialized); + + core::array::ArrayTrait::span(@serialized) + } + + fn from_values(entity_id: felt252, values: Span) -> ModelWithStringNamespaceEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { + panic!( + "ModelEntity `ModelWithStringNamespaceEntity`: deserialization failed." + ); + } + core::option::OptionTrait::::unwrap(entity_values) + } + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithStringNamespaceEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::Id(entity_id), + dojo::model::Model::::layout() + ); + Self::from_values(entity_id, values) + } + + fn update(self: @ModelWithStringNamespaceEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::Id(self.id()), + self.values(), + dojo::model::Model::::layout() + ); } - fn delete(self: @ModelWithStringNamespaceValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithStringNamespaceEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithStringNamespaceEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithStringNamespaceImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithStringNamespace { + +impl ModelWithStringNamespaceModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithStringNamespace { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -3520,34 +5064,70 @@ impl ModelWithStringNamespaceImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithStringNamespace, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithStringNamespace, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithStringNamespace, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithStringNamespace" @@ -3587,7 +5167,7 @@ impl ModelWithStringNamespaceImpl of dojo::model::Model felt252 { 1685136890688416384941629523783652800960468745356230625531475538826800548713 } - + #[inline(always)] fn entity_id(self: @ModelWithStringNamespace) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -3746,95 +5326,217 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct PositionValues { +pub struct PositionEntity { + __id: felt252, // private field v: Vec3, } + +#[generate_trait] +impl PositionEntityImpl of PositionEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> PositionEntity { + PositionModelEntityImpl::get(world, entity_id) + } + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `Position::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_v(self: @PositionEntity, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); + } + +} + #[generate_trait] -impl PositionModel of PositionTrait { +impl PositionImpl of PositionTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> Position { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } - fn set(self: @Position, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, id); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 578691550836206188651404750433984985630363913126316857592149308417275000080 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `Position::v`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn delete(self: @Position, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_v(self: @Position, world: dojo::world::IWorldDispatcher, value: Vec3) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 578691550836206188651404750433984985630363913126316857592149308417275000080, + serialized.span() + ); } + } -impl PositionModelValues of dojo::model::ModelValues { - fn values(self: @PositionValues) -> Span { + +impl PositionModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @PositionEntity) -> felt252 { + *self.__id + } + + fn values(self: @PositionEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.v, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> PositionValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> PositionEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `PositionValues`: deserialization failed." + "ModelEntity `PositionEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> PositionValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> PositionEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @PositionValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @PositionEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @PositionValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @PositionEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @PositionEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl PositionImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> Position { + +impl PositionModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> Position { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -3855,34 +5557,70 @@ impl PositionImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @Position, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @Position, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @Position, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "Position" @@ -3922,7 +5660,7 @@ impl PositionImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @Position) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -4081,93 +5819,214 @@ impl RolesIntrospect<> of dojo::database::introspect::Introspect> { } #[derive(Drop, Serde)] -pub struct RolesValues { +pub struct RolesEntity { + __id: felt252, // private field role_ids: Array, } + #[generate_trait] -impl RolesModel of RolesTrait { - fn entity_id_from_keys() -> felt252 { - let mut serialized = core::array::ArrayTrait::new(); - - core::poseidon::poseidon_hash_span(serialized.span()) - } - fn get(world: dojo::world::IWorldDispatcher, ) -> Roles { - let mut serialized = core::array::ArrayTrait::new(); - - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) - } - fn set(self: @Roles, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) +impl RolesEntityImpl of RolesEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> RolesEntity { + RolesModelEntityImpl::get(world, entity_id) } - fn delete(self: @Roles, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + + fn get_role_ids(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Array { + let values = dojo::model::ModelEntity::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) - } -} -impl RolesModelValues of dojo::model::ModelValues { - fn values(self: @RolesValues) -> Span { + entity_id, + 387776731289756409274549987067854286905927440612427426920343953432870065647 + ); + let mut serialized = core::array::ArrayTrait::new(); - core::serde::Serde::serialize(self.role_ids, ref serialized); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); - core::array::ArrayTrait::span(@serialized) - } - fn from_values(values: Span) -> RolesValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + let field_value = core::serde::Serde::>::deserialize(ref serialized); + + if core::option::OptionTrait::>::is_none(@field_value) { panic!( - "ModelValues `RolesValues`: deserialization failed." + "Field `Roles::role_ids`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) - } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> RolesValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( - world, - dojo::model::Model::::selector(), - id, - dojo::model::Model::::layout() - ); - Self::from_values(values) + + core::option::OptionTrait::>::unwrap(field_value) } - fn update(self: @RolesValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn set_role_ids(self: @RolesEntity, world: dojo::world::IWorldDispatcher, value: Array) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::selector(), - id, - self.values(), - dojo::model::Model::::layout() + 387776731289756409274549987067854286905927440612427426920343953432870065647, + serialized.span() ); } - fn delete(self: @RolesValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( - world, + +} + +#[generate_trait] +impl RolesImpl of RolesTrait { + fn entity_id_from_keys() -> felt252 { + let mut serialized = core::array::ArrayTrait::new(); + + core::poseidon::poseidon_hash_span(serialized.span()) + } + + fn get(world: dojo::world::IWorldDispatcher, ) -> Roles { + let mut serialized = core::array::ArrayTrait::new(); + + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_role_ids(world: dojo::world::IWorldDispatcher, ) -> Array { + let mut serialized = core::array::ArrayTrait::new(); + + + let values = dojo::model::Model::::get_member( + world, + serialized.span(), + 387776731289756409274549987067854286905927440612427426920343953432870065647 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::>::deserialize(ref serialized); + + if core::option::OptionTrait::>::is_none(@field_value) { + panic!( + "Field `Roles::role_ids`: deserialization failed." + ); + } + + core::option::OptionTrait::>::unwrap(field_value) + } + + fn set_role_ids(self: @Roles, world: dojo::world::IWorldDispatcher, value: Array) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 387776731289756409274549987067854286905927440612427426920343953432870065647, + serialized.span() + ); + } + +} + +impl RolesModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @RolesEntity) -> felt252 { + *self.__id + } + + fn values(self: @RolesEntity) -> Span { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(self.role_ids, ref serialized); + + core::array::ArrayTrait::span(@serialized) + } + + fn from_values(entity_id: felt252, values: Span) -> RolesEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { + panic!( + "ModelEntity `RolesEntity`: deserialization failed." + ); + } + core::option::OptionTrait::::unwrap(entity_values) + } + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> RolesEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::Id(entity_id), + dojo::model::Model::::layout() + ); + Self::from_values(entity_id, values) + } + + fn update(self: @RolesEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::Id(self.id()), + self.values(), + dojo::model::Model::::layout() + ); + } + + fn delete(self: @RolesEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( + world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @RolesEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl RolesImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> Roles { + +impl RolesModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> Roles { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -4188,34 +6047,70 @@ impl RolesImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @Roles, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @Roles, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @Roles, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "Roles" @@ -4255,7 +6150,7 @@ impl RolesImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @Roles) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -4405,93 +6300,145 @@ impl OnlyKeyModelIntrospect<> of dojo::database::introspect::Introspect OnlyKeyModelEntity { + OnlyKeyModelModelEntityImpl::get(world, entity_id) + } + } + #[generate_trait] -impl OnlyKeyModelModel of OnlyKeyModelTrait { +impl OnlyKeyModelImpl of OnlyKeyModelTrait { fn entity_id_from_keys(id: felt252) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> OnlyKeyModel { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, id); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) - } - fn set(self: @OnlyKeyModel, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) - } - fn delete(self: @OnlyKeyModel, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } + + } -impl OnlyKeyModelModelValues of dojo::model::ModelValues { - fn values(self: @OnlyKeyModelValues) -> Span { + +impl OnlyKeyModelModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @OnlyKeyModelEntity) -> felt252 { + *self.__id + } + + fn values(self: @OnlyKeyModelEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> OnlyKeyModelValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> OnlyKeyModelEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `OnlyKeyModelValues`: deserialization failed." + "ModelEntity `OnlyKeyModelEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> OnlyKeyModelValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> OnlyKeyModelEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @OnlyKeyModelValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @OnlyKeyModelEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @OnlyKeyModelValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @OnlyKeyModelEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @OnlyKeyModelEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl OnlyKeyModelImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> OnlyKeyModel { + +impl OnlyKeyModelModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> OnlyKeyModel { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -4512,34 +6459,70 @@ impl OnlyKeyModelImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @OnlyKeyModel, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @OnlyKeyModel, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @OnlyKeyModel, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "OnlyKeyModel" @@ -4579,7 +6562,7 @@ impl OnlyKeyModelImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @OnlyKeyModel) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -4729,93 +6712,145 @@ impl U256KeyModelIntrospect<> of dojo::database::introspect::Introspect U256KeyModelEntity { + U256KeyModelModelEntityImpl::get(world, entity_id) + } + } + #[generate_trait] -impl U256KeyModelModel of U256KeyModelTrait { +impl U256KeyModelImpl of U256KeyModelTrait { fn entity_id_from_keys(id: u256) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@id, ref serialized); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, id: u256) -> U256KeyModel { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@id, ref serialized); - dojo::model::Model::::entity( - world, - serialized.span(), - dojo::model::Model::::layout() - ) - } - fn set(self: @U256KeyModel, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) - } - fn delete(self: @U256KeyModel, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( - world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + + dojo::model::Model::::get(world, serialized.span()) } + + } -impl U256KeyModelModelValues of dojo::model::ModelValues { - fn values(self: @U256KeyModelValues) -> Span { + +impl U256KeyModelModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @U256KeyModelEntity) -> felt252 { + *self.__id + } + + fn values(self: @U256KeyModelEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> U256KeyModelValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> U256KeyModelEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `U256KeyModelValues`: deserialization failed." + "ModelEntity `U256KeyModelEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> U256KeyModelValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> U256KeyModelEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @U256KeyModelValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @U256KeyModelEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @U256KeyModelValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @U256KeyModelEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @U256KeyModelEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl U256KeyModelImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> U256KeyModel { + +impl U256KeyModelModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> U256KeyModel { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -4836,34 +6871,70 @@ impl U256KeyModelImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @U256KeyModel, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @U256KeyModel, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @U256KeyModel, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "U256KeyModel" @@ -4903,7 +6974,7 @@ impl U256KeyModelImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @U256KeyModel) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -5066,97 +7137,220 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct PlayerValues { +pub struct PlayerEntity { + __id: felt252, // private field name: felt252, } -#[generate_trait] -impl PlayerModel of PlayerTrait { - fn entity_id_from_keys(game: felt252, player: ContractAddress) -> felt252 { - let mut serialized = core::array::ArrayTrait::new(); - core::array::ArrayTrait::append(ref serialized, game); -core::serde::Serde::serialize(@player, ref serialized); - core::poseidon::poseidon_hash_span(serialized.span()) +#[generate_trait] +impl PlayerEntityImpl of PlayerEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> PlayerEntity { + PlayerModelEntityImpl::get(world, entity_id) } - fn get(world: dojo::world::IWorldDispatcher, game: felt252, player: ContractAddress) -> Player { - let mut serialized = core::array::ArrayTrait::new(); - core::array::ArrayTrait::append(ref serialized, game); -core::serde::Serde::serialize(@player, ref serialized); - dojo::model::Model::::entity( + + fn get_name(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> felt252 { + let values = dojo::model::ModelEntity::::get_member( world, - serialized.span(), - dojo::model::Model::::layout() - ) + entity_id, + 1528802474226268325865027367859591458315299653151958663884057507666229546336 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `Player::name`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn set(self: @Player, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn set_name(self: @PlayerEntity, world: dojo::world::IWorldDispatcher, value: felt252) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + 1528802474226268325865027367859591458315299653151958663884057507666229546336, + serialized.span() + ); + } + +} + +#[generate_trait] +impl PlayerImpl of PlayerTrait { + fn entity_id_from_keys(game: felt252, player: ContractAddress) -> felt252 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, game); +core::serde::Serde::serialize(@player, ref serialized); + + core::poseidon::poseidon_hash_span(serialized.span()) + } + + fn get(world: dojo::world::IWorldDispatcher, game: felt252, player: ContractAddress) -> Player { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, game); +core::serde::Serde::serialize(@player, ref serialized); + + + dojo::model::Model::::get(world, serialized.span()) } - fn delete(self: @Player, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + + fn get_name(world: dojo::world::IWorldDispatcher, game: felt252, player: ContractAddress) -> felt252 { + let mut serialized = core::array::ArrayTrait::new(); + core::array::ArrayTrait::append(ref serialized, game); +core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 1528802474226268325865027367859591458315299653151958663884057507666229546336 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `Player::name`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_name(self: @Player, world: dojo::world::IWorldDispatcher, value: felt252) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1528802474226268325865027367859591458315299653151958663884057507666229546336, + serialized.span() + ); } + } -impl PlayerModelValues of dojo::model::ModelValues { - fn values(self: @PlayerValues) -> Span { + +impl PlayerModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @PlayerEntity) -> felt252 { + *self.__id + } + + fn values(self: @PlayerEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::array::ArrayTrait::append(ref serialized, *self.name); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> PlayerValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> PlayerEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `PlayerValues`: deserialization failed." + "ModelEntity `PlayerEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> PlayerValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> PlayerEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @PlayerValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @PlayerEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @PlayerValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @PlayerEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @PlayerEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl PlayerImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> Player { + +impl PlayerModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> Player { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -5177,34 +7371,70 @@ impl PlayerImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @Player, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @Player, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @Player, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "Player" @@ -5244,7 +7474,7 @@ impl PlayerImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @Player) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -5418,97 +7648,289 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct ModelWithSimpleArrayValues { +pub struct ModelWithSimpleArrayEntity { + __id: felt252, // private field x: u16, y: Array, } + +#[generate_trait] +impl ModelWithSimpleArrayEntityImpl of ModelWithSimpleArrayEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithSimpleArrayEntity { + ModelWithSimpleArrayModelEntityImpl::get(world, entity_id) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithSimpleArray::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_x(self: @ModelWithSimpleArrayEntity, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); + } + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Array { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::>::deserialize(ref serialized); + + if core::option::OptionTrait::>::is_none(@field_value) { + panic!( + "Field `ModelWithSimpleArray::y`: deserialization failed." + ); + } + + core::option::OptionTrait::>::unwrap(field_value) + } + + fn set_y(self: @ModelWithSimpleArrayEntity, world: dojo::world::IWorldDispatcher, value: Array) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); + } + +} + #[generate_trait] -impl ModelWithSimpleArrayModel of ModelWithSimpleArrayTrait { +impl ModelWithSimpleArrayImpl of ModelWithSimpleArrayTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithSimpleArray { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); - dojo::model::Model::::entity( + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16 { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, serialized.span(), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithSimpleArray::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn set(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn set_x(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); } - fn delete(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> Array { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::>::deserialize(ref serialized); + + if core::option::OptionTrait::>::is_none(@field_value) { + panic!( + "Field `ModelWithSimpleArray::y`: deserialization failed." + ); + } + + core::option::OptionTrait::>::unwrap(field_value) + } + + fn set_y(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher, value: Array) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); } + } -impl ModelWithSimpleArrayModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithSimpleArrayValues) -> Span { + +impl ModelWithSimpleArrayModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithSimpleArrayEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithSimpleArrayEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.x, ref serialized); core::serde::Serde::serialize(self.y, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> ModelWithSimpleArrayValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> ModelWithSimpleArrayEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithSimpleArrayValues`: deserialization failed." + "ModelEntity `ModelWithSimpleArrayEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithSimpleArrayValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithSimpleArrayEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithSimpleArrayValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithSimpleArrayEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithSimpleArrayValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithSimpleArrayEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithSimpleArrayEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithSimpleArrayImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithSimpleArray { + +impl ModelWithSimpleArrayModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithSimpleArray { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -5529,34 +7951,70 @@ impl ModelWithSimpleArrayImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithSimpleArray, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithSimpleArray, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithSimpleArray, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithSimpleArray" @@ -5596,7 +8054,7 @@ impl ModelWithSimpleArrayImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @ModelWithSimpleArray) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -5766,97 +8224,289 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct ModelWithByteArrayValues { +pub struct ModelWithByteArrayEntity { + __id: felt252, // private field x: u16, y: ByteArray, } + #[generate_trait] -impl ModelWithByteArrayModel of ModelWithByteArrayTrait { - fn entity_id_from_keys(player: ContractAddress) -> felt252 { - let mut serialized = core::array::ArrayTrait::new(); +impl ModelWithByteArrayEntityImpl of ModelWithByteArrayEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithByteArrayEntity { + ModelWithByteArrayModelEntityImpl::get(world, entity_id) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithByteArray::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_x(self: @ModelWithByteArrayEntity, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); + } + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ByteArray { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithByteArray::y`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_y(self: @ModelWithByteArrayEntity, world: dojo::world::IWorldDispatcher, value: ByteArray) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); + } + +} + +#[generate_trait] +impl ModelWithByteArrayImpl of ModelWithByteArrayTrait { + fn entity_id_from_keys(player: ContractAddress) -> felt252 { + let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithByteArray { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); - dojo::model::Model::::entity( + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16 { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, serialized.span(), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithByteArray::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn set(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn set_x(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); } - fn delete(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ByteArray { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithByteArray::y`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_y(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher, value: ByteArray) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); } + } -impl ModelWithByteArrayModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithByteArrayValues) -> Span { + +impl ModelWithByteArrayModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithByteArrayEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithByteArrayEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.x, ref serialized); core::serde::Serde::serialize(self.y, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> ModelWithByteArrayValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> ModelWithByteArrayEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithByteArrayValues`: deserialization failed." + "ModelEntity `ModelWithByteArrayEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithByteArrayValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithByteArrayEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithByteArrayValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithByteArrayEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithByteArrayValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithByteArrayEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithByteArrayEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithByteArrayImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithByteArray { + +impl ModelWithByteArrayModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithByteArray { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -5877,34 +8527,70 @@ impl ModelWithByteArrayImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithByteArray, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithByteArray, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithByteArray, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithByteArray" @@ -5944,7 +8630,7 @@ impl ModelWithByteArrayImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @ModelWithByteArray) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -6118,97 +8804,289 @@ dojo::database::introspect::Member { } #[derive(Drop, Serde)] -pub struct ModelWithComplexArrayValues { +pub struct ModelWithComplexArrayEntity { + __id: felt252, // private field x: u16, y: Array, } + +#[generate_trait] +impl ModelWithComplexArrayEntityImpl of ModelWithComplexArrayEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithComplexArrayEntity { + ModelWithComplexArrayModelEntityImpl::get(world, entity_id) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithComplexArray::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_x(self: @ModelWithComplexArrayEntity, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); + } + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Array { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::>::deserialize(ref serialized); + + if core::option::OptionTrait::>::is_none(@field_value) { + panic!( + "Field `ModelWithComplexArray::y`: deserialization failed." + ); + } + + core::option::OptionTrait::>::unwrap(field_value) + } + + fn set_y(self: @ModelWithComplexArrayEntity, world: dojo::world::IWorldDispatcher, value: Array) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); + } + +} + #[generate_trait] -impl ModelWithComplexArrayModel of ModelWithComplexArrayTrait { +impl ModelWithComplexArrayImpl of ModelWithComplexArrayTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithComplexArray { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); - dojo::model::Model::::entity( + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16 { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, serialized.span(), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithComplexArray::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_x(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); } - fn set(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> Array { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::>::deserialize(ref serialized); + + if core::option::OptionTrait::>::is_none(@field_value) { + panic!( + "Field `ModelWithComplexArray::y`: deserialization failed." + ); + } + + core::option::OptionTrait::>::unwrap(field_value) } - fn delete(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_y(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher, value: Array) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); } + } -impl ModelWithComplexArrayModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithComplexArrayValues) -> Span { + +impl ModelWithComplexArrayModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithComplexArrayEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithComplexArrayEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.x, ref serialized); core::serde::Serde::serialize(self.y, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> ModelWithComplexArrayValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> ModelWithComplexArrayEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithComplexArrayValues`: deserialization failed." + "ModelEntity `ModelWithComplexArrayEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithComplexArrayValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithComplexArrayEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithComplexArrayValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithComplexArrayEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithComplexArrayValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithComplexArrayEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithComplexArrayEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithComplexArrayImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithComplexArray { + +impl ModelWithComplexArrayModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithComplexArray { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -6229,34 +9107,70 @@ impl ModelWithComplexArrayImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithComplexArray, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithComplexArray, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithComplexArray, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithComplexArray" @@ -6296,7 +9210,7 @@ impl ModelWithComplexArrayImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @ModelWithComplexArray) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -6477,97 +9391,289 @@ dojo::database::introspect::Introspect::::ty() } #[derive(Drop, Serde)] -pub struct ModelWithTupleValues { +pub struct ModelWithTupleEntity { + __id: felt252, // private field x: u16, y: (u8, u16, u32), } + +#[generate_trait] +impl ModelWithTupleEntityImpl of ModelWithTupleEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithTupleEntity { + ModelWithTupleModelEntityImpl::get(world, entity_id) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithTuple::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_x(self: @ModelWithTupleEntity, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); + } + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> (u8, u16, u32) { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::<(u8, u16, u32)>::deserialize(ref serialized); + + if core::option::OptionTrait::<(u8, u16, u32)>::is_none(@field_value) { + panic!( + "Field `ModelWithTuple::y`: deserialization failed." + ); + } + + core::option::OptionTrait::<(u8, u16, u32)>::unwrap(field_value) + } + + fn set_y(self: @ModelWithTupleEntity, world: dojo::world::IWorldDispatcher, value: (u8, u16, u32)) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); + } + +} + #[generate_trait] -impl ModelWithTupleModel of ModelWithTupleTrait { +impl ModelWithTupleImpl of ModelWithTupleTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithTuple { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); - dojo::model::Model::::entity( + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16 { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, serialized.span(), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithTuple::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn set(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn set_x(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); } - fn delete(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> (u8, u16, u32) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + serialized.span(), + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::<(u8, u16, u32)>::deserialize(ref serialized); + + if core::option::OptionTrait::<(u8, u16, u32)>::is_none(@field_value) { + panic!( + "Field `ModelWithTuple::y`: deserialization failed." + ); + } + + core::option::OptionTrait::<(u8, u16, u32)>::unwrap(field_value) } + + fn set_y(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher, value: (u8, u16, u32)) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); + } + } -impl ModelWithTupleModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithTupleValues) -> Span { + +impl ModelWithTupleModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithTupleEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithTupleEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.x, ref serialized); core::serde::Serde::serialize(self.y, ref serialized); core::array::ArrayTrait::span(@serialized) } - fn from_values(values: Span) -> ModelWithTupleValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + + fn from_values(entity_id: felt252, values: Span) -> ModelWithTupleEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithTupleValues`: deserialization failed." + "ModelEntity `ModelWithTupleEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithTupleValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithTupleEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithTupleValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithTupleEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithTupleValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithTupleEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithTupleEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithTupleImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithTuple { + +impl ModelWithTupleModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithTuple { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -6588,34 +9694,70 @@ impl ModelWithTupleImpl of dojo::model::Model { core::option::OptionTrait::::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithTuple, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithTuple, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithTuple, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithTuple" @@ -6655,7 +9797,7 @@ impl ModelWithTupleImpl of dojo::model::Model { fn namespace_hash() -> felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @ModelWithTuple) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -6845,97 +9987,289 @@ dojo::database::introspect::Introspect::::ty() } #[derive(Drop, Serde)] -pub struct ModelWithTupleNoPrimitivesValues { +pub struct ModelWithTupleNoPrimitivesEntity { + __id: felt252, // private field x: u16, y: (u8, Vec3, u32), } + +#[generate_trait] +impl ModelWithTupleNoPrimitivesEntityImpl of ModelWithTupleNoPrimitivesEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithTupleNoPrimitivesEntity { + ModelWithTupleNoPrimitivesModelEntityImpl::get(world, entity_id) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16 { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithTupleNoPrimitives::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) + } + + fn set_x(self: @ModelWithTupleNoPrimitivesEntity, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); + } + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> (u8, Vec3, u32) { + let values = dojo::model::ModelEntity::::get_member( + world, + entity_id, + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::<(u8, Vec3, u32)>::deserialize(ref serialized); + + if core::option::OptionTrait::<(u8, Vec3, u32)>::is_none(@field_value) { + panic!( + "Field `ModelWithTupleNoPrimitives::y`: deserialization failed." + ); + } + + core::option::OptionTrait::<(u8, Vec3, u32)>::unwrap(field_value) + } + + fn set_y(self: @ModelWithTupleNoPrimitivesEntity, world: dojo::world::IWorldDispatcher, value: (u8, Vec3, u32)) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( + world, + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); + } + +} + #[generate_trait] -impl ModelWithTupleNoPrimitivesModel of ModelWithTupleNoPrimitivesTrait { +impl ModelWithTupleNoPrimitivesImpl of ModelWithTupleNoPrimitivesTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252 { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); core::poseidon::poseidon_hash_span(serialized.span()) } + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithTupleNoPrimitives { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(@player, ref serialized); - dojo::model::Model::::entity( + + dojo::model::Model::::get(world, serialized.span()) + } + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16 { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( world, serialized.span(), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::::deserialize(ref serialized); + + if core::option::OptionTrait::::is_none(@field_value) { + panic!( + "Field `ModelWithTupleNoPrimitives::x`: deserialization failed." + ); + } + + core::option::OptionTrait::::unwrap(field_value) } - fn set(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::set_entity( + + fn set_x(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher, value: u16) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::values(self), - dojo::model::Model::::layout() - ) + 512066735765477566404754172672287371265995314501343422459174036873487219331, + serialized.span() + ); + } + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> (u8, Vec3, u32) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@player, ref serialized); + + + let values = dojo::model::Model::::get_member( + world, + serialized.span(), + 1591024729085637502504777720563487898377940395575083379770417352976841400819 + ); + + let mut serialized = core::array::ArrayTrait::new(); + core::array::serialize_array_helper(values, ref serialized); + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let field_value = core::serde::Serde::<(u8, Vec3, u32)>::deserialize(ref serialized); + + if core::option::OptionTrait::<(u8, Vec3, u32)>::is_none(@field_value) { + panic!( + "Field `ModelWithTupleNoPrimitives::y`: deserialization failed." + ); + } + + core::option::OptionTrait::<(u8, Vec3, u32)>::unwrap(field_value) } - fn delete(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher) { - dojo::model::Model::::delete_entity( + + fn set_y(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher, value: (u8, Vec3, u32)) { + let mut serialized = core::array::ArrayTrait::new(); + core::serde::Serde::serialize(@value, ref serialized); + + self.set_member( world, - dojo::model::Model::::keys(self), - dojo::model::Model::::layout() - ) + 1591024729085637502504777720563487898377940395575083379770417352976841400819, + serialized.span() + ); } + } -impl ModelWithTupleNoPrimitivesModelValues of dojo::model::ModelValues { - fn values(self: @ModelWithTupleNoPrimitivesValues) -> Span { + +impl ModelWithTupleNoPrimitivesModelEntityImpl of dojo::model::ModelEntity { + fn id(self: @ModelWithTupleNoPrimitivesEntity) -> felt252 { + *self.__id + } + + fn values(self: @ModelWithTupleNoPrimitivesEntity) -> Span { let mut serialized = core::array::ArrayTrait::new(); core::serde::Serde::serialize(self.x, ref serialized); core::serde::Serde::serialize(self.y, ref serialized); - core::array::ArrayTrait::span(@serialized) - } - fn from_values(values: Span) -> ModelWithTupleNoPrimitivesValues { - let mut serialized = values; - let entity_values = core::serde::Serde::::deserialize(ref serialized); - if core::option::OptionTrait::::is_none(@entity_values) { + core::array::ArrayTrait::span(@serialized) + } + + fn from_values(entity_id: felt252, values: Span) -> ModelWithTupleNoPrimitivesEntity { + let mut serialized = array![entity_id]; + let mut i = 0; + loop { + if i >= values.len() { break; } + serialized.append(*values.at(i)); + i += 1; + }; + let mut serialized = core::array::ArrayTrait::span(@serialized); + + let entity_values = core::serde::Serde::::deserialize(ref serialized); + if core::option::OptionTrait::::is_none(@entity_values) { panic!( - "ModelValues `ModelWithTupleNoPrimitivesValues`: deserialization failed." + "ModelEntity `ModelWithTupleNoPrimitivesEntity`: deserialization failed." ); } - core::option::OptionTrait::::unwrap(entity_values) + core::option::OptionTrait::::unwrap(entity_values) } - fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithTupleNoPrimitivesValues { - let values = dojo::world::IWorldDispatcherTrait::entity_by_id( + + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithTupleNoPrimitivesEntity { + let values = dojo::world::IWorldDispatcherTrait::entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(entity_id), dojo::model::Model::::layout() ); - Self::from_values(values) + Self::from_values(entity_id, values) } - fn update(self: @ModelWithTupleNoPrimitivesValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::set_entity_by_id( + + fn update(self: @ModelWithTupleNoPrimitivesEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::set_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), self.values(), dojo::model::Model::::layout() ); } - fn delete(self: @ModelWithTupleNoPrimitivesValues, world: dojo::world::IWorldDispatcher, id: felt252) { - dojo::world::IWorldDispatcherTrait::delete_entity_by_id( + + fn delete(self: @ModelWithTupleNoPrimitivesEntity, world: dojo::world::IWorldDispatcher) { + dojo::world::IWorldDispatcherTrait::delete_entity( world, dojo::model::Model::::selector(), - id, + dojo::world::ModelIndex::Id(self.id()), dojo::model::Model::::layout() ); } + + fn get_member( + world: dojo::world::IWorldDispatcher, + entity_id: felt252, + member_id: felt252, + ) -> Span { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithTupleNoPrimitivesEntity, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span, + ) { + match dojo::utils::find_model_field_layout(dojo::model::Model::::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + dojo::model::Model::::selector(), + dojo::world::ModelIndex::MemberId((self.id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } } -impl ModelWithTupleNoPrimitivesImpl of dojo::model::Model { - fn entity(world: dojo::world::IWorldDispatcher, keys: Span, layout: dojo::database::introspect::Layout) -> ModelWithTupleNoPrimitives { + +impl ModelWithTupleNoPrimitivesModelImpl of dojo::model::Model { + fn get(world: dojo::world::IWorldDispatcher, keys: Span) -> ModelWithTupleNoPrimitives { let values = dojo::world::IWorldDispatcherTrait::entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(keys), + Self::layout() ); // TODO: Generate method to deserialize from keys / values directly to avoid @@ -6956,34 +10290,70 @@ impl ModelWithTupleNoPrimitivesImpl of dojo::model::Model::unwrap(entity) } - fn set_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - values: Span, - layout: dojo::database::introspect::Layout + fn set( + self: @ModelWithTupleNoPrimitives, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::set_entity( world, Self::selector(), - keys, - values, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::values(self), + Self::layout() ); } - fn delete_entity( - world: dojo::world::IWorldDispatcher, - keys: Span, - layout: dojo::database::introspect::Layout + fn delete( + self: @ModelWithTupleNoPrimitives, + world: dojo::world::IWorldDispatcher ) { dojo::world::IWorldDispatcherTrait::delete_entity( world, Self::selector(), - keys, - layout + dojo::world::ModelIndex::Keys(Self::keys(self)), + Self::layout() ); } + fn get_member( + world: dojo::world::IWorldDispatcher, + keys: Span, + member_id: felt252 + ) -> Span { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + let entity_id = dojo::utils::entity_id_from_keys(keys); + dojo::world::IWorldDispatcherTrait::entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((entity_id, member_id)), + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + + fn set_member( + self: @ModelWithTupleNoPrimitives, + world: dojo::world::IWorldDispatcher, + member_id: felt252, + values: Span + ) { + match dojo::utils::find_model_field_layout(Self::layout(), member_id) { + Option::Some(field_layout) => { + dojo::world::IWorldDispatcherTrait::set_entity( + world, + Self::selector(), + dojo::world::ModelIndex::MemberId((self.entity_id(), member_id)), + values, + field_layout + ) + }, + Option::None => core::panic_with_felt252('bad member id') + } + } + #[inline(always)] fn name() -> ByteArray { "ModelWithTupleNoPrimitives" @@ -7023,7 +10393,7 @@ impl ModelWithTupleNoPrimitivesImpl of dojo::model::Model felt252 { 3437408695301308226171664635441698996501144546809569617702850025816833723775 } - + #[inline(always)] fn entity_id(self: @ModelWithTupleNoPrimitives) -> felt252 { core::poseidon::poseidon_hash_span(self.keys()) @@ -7140,355 +10510,695 @@ mod model_with_tuple_no_primitives { } } } -impl BadModelMultipleVersionsValuesDrop of core::traits::Drop::; -impl BadModelMultipleVersionsValuesSerde of core::serde::Serde:: { - fn serialize(self: @BadModelMultipleVersionsValues, ref output: core::array::Array) { +impl BadModelMultipleVersionsEntityDrop of core::traits::Drop::; +impl BadModelMultipleVersionsEntitySerde of core::serde::Serde:: { + fn serialize(self: @BadModelMultipleVersionsEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(BadModelMultipleVersionsValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(BadModelMultipleVersionsEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait BadModelMultipleVersionsEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelMultipleVersionsEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @BadModelMultipleVersionsEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait BadModelMultipleVersionsTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelMultipleVersions; - fn set(self: @BadModelMultipleVersions, world: dojo::world::IWorldDispatcher); - fn delete(self: @BadModelMultipleVersions, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @BadModelMultipleVersions, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl BadModelBadVersionTypeValuesDrop of core::traits::Drop::; -impl BadModelBadVersionTypeValuesSerde of core::serde::Serde:: { - fn serialize(self: @BadModelBadVersionTypeValues, ref output: core::array::Array) { +impl BadModelBadVersionTypeEntityDrop of core::traits::Drop::; +impl BadModelBadVersionTypeEntitySerde of core::serde::Serde:: { + fn serialize(self: @BadModelBadVersionTypeEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(BadModelBadVersionTypeValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(BadModelBadVersionTypeEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait BadModelBadVersionTypeEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelBadVersionTypeEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @BadModelBadVersionTypeEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait BadModelBadVersionTypeTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelBadVersionType; - fn set(self: @BadModelBadVersionType, world: dojo::world::IWorldDispatcher); - fn delete(self: @BadModelBadVersionType, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @BadModelBadVersionType, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl BadModelNoVersionValueValuesDrop of core::traits::Drop::; -impl BadModelNoVersionValueValuesSerde of core::serde::Serde:: { - fn serialize(self: @BadModelNoVersionValueValues, ref output: core::array::Array) { +impl BadModelNoVersionValueEntityDrop of core::traits::Drop::; +impl BadModelNoVersionValueEntitySerde of core::serde::Serde:: { + fn serialize(self: @BadModelNoVersionValueEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(BadModelNoVersionValueValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(BadModelNoVersionValueEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait BadModelNoVersionValueEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelNoVersionValueEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @BadModelNoVersionValueEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait BadModelNoVersionValueTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelNoVersionValue; - fn set(self: @BadModelNoVersionValue, world: dojo::world::IWorldDispatcher); - fn delete(self: @BadModelNoVersionValue, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @BadModelNoVersionValue, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl BadModelUnexpectedArgWithValueValuesDrop of core::traits::Drop::; -impl BadModelUnexpectedArgWithValueValuesSerde of core::serde::Serde:: { - fn serialize(self: @BadModelUnexpectedArgWithValueValues, ref output: core::array::Array) { +impl BadModelUnexpectedArgWithValueEntityDrop of core::traits::Drop::; +impl BadModelUnexpectedArgWithValueEntitySerde of core::serde::Serde:: { + fn serialize(self: @BadModelUnexpectedArgWithValueEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(BadModelUnexpectedArgWithValueValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(BadModelUnexpectedArgWithValueEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait BadModelUnexpectedArgWithValueEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelUnexpectedArgWithValueEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @BadModelUnexpectedArgWithValueEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait BadModelUnexpectedArgWithValueTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelUnexpectedArgWithValue; - fn set(self: @BadModelUnexpectedArgWithValue, world: dojo::world::IWorldDispatcher); - fn delete(self: @BadModelUnexpectedArgWithValue, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @BadModelUnexpectedArgWithValue, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl BadModelUnexpectedArgValuesDrop of core::traits::Drop::; -impl BadModelUnexpectedArgValuesSerde of core::serde::Serde:: { - fn serialize(self: @BadModelUnexpectedArgValues, ref output: core::array::Array) { +impl BadModelUnexpectedArgEntityDrop of core::traits::Drop::; +impl BadModelUnexpectedArgEntitySerde of core::serde::Serde:: { + fn serialize(self: @BadModelUnexpectedArgEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(BadModelUnexpectedArgValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(BadModelUnexpectedArgEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait BadModelUnexpectedArgEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelUnexpectedArgEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @BadModelUnexpectedArgEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait BadModelUnexpectedArgTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelUnexpectedArg; - fn set(self: @BadModelUnexpectedArg, world: dojo::world::IWorldDispatcher); - fn delete(self: @BadModelUnexpectedArg, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @BadModelUnexpectedArg, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl BadModelNotSupportedVersionValuesDrop of core::traits::Drop::; -impl BadModelNotSupportedVersionValuesSerde of core::serde::Serde:: { - fn serialize(self: @BadModelNotSupportedVersionValues, ref output: core::array::Array) { +impl BadModelNotSupportedVersionEntityDrop of core::traits::Drop::; +impl BadModelNotSupportedVersionEntitySerde of core::serde::Serde:: { + fn serialize(self: @BadModelNotSupportedVersionEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(BadModelNotSupportedVersionValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(BadModelNotSupportedVersionEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait BadModelNotSupportedVersionEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> BadModelNotSupportedVersionEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @BadModelNotSupportedVersionEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait BadModelNotSupportedVersionTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> BadModelNotSupportedVersion; - fn set(self: @BadModelNotSupportedVersion, world: dojo::world::IWorldDispatcher); - fn delete(self: @BadModelNotSupportedVersion, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @BadModelNotSupportedVersion, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl Modelv0ValuesDrop of core::traits::Drop::; -impl Modelv0ValuesSerde of core::serde::Serde:: { - fn serialize(self: @Modelv0Values, ref output: core::array::Array) { +impl Modelv0EntityDrop of core::traits::Drop::; +impl Modelv0EntitySerde of core::serde::Serde:: { + fn serialize(self: @Modelv0Entity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(Modelv0Values { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(Modelv0Entity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait Modelv0EntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Modelv0Entity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @Modelv0Entity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait Modelv0Trait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> Modelv0; - fn set(self: @Modelv0, world: dojo::world::IWorldDispatcher); - fn delete(self: @Modelv0, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @Modelv0, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl ModelWithBadNamespaceFormatValuesDrop of core::traits::Drop::; -impl ModelWithBadNamespaceFormatValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithBadNamespaceFormatValues, ref output: core::array::Array) { +impl ModelWithBadNamespaceFormatEntityDrop of core::traits::Drop::; +impl ModelWithBadNamespaceFormatEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithBadNamespaceFormatEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithBadNamespaceFormatValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithBadNamespaceFormatEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithBadNamespaceFormatEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithBadNamespaceFormatEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @ModelWithBadNamespaceFormatEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait ModelWithBadNamespaceFormatTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithBadNamespaceFormat; - fn set(self: @ModelWithBadNamespaceFormat, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithBadNamespaceFormat, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @ModelWithBadNamespaceFormat, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl ModelWithShortStringNamespaceValuesDrop of core::traits::Drop::; -impl ModelWithShortStringNamespaceValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithShortStringNamespaceValues, ref output: core::array::Array) { +impl ModelWithShortStringNamespaceEntityDrop of core::traits::Drop::; +impl ModelWithShortStringNamespaceEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithShortStringNamespaceEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithShortStringNamespaceValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithShortStringNamespaceEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithShortStringNamespaceEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithShortStringNamespaceEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @ModelWithShortStringNamespaceEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait ModelWithShortStringNamespaceTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithShortStringNamespace; - fn set(self: @ModelWithShortStringNamespace, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithShortStringNamespace, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @ModelWithShortStringNamespace, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl ModelWithStringNamespaceValuesDrop of core::traits::Drop::; -impl ModelWithStringNamespaceValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithStringNamespaceValues, ref output: core::array::Array) { +impl ModelWithStringNamespaceEntityDrop of core::traits::Drop::; +impl ModelWithStringNamespaceEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithStringNamespaceEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithStringNamespaceValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithStringNamespaceEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithStringNamespaceEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithStringNamespaceEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @ModelWithStringNamespaceEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait ModelWithStringNamespaceTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> ModelWithStringNamespace; - fn set(self: @ModelWithStringNamespace, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithStringNamespace, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @ModelWithStringNamespace, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl PositionValuesDrop of core::traits::Drop::; -impl PositionValuesSerde of core::serde::Serde:: { - fn serialize(self: @PositionValues, ref output: core::array::Array) { +impl PositionEntityDrop of core::traits::Drop::; +impl PositionEntitySerde of core::serde::Serde:: { + fn serialize(self: @PositionEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.v, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(PositionValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(PositionEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, v: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait PositionEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> PositionEntity; + + + fn get_v(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Vec3; + + fn set_v(self: @PositionEntity, world: dojo::world::IWorldDispatcher, value: Vec3); + +} trait PositionTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> Position; - fn set(self: @Position, world: dojo::world::IWorldDispatcher); - fn delete(self: @Position, world: dojo::world::IWorldDispatcher); + + + fn get_v(world: dojo::world::IWorldDispatcher, id: felt252) -> Vec3; + + fn set_v(self: @Position, world: dojo::world::IWorldDispatcher, value: Vec3); + } -impl RolesValuesDrop of core::traits::Drop::; -impl RolesValuesSerde of core::serde::Serde:: { - fn serialize(self: @RolesValues, ref output: core::array::Array) { +impl RolesEntityDrop of core::traits::Drop::; +impl RolesEntitySerde of core::serde::Serde:: { + fn serialize(self: @RolesEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.role_ids, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(RolesValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(RolesEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, role_ids: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait RolesEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> RolesEntity; + + + fn get_role_ids(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Array; + + fn set_role_ids(self: @RolesEntity, world: dojo::world::IWorldDispatcher, value: Array); + +} trait RolesTrait { fn entity_id_from_keys() -> felt252; + fn get(world: dojo::world::IWorldDispatcher, ) -> Roles; - fn set(self: @Roles, world: dojo::world::IWorldDispatcher); - fn delete(self: @Roles, world: dojo::world::IWorldDispatcher); + + + fn get_role_ids(world: dojo::world::IWorldDispatcher, ) -> Array; + + fn set_role_ids(self: @Roles, world: dojo::world::IWorldDispatcher, value: Array); + } -impl OnlyKeyModelValuesDrop of core::traits::Drop::; -impl OnlyKeyModelValuesSerde of core::serde::Serde:: { - fn serialize(self: @OnlyKeyModelValues, ref output: core::array::Array) { - +impl OnlyKeyModelEntityDrop of core::traits::Drop::; +impl OnlyKeyModelEntitySerde of core::serde::Serde:: { + fn serialize(self: @OnlyKeyModelEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(OnlyKeyModelValues { - + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(OnlyKeyModelEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, }) } +} +trait OnlyKeyModelEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> OnlyKeyModelEntity; + + } trait OnlyKeyModelTrait { fn entity_id_from_keys(id: felt252) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: felt252) -> OnlyKeyModel; - fn set(self: @OnlyKeyModel, world: dojo::world::IWorldDispatcher); - fn delete(self: @OnlyKeyModel, world: dojo::world::IWorldDispatcher); + + } -impl U256KeyModelValuesDrop of core::traits::Drop::; -impl U256KeyModelValuesSerde of core::serde::Serde:: { - fn serialize(self: @U256KeyModelValues, ref output: core::array::Array) { - +impl U256KeyModelEntityDrop of core::traits::Drop::; +impl U256KeyModelEntitySerde of core::serde::Serde:: { + fn serialize(self: @U256KeyModelEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(U256KeyModelValues { - + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(U256KeyModelEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, }) } +} +trait U256KeyModelEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> U256KeyModelEntity; + + } trait U256KeyModelTrait { fn entity_id_from_keys(id: u256) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, id: u256) -> U256KeyModel; - fn set(self: @U256KeyModel, world: dojo::world::IWorldDispatcher); - fn delete(self: @U256KeyModel, world: dojo::world::IWorldDispatcher); + + } -impl PlayerValuesDrop of core::traits::Drop::; -impl PlayerValuesSerde of core::serde::Serde:: { - fn serialize(self: @PlayerValues, ref output: core::array::Array) { +impl PlayerEntityDrop of core::traits::Drop::; +impl PlayerEntitySerde of core::serde::Serde:: { + fn serialize(self: @PlayerEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.name, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(PlayerValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(PlayerEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, name: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait PlayerEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> PlayerEntity; + + + fn get_name(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> felt252; + + fn set_name(self: @PlayerEntity, world: dojo::world::IWorldDispatcher, value: felt252); + +} trait PlayerTrait { fn entity_id_from_keys(game: felt252, player: ContractAddress) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, game: felt252, player: ContractAddress) -> Player; - fn set(self: @Player, world: dojo::world::IWorldDispatcher); - fn delete(self: @Player, world: dojo::world::IWorldDispatcher); + + + fn get_name(world: dojo::world::IWorldDispatcher, game: felt252, player: ContractAddress) -> felt252; + + fn set_name(self: @Player, world: dojo::world::IWorldDispatcher, value: felt252); + } -impl ModelWithSimpleArrayValuesDrop of core::traits::Drop::; -impl ModelWithSimpleArrayValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithSimpleArrayValues, ref output: core::array::Array) { +impl ModelWithSimpleArrayEntityDrop of core::traits::Drop::; +impl ModelWithSimpleArrayEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithSimpleArrayEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.x, ref output); core::serde::Serde::serialize(self.y, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithSimpleArrayValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithSimpleArrayEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, x: core::serde::Serde::deserialize(ref serialized)?, y: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithSimpleArrayEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithSimpleArrayEntity; + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16; + + fn set_x(self: @ModelWithSimpleArrayEntity, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Array; + + fn set_y(self: @ModelWithSimpleArrayEntity, world: dojo::world::IWorldDispatcher, value: Array); + +} trait ModelWithSimpleArrayTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithSimpleArray; - fn set(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher); + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16; + + fn set_x(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> Array; + + fn set_y(self: @ModelWithSimpleArray, world: dojo::world::IWorldDispatcher, value: Array); + } -impl ModelWithByteArrayValuesDrop of core::traits::Drop::; -impl ModelWithByteArrayValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithByteArrayValues, ref output: core::array::Array) { +impl ModelWithByteArrayEntityDrop of core::traits::Drop::; +impl ModelWithByteArrayEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithByteArrayEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.x, ref output); core::serde::Serde::serialize(self.y, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithByteArrayValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithByteArrayEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, x: core::serde::Serde::deserialize(ref serialized)?, y: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithByteArrayEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithByteArrayEntity; + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16; + + fn set_x(self: @ModelWithByteArrayEntity, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ByteArray; + + fn set_y(self: @ModelWithByteArrayEntity, world: dojo::world::IWorldDispatcher, value: ByteArray); + +} trait ModelWithByteArrayTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithByteArray; - fn set(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher); + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16; + + fn set_x(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ByteArray; + + fn set_y(self: @ModelWithByteArray, world: dojo::world::IWorldDispatcher, value: ByteArray); + } -impl ModelWithComplexArrayValuesDrop of core::traits::Drop::; -impl ModelWithComplexArrayValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithComplexArrayValues, ref output: core::array::Array) { +impl ModelWithComplexArrayEntityDrop of core::traits::Drop::; +impl ModelWithComplexArrayEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithComplexArrayEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.x, ref output); core::serde::Serde::serialize(self.y, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithComplexArrayValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithComplexArrayEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, x: core::serde::Serde::deserialize(ref serialized)?, y: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithComplexArrayEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithComplexArrayEntity; + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16; + + fn set_x(self: @ModelWithComplexArrayEntity, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> Array; + + fn set_y(self: @ModelWithComplexArrayEntity, world: dojo::world::IWorldDispatcher, value: Array); + +} trait ModelWithComplexArrayTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithComplexArray; - fn set(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher); + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16; + + fn set_x(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> Array; + + fn set_y(self: @ModelWithComplexArray, world: dojo::world::IWorldDispatcher, value: Array); + } -impl ModelWithTupleValuesDrop of core::traits::Drop::; -impl ModelWithTupleValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithTupleValues, ref output: core::array::Array) { +impl ModelWithTupleEntityDrop of core::traits::Drop::; +impl ModelWithTupleEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithTupleEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.x, ref output); core::serde::Serde::serialize(self.y, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithTupleValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithTupleEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, x: core::serde::Serde::deserialize(ref serialized)?, y: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithTupleEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithTupleEntity; + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16; + + fn set_x(self: @ModelWithTupleEntity, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> (u8, u16, u32); + + fn set_y(self: @ModelWithTupleEntity, world: dojo::world::IWorldDispatcher, value: (u8, u16, u32)); + +} trait ModelWithTupleTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithTuple; - fn set(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher); + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16; + + fn set_x(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> (u8, u16, u32); + + fn set_y(self: @ModelWithTuple, world: dojo::world::IWorldDispatcher, value: (u8, u16, u32)); + } -impl ModelWithTupleNoPrimitivesValuesDrop of core::traits::Drop::; -impl ModelWithTupleNoPrimitivesValuesSerde of core::serde::Serde:: { - fn serialize(self: @ModelWithTupleNoPrimitivesValues, ref output: core::array::Array) { +impl ModelWithTupleNoPrimitivesEntityDrop of core::traits::Drop::; +impl ModelWithTupleNoPrimitivesEntitySerde of core::serde::Serde:: { + fn serialize(self: @ModelWithTupleNoPrimitivesEntity, ref output: core::array::Array) { + core::serde::Serde::serialize(self.__id, ref output); core::serde::Serde::serialize(self.x, ref output); core::serde::Serde::serialize(self.y, ref output) } - fn deserialize(ref serialized: core::array::Span) -> core::option::Option { - core::option::Option::Some(ModelWithTupleNoPrimitivesValues { + fn deserialize(ref serialized: core::array::Span) -> core::option::Option { + core::option::Option::Some(ModelWithTupleNoPrimitivesEntity { + __id: core::serde::Serde::deserialize(ref serialized)?, x: core::serde::Serde::deserialize(ref serialized)?, y: core::serde::Serde::deserialize(ref serialized)?, }) } } +trait ModelWithTupleNoPrimitivesEntityTrait { + fn get(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> ModelWithTupleNoPrimitivesEntity; + + + fn get_x(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> u16; + + fn set_x(self: @ModelWithTupleNoPrimitivesEntity, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, entity_id: felt252) -> (u8, Vec3, u32); + + fn set_y(self: @ModelWithTupleNoPrimitivesEntity, world: dojo::world::IWorldDispatcher, value: (u8, Vec3, u32)); + +} trait ModelWithTupleNoPrimitivesTrait { fn entity_id_from_keys(player: ContractAddress) -> felt252; + fn get(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> ModelWithTupleNoPrimitives; - fn set(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher); - fn delete(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher); + + + fn get_x(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> u16; + + fn set_x(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher, value: u16); + + fn get_y(world: dojo::world::IWorldDispatcher, player: ContractAddress) -> (u8, Vec3, u32); + + fn set_y(self: @ModelWithTupleNoPrimitives, world: dojo::world::IWorldDispatcher, value: (u8, Vec3, u32)); + } //! > expected_diagnostics diff --git a/crates/dojo-lang/src/semantics/test_data/get b/crates/dojo-lang/src/semantics/test_data/get index 5f90c0d359..13e45b47a7 100644 --- a/crates/dojo-lang/src/semantics/test_data/get +++ b/crates/dojo-lang/src/semantics/test_data/get @@ -194,21 +194,6 @@ Block( ), }, ), - Let( - StatementLet { - pattern: Variable( - __Health_layout__, - ), - expr: FunctionCall( - ExprFunctionCall { - function: ?7::layout, - args: [], - coupon_arg: None, - ty: dojo::database::introspect::Layout, - }, - ), - }, - ), Let( StatementLet { pattern: Variable( @@ -216,7 +201,7 @@ Block( ), expr: FunctionCall( ExprFunctionCall { - function: ?8::entity, + function: ?7::get, args: [ Value( Var( @@ -228,11 +213,6 @@ Block( LocalVarId(test::__get_macro_keys__), ), ), - Value( - Var( - LocalVarId(test::__Health_layout__), - ), - ), ], coupon_arg: None, ty: test::Health, diff --git a/crates/dojo-lang/src/semantics/test_data/set b/crates/dojo-lang/src/semantics/test_data/set index d41133d396..03cd1da1b9 100644 --- a/crates/dojo-lang/src/semantics/test_data/set +++ b/crates/dojo-lang/src/semantics/test_data/set @@ -119,95 +119,21 @@ Block( StatementExpr { expr: FunctionCall( ExprFunctionCall { - function: dojo::world::IWorldDispatcherImpl::set_entity, + function: ?6::set, args: [ Value( - Var( - LocalVarId(test::world), - ), - ), - Value( - FunctionCall( - ExprFunctionCall { - function: ?7::instance_selector, - args: [ - Value( - Snapshot( - ExprSnapshot { - inner: Var( - LocalVarId(test::__set_model_instance__), - ), - ty: @test::Health, - }, - ), - ), - ], - coupon_arg: None, - ty: core::felt252, - }, - ), - ), - Value( - FunctionCall( - ExprFunctionCall { - function: ?8::keys, - args: [ - Value( - Snapshot( - ExprSnapshot { - inner: Var( - LocalVarId(test::__set_model_instance__), - ), - ty: @test::Health, - }, - ), - ), - ], - coupon_arg: None, - ty: core::array::Span::, - }, - ), - ), - Value( - FunctionCall( - ExprFunctionCall { - function: ?9::values, - args: [ - Value( - Snapshot( - ExprSnapshot { - inner: Var( - LocalVarId(test::__set_model_instance__), - ), - ty: @test::Health, - }, - ), - ), - ], - coupon_arg: None, - ty: core::array::Span::, + Snapshot( + ExprSnapshot { + inner: Var( + LocalVarId(test::__set_model_instance__), + ), + ty: @test::Health, }, ), ), Value( - FunctionCall( - ExprFunctionCall { - function: ?10::instance_layout, - args: [ - Value( - Snapshot( - ExprSnapshot { - inner: Var( - LocalVarId(test::__set_model_instance__), - ), - ty: @test::Health, - }, - ), - ), - ], - coupon_arg: None, - ty: dojo::database::introspect::Layout, - }, + Var( + LocalVarId(test::world), ), ), ], diff --git a/crates/dojo-world/src/contracts/abi/world.rs b/crates/dojo-world/src/contracts/abi/world.rs index 62f1b0b137..05a3c18707 100644 --- a/crates/dojo-world/src/contracts/abi/world.rs +++ b/crates/dojo-world/src/contracts/abi/world.rs @@ -52,6 +52,24 @@ abigen!( } ] }, + { + "type": "enum", + "name": "dojo::world::ModelIndex", + "variants": [ + { + "name": "Keys", + "type": "core::array::Span::" + }, + { + "name": "Id", + "type": "core::felt252" + }, + { + "name": "MemberId", + "type": "(core::felt252, core::felt252)" + } + ] + }, { "type": "struct", "name": "core::array::Span::", @@ -288,36 +306,12 @@ abigen!( "name": "entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [ - { - "type": "core::array::Span::" - } - ], - "state_mutability": "view" - }, - { - "type": "function", - "name": "entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -336,36 +330,12 @@ abigen!( "name": "set_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "values", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "set_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "values", @@ -384,32 +354,12 @@ abigen!( "name": "delete_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "delete_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -559,7 +509,7 @@ abigen!( "name": "can_write_model", "inputs": [ { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { @@ -979,7 +929,7 @@ abigen!( "kind": "struct", "members": [ { - "name": "model_id", + "name": "table", "type": "core::felt252", "kind": "data" }, diff --git a/crates/dojo-world/src/contracts/model.rs b/crates/dojo-world/src/contracts/model.rs index de38198885..1026a2c19f 100644 --- a/crates/dojo-world/src/contracts/model.rs +++ b/crates/dojo-world/src/contracts/model.rs @@ -25,6 +25,9 @@ pub mod abigen { pub mod model { pub use crate::contracts::abi::model::*; } + pub mod world { + pub use crate::contracts::abi::world::*; + } } #[derive(Debug, thiserror::Error)] @@ -126,7 +129,11 @@ where let raw_layout = self.model_reader.layout().raw_call().await?; let layout = Layout::cairo_deserialize(raw_layout.as_slice(), 0)?; - Ok(self.world_reader.entity(&self.selector(), &keys.to_vec(), &layout).call().await?) + Ok(self + .world_reader + .entity(&self.selector(), &abigen::world::ModelIndex::Keys(keys.to_vec()), &layout) + .call() + .await?) } pub async fn entity(&self, keys: &[Felt]) -> Result { diff --git a/crates/dojo-world/src/contracts/naming.rs b/crates/dojo-world/src/contracts/naming.rs index d910e98837..5dbd4e80f9 100644 --- a/crates/dojo-world/src/contracts/naming.rs +++ b/crates/dojo-world/src/contracts/naming.rs @@ -57,8 +57,8 @@ pub fn get_filename_from_tag(tag: &str) -> String { format!("{tag}{TAG_SEPARATOR}{selector}") } -pub fn compute_bytearray_hash(namespace: &str) -> Felt { - let ba = ByteArray::from_string(namespace).unwrap(); +pub fn compute_bytearray_hash(value: &str) -> Felt { + let ba = ByteArray::from_string(value).unwrap(); poseidon_hash_many(&ByteArray::cairo_serialize(&ba)) } diff --git a/crates/torii/types-test/src/contracts.cairo b/crates/torii/types-test/src/contracts.cairo index df0ef8be39..88a24731ce 100644 --- a/crates/torii/types-test/src/contracts.cairo +++ b/crates/torii/types-test/src/contracts.cairo @@ -10,7 +10,7 @@ trait IRecords { mod records { use starknet::{ContractAddress, get_caller_address}; use types_test::models::{ - Record, RecordSibling, Subrecord, Nested, NestedMore, NestedMost, Depth + Record, RecordTrait, RecordSibling, RecordSiblingTrait, Subrecord, SubrecordTrait, Nested, NestedMore, NestedMost, Depth }; use types_test::{seed, random}; use super::IRecords; diff --git a/examples/spawn-and-move/._target b/examples/spawn-and-move/._target new file mode 100644 index 0000000000000000000000000000000000000000..7a6a71237f99d60bcab0516a4b0cb2dffab28f29 GIT binary patch literal 4096 zcmeH~y$ZrW498PJ)TQX+B<1h{q&Nx=jt(Md2e)#)Ml8L4&|X2`%E4Fh1$+?e)%t-h z?vg-A@+TqWw*{L07Bm1BT(ISuZP>#q4LaJ#0OnCgU7HsG!_xT=n>o&^yq<^k1e|pH z^lQY>^+UHs5{-D8N*qO~xX%@zXvw`xuE#}Kq%Q7-EPR|Ri~zh;2D!3rx7&Nq){TC< zUSw1YDtpGd0vJ3KibQ}25CI}U1c(3;AOb{y2oM1x@OK2NAMo`DTFx%WS%!I1WCGbX k$wC&y3S$){F_-edByJV+B#%S=3;zR*&--5&4ZteP8=kg2wg3PC literal 0 HcmV?d00001 diff --git a/examples/spawn-and-move/Scarb.toml b/examples/spawn-and-move/Scarb.toml index 6205e442b2..72c8bfdb64 100644 --- a/examples/spawn-and-move/Scarb.toml +++ b/examples/spawn-and-move/Scarb.toml @@ -33,7 +33,8 @@ rpc_url = "http://localhost:5050/" # Default account for katana with seed = 0 account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03" private_key = "0x1800000000300000180000000000030000000000003006001800006600" -world_address = "0x6997a9f670ca240d7dca99fa26fcb702f5922b0c26d454a04db62876f5c2661" +world_address = "0x6d95c696211b4453e1f4b1b2dc9fb9d91602d4a7a1550567362bd9b8bcd9a82" + # `release` profile # # for now configurations in `tool` are not merged recursively so to override @@ -52,7 +53,7 @@ rpc_url = "http://localhost:5050/" # Default account for katana with seed = 0 account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03" private_key = "0x1800000000300000180000000000030000000000003006001800006600" -world_address = "0x07efebb0c2d4cc285d48a97a7174def3be7fdd6b7bd29cca758fa2e17e03ef30" +world_address = "0x6d95c696211b4453e1f4b1b2dc9fb9d91602d4a7a1550567362bd9b8bcd9a82" [profile.release.tool.dojo] # for more info on how `merge-strategy` works see: diff --git a/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json b/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json index a8654af001..c2e9d96d5a 100644 --- a/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json +++ b/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json @@ -274,6 +274,30 @@ ], "state_mutability": "view" }, + { + "type": "function", + "name": "update_player_name", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "update_player_name_value", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, { "type": "function", "name": "reset_player_config", diff --git a/examples/spawn-and-move/manifests/dev/base/abis/dojo-world.json b/examples/spawn-and-move/manifests/dev/base/abis/dojo-world.json index 38a76d87cb..6dd9a18e1a 100644 --- a/examples/spawn-and-move/manifests/dev/base/abis/dojo-world.json +++ b/examples/spawn-and-move/manifests/dev/base/abis/dojo-world.json @@ -46,6 +46,24 @@ } ] }, + { + "type": "enum", + "name": "dojo::world::ModelIndex", + "variants": [ + { + "name": "Keys", + "type": "core::array::Span::" + }, + { + "name": "Id", + "type": "core::felt252" + }, + { + "name": "MemberId", + "type": "(core::felt252, core::felt252)" + } + ] + }, { "type": "struct", "name": "core::array::Span::", @@ -282,36 +300,12 @@ "name": "entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [ - { - "type": "core::array::Span::" - } - ], - "state_mutability": "view" - }, - { - "type": "function", - "name": "entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -330,36 +324,12 @@ "name": "set_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "values", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "set_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "values", @@ -378,32 +348,12 @@ "name": "delete_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "delete_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -553,7 +503,7 @@ "name": "can_write_model", "inputs": [ { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { @@ -973,7 +923,7 @@ "kind": "struct", "members": [ { - "name": "model_id", + "name": "table", "type": "core::felt252", "kind": "data" }, diff --git a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml index 8a0bda9f6a..8a44f07d45 100644 --- a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml +++ b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml @@ -1,6 +1,6 @@ kind = "DojoContract" -class_hash = "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2" -original_class_hash = "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2" +class_hash = "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d" +original_class_hash = "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d" base_class_hash = "0x0" abi = "manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json" reads = [] diff --git a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-mock_token-31599eb2.toml b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-mock_token-31599eb2.toml index 137baf0aaa..295d2d78f1 100644 --- a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-mock_token-31599eb2.toml +++ b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-mock_token-31599eb2.toml @@ -1,6 +1,6 @@ kind = "DojoContract" -class_hash = "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef" -original_class_hash = "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef" +class_hash = "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028" +original_class_hash = "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028" base_class_hash = "0x0" abi = "manifests/dev/base/abis/contracts/dojo_examples-mock_token-31599eb2.json" reads = [] diff --git a/examples/spawn-and-move/manifests/dev/base/dojo-world.toml b/examples/spawn-and-move/manifests/dev/base/dojo-world.toml index bf10b52348..03f06ebea5 100644 --- a/examples/spawn-and-move/manifests/dev/base/dojo-world.toml +++ b/examples/spawn-and-move/manifests/dev/base/dojo-world.toml @@ -1,6 +1,6 @@ kind = "Class" -class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" -original_class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" +class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" +original_class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" abi = "manifests/dev/base/abis/dojo-world.json" tag = "dojo-world" manifest_name = "dojo-world" diff --git a/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json b/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json index 16ee68e05e..c2e9d96d5a 100644 --- a/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json +++ b/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json @@ -274,6 +274,30 @@ ], "state_mutability": "view" }, + { + "type": "function", + "name": "update_player_name", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "update_player_name_value", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, { "type": "function", "name": "reset_player_config", @@ -296,6 +320,18 @@ ], "outputs": [], "state_mutability": "external" + }, + { + "type": "function", + "name": "call_something", + "inputs": [ + { + "name": "something_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "view" } ] }, diff --git a/examples/spawn-and-move/manifests/dev/deployment/abis/dojo-world.json b/examples/spawn-and-move/manifests/dev/deployment/abis/dojo-world.json index 38a76d87cb..6dd9a18e1a 100644 --- a/examples/spawn-and-move/manifests/dev/deployment/abis/dojo-world.json +++ b/examples/spawn-and-move/manifests/dev/deployment/abis/dojo-world.json @@ -46,6 +46,24 @@ } ] }, + { + "type": "enum", + "name": "dojo::world::ModelIndex", + "variants": [ + { + "name": "Keys", + "type": "core::array::Span::" + }, + { + "name": "Id", + "type": "core::felt252" + }, + { + "name": "MemberId", + "type": "(core::felt252, core::felt252)" + } + ] + }, { "type": "struct", "name": "core::array::Span::", @@ -282,36 +300,12 @@ "name": "entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [ - { - "type": "core::array::Span::" - } - ], - "state_mutability": "view" - }, - { - "type": "function", - "name": "entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -330,36 +324,12 @@ "name": "set_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "values", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "set_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "values", @@ -378,32 +348,12 @@ "name": "delete_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "delete_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -553,7 +503,7 @@ "name": "can_write_model", "inputs": [ { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { @@ -973,7 +923,7 @@ "kind": "struct", "members": [ { - "name": "model_id", + "name": "table", "type": "core::felt252", "kind": "data" }, diff --git a/examples/spawn-and-move/manifests/dev/deployment/manifest.json b/examples/spawn-and-move/manifests/dev/deployment/manifest.json index 177e19e53c..c07640232d 100644 --- a/examples/spawn-and-move/manifests/dev/deployment/manifest.json +++ b/examples/spawn-and-move/manifests/dev/deployment/manifest.json @@ -1,8 +1,8 @@ { "world": { "kind": "WorldContract", - "class_hash": "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61", - "original_class_hash": "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61", + "class_hash": "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e", + "original_class_hash": "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e", "abi": [ { "type": "impl", @@ -51,6 +51,24 @@ } ] }, + { + "type": "enum", + "name": "dojo::world::ModelIndex", + "variants": [ + { + "name": "Keys", + "type": "core::array::Span::" + }, + { + "name": "Id", + "type": "core::felt252" + }, + { + "name": "MemberId", + "type": "(core::felt252, core::felt252)" + } + ] + }, { "type": "struct", "name": "core::array::Span::", @@ -287,36 +305,12 @@ "name": "entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [ - { - "type": "core::array::Span::" - } - ], - "state_mutability": "view" - }, - { - "type": "function", - "name": "entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -335,36 +329,12 @@ "name": "set_entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "values", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "set_entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "values", @@ -383,32 +353,12 @@ "name": "delete_entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "delete_entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -558,7 +508,7 @@ "name": "can_write_model", "inputs": [ { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { @@ -978,7 +928,7 @@ "kind": "struct", "members": [ { - "name": "model_id", + "name": "table", "type": "core::felt252", "kind": "data" }, @@ -1203,8 +1153,8 @@ ] } ], - "address": "0x6997a9f670ca240d7dca99fa26fcb702f5922b0c26d454a04db62876f5c2661", - "transaction_hash": "0x4d1e6ab2b50ba6629908bee409050f32363422bf918e4f1cc9913eeaf688cd0", + "address": "0x6d95c696211b4453e1f4b1b2dc9fb9d91602d4a7a1550567362bd9b8bcd9a82", + "transaction_hash": "0x3290c6ba1226811dcf2c971b005dffd18965e93d0c11f9d8f2ae853d6890ab4", "block_number": 3, "seed": "dojo_examples", "metadata": { @@ -1224,9 +1174,9 @@ "contracts": [ { "kind": "DojoContract", - "address": "0x370a8494164d49b607864fb948820db4f21a91dc53eac3e2a58090ceb276c36", - "class_hash": "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2", - "original_class_hash": "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2", + "address": "0x1a0504af4ffec1a748ae115e8d36b8cd7913298308ae4eb39e1eee8fc19d516", + "class_hash": "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d", + "original_class_hash": "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d", "base_class_hash": "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4", "abi": [ { @@ -1504,6 +1454,30 @@ ], "state_mutability": "view" }, + { + "type": "function", + "name": "update_player_name", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "update_player_name_value", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, { "type": "function", "name": "reset_player_config", @@ -1526,6 +1500,18 @@ ], "outputs": [], "state_mutability": "external" + }, + { + "type": "function", + "name": "call_something", + "inputs": [ + { + "name": "something_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "view" } ] }, @@ -1619,9 +1605,9 @@ }, { "kind": "DojoContract", - "address": "0x4a90d939c2aaa49a8761e9b4b88e01cad226b6b2c4fd2c5371c7ef1b71ddef4", - "class_hash": "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef", - "original_class_hash": "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef", + "address": "0x5a8f0aacc5fa9b30fdffee908d7e6093dedda92ad6deefff31aa06b473312e8", + "class_hash": "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028", + "original_class_hash": "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028", "base_class_hash": "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4", "abi": [ { @@ -1838,7 +1824,7 @@ }, { "kind": "DojoContract", - "address": "0x58eea790580fc315042c6486f68b9d15298d6f01771e3991d42827fe6fd6744", + "address": "0x5958b21ca9debb6bf444aebefef92305d3b0f3fd39e20097161282078666873", "class_hash": "0x479bfb12dcba5398d77303e7a665fc3fedb16f2d7f9cb1f5d7e2beb3b7e2ba7", "original_class_hash": "0x479bfb12dcba5398d77303e7a665fc3fedb16f2d7f9cb1f5d7e2beb3b7e2ba7", "base_class_hash": "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4", @@ -2071,6 +2057,243 @@ ], "tag": "dojo_examples-others", "manifest_name": "dojo_examples-others-61de2c18" + }, + { + "kind": "DojoContract", + "address": "0x20cf302cf7c93c871d2ec1bc0d4256e926a54b59ddbc3a6746f2b3430ab6f31", + "class_hash": "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc", + "original_class_hash": "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc", + "base_class_hash": "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4", + "abi": [ + { + "type": "impl", + "name": "ContractImpl", + "interface_name": "dojo::contract::IContract" + }, + { + "type": "struct", + "name": "core::byte_array::ByteArray", + "members": [ + { + "name": "data", + "type": "core::array::Array::" + }, + { + "name": "pending_word", + "type": "core::felt252" + }, + { + "name": "pending_word_len", + "type": "core::integer::u32" + } + ] + }, + { + "type": "interface", + "name": "dojo::contract::IContract", + "items": [ + { + "type": "function", + "name": "contract_name", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "tag", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "name_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "selector", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "WorldProviderImpl", + "interface_name": "dojo::world::IWorldProvider" + }, + { + "type": "struct", + "name": "dojo::world::IWorldDispatcher", + "members": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "interface", + "name": "dojo::world::IWorldProvider", + "items": [ + { + "type": "function", + "name": "world", + "inputs": [], + "outputs": [ + { + "type": "dojo::world::IWorldDispatcher" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "ISomethingImpl", + "interface_name": "dojo_examples::something::ISomething" + }, + { + "type": "interface", + "name": "dojo_examples::something::ISomething", + "items": [ + { + "type": "function", + "name": "something", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "IDojoInitImpl", + "interface_name": "dojo_examples::something::something::IDojoInit" + }, + { + "type": "interface", + "name": "dojo_examples::something::something::IDojoInit", + "items": [ + { + "type": "function", + "name": "dojo_init", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "UpgradableImpl", + "interface_name": "dojo::components::upgradeable::IUpgradeable" + }, + { + "type": "interface", + "name": "dojo::components::upgradeable::IUpgradeable", + "items": [ + { + "type": "function", + "name": "upgrade", + "inputs": [ + { + "name": "new_class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "struct", + "members": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Event", + "kind": "enum", + "variants": [ + { + "name": "Upgraded", + "type": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "nested" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::something::something::Event", + "kind": "enum", + "variants": [ + { + "name": "UpgradeableEvent", + "type": "dojo::components::upgradeable::upgradeable::Event", + "kind": "nested" + } + ] + } + ], + "reads": [], + "writes": [], + "computed": [], + "init_calldata": [], + "tag": "dojo_examples-something", + "manifest_name": "dojo_examples-something-71cfad55" } ], "models": [ diff --git a/examples/spawn-and-move/manifests/dev/deployment/manifest.toml b/examples/spawn-and-move/manifests/dev/deployment/manifest.toml index 46b9be732f..6b379c900d 100644 --- a/examples/spawn-and-move/manifests/dev/deployment/manifest.toml +++ b/examples/spawn-and-move/manifests/dev/deployment/manifest.toml @@ -1,10 +1,10 @@ [world] kind = "WorldContract" -class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" -original_class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" +class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" +original_class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" abi = "manifests/dev/deployment/abis/dojo-world.json" -address = "0x6997a9f670ca240d7dca99fa26fcb702f5922b0c26d454a04db62876f5c2661" -transaction_hash = "0x4d1e6ab2b50ba6629908bee409050f32363422bf918e4f1cc9913eeaf688cd0" +address = "0x6d95c696211b4453e1f4b1b2dc9fb9d91602d4a7a1550567362bd9b8bcd9a82" +transaction_hash = "0x3290c6ba1226811dcf2c971b005dffd18965e93d0c11f9d8f2ae853d6890ab4" block_number = 3 seed = "dojo_examples" manifest_name = "dojo-world" @@ -23,9 +23,9 @@ manifest_name = "dojo-base" [[contracts]] kind = "DojoContract" -address = "0x370a8494164d49b607864fb948820db4f21a91dc53eac3e2a58090ceb276c36" -class_hash = "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2" -original_class_hash = "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2" +address = "0x1a0504af4ffec1a748ae115e8d36b8cd7913298308ae4eb39e1eee8fc19d516" +class_hash = "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d" +original_class_hash = "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d" base_class_hash = "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4" abi = "manifests/dev/deployment/abis/contracts/dojo_examples-actions-40b6994c.json" reads = [] @@ -40,9 +40,9 @@ manifest_name = "dojo_examples-actions-40b6994c" [[contracts]] kind = "DojoContract" -address = "0x4a90d939c2aaa49a8761e9b4b88e01cad226b6b2c4fd2c5371c7ef1b71ddef4" -class_hash = "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef" -original_class_hash = "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef" +address = "0x5a8f0aacc5fa9b30fdffee908d7e6093dedda92ad6deefff31aa06b473312e8" +class_hash = "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028" +original_class_hash = "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028" base_class_hash = "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4" abi = "manifests/dev/deployment/abis/contracts/dojo_examples-mock_token-31599eb2.json" reads = [] @@ -54,7 +54,7 @@ manifest_name = "dojo_examples-mock_token-31599eb2" [[contracts]] kind = "DojoContract" -address = "0x58eea790580fc315042c6486f68b9d15298d6f01771e3991d42827fe6fd6744" +address = "0x5958b21ca9debb6bf444aebefef92305d3b0f3fd39e20097161282078666873" class_hash = "0x479bfb12dcba5398d77303e7a665fc3fedb16f2d7f9cb1f5d7e2beb3b7e2ba7" original_class_hash = "0x479bfb12dcba5398d77303e7a665fc3fedb16f2d7f9cb1f5d7e2beb3b7e2ba7" base_class_hash = "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4" @@ -70,6 +70,20 @@ init_calldata = [ tag = "dojo_examples-others" manifest_name = "dojo_examples-others-61de2c18" +[[contracts]] +kind = "DojoContract" +address = "0x20cf302cf7c93c871d2ec1bc0d4256e926a54b59ddbc3a6746f2b3430ab6f31" +class_hash = "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc" +original_class_hash = "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc" +base_class_hash = "0x26a4f5d2d9638877a2648297339275df5eaab0adb3cdf0010887c2dbf2be4" +abi = "manifests/dev/deployment/abis/contracts/dojo_examples-something-71cfad55.json" +reads = [] +writes = [] +computed = [] +init_calldata = [] +tag = "dojo_examples-something" +manifest_name = "dojo_examples-something-71cfad55" + [[models]] kind = "DojoModel" class_hash = "0x1da39caefeb15d61baa9d1d71f21ed79cf5650aa215b583e7f453c0d7d4ee65" diff --git a/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json b/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json index a8654af001..c2e9d96d5a 100644 --- a/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json +++ b/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json @@ -274,6 +274,30 @@ ], "state_mutability": "view" }, + { + "type": "function", + "name": "update_player_name", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "update_player_name_value", + "inputs": [ + { + "name": "name", + "type": "core::byte_array::ByteArray" + } + ], + "outputs": [], + "state_mutability": "external" + }, { "type": "function", "name": "reset_player_config", diff --git a/examples/spawn-and-move/manifests/release/base/abis/dojo-world.json b/examples/spawn-and-move/manifests/release/base/abis/dojo-world.json index 38a76d87cb..6dd9a18e1a 100644 --- a/examples/spawn-and-move/manifests/release/base/abis/dojo-world.json +++ b/examples/spawn-and-move/manifests/release/base/abis/dojo-world.json @@ -46,6 +46,24 @@ } ] }, + { + "type": "enum", + "name": "dojo::world::ModelIndex", + "variants": [ + { + "name": "Keys", + "type": "core::array::Span::" + }, + { + "name": "Id", + "type": "core::felt252" + }, + { + "name": "MemberId", + "type": "(core::felt252, core::felt252)" + } + ] + }, { "type": "struct", "name": "core::array::Span::", @@ -282,36 +300,12 @@ "name": "entity", "inputs": [ { - "name": "model", - "type": "core::felt252" - }, - { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [ - { - "type": "core::array::Span::" - } - ], - "state_mutability": "view" - }, - { - "type": "function", - "name": "entity_by_id", - "inputs": [ - { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -330,36 +324,12 @@ "name": "set_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "values", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "set_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "values", @@ -378,32 +348,12 @@ "name": "delete_entity", "inputs": [ { - "name": "model", + "name": "model_selector", "type": "core::felt252" }, { - "name": "keys", - "type": "core::array::Span::" - }, - { - "name": "layout", - "type": "dojo::database::introspect::Layout" - } - ], - "outputs": [], - "state_mutability": "external" - }, - { - "type": "function", - "name": "delete_entity_by_id", - "inputs": [ - { - "name": "model_id", - "type": "core::felt252" - }, - { - "name": "entity_id", - "type": "core::felt252" + "name": "index", + "type": "dojo::world::ModelIndex" }, { "name": "layout", @@ -553,7 +503,7 @@ "name": "can_write_model", "inputs": [ { - "name": "model_id", + "name": "model_selector", "type": "core::felt252" }, { @@ -973,7 +923,7 @@ "kind": "struct", "members": [ { - "name": "model_id", + "name": "table", "type": "core::felt252", "kind": "data" }, diff --git a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml index b357f9172c..175d7e1fd8 100644 --- a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml +++ b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml @@ -1,6 +1,6 @@ kind = "DojoContract" -class_hash = "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2" -original_class_hash = "0x7b605612a7c49a92dd752a50f3379f63d5ac89c8b4ac4f374e28f2f042852a2" +class_hash = "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d" +original_class_hash = "0x288e853c84bde01bdbfbd8b8ffe0ff91ebbce90891e5d300f3395abbb50094d" base_class_hash = "0x0" abi = "manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json" reads = [] diff --git a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-mock_token-31599eb2.toml b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-mock_token-31599eb2.toml index 1ead2c6821..8e068df249 100644 --- a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-mock_token-31599eb2.toml +++ b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-mock_token-31599eb2.toml @@ -1,6 +1,6 @@ kind = "DojoContract" -class_hash = "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef" -original_class_hash = "0x97cd4fb3acfe9e6a024589ea34db2fc587586d699ef3732ce627e1771158ef" +class_hash = "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028" +original_class_hash = "0x761d18a3557d98b3962ebb2c9ddae89ad586ce81de7e86c5fd1e1b4f9d0028" base_class_hash = "0x0" abi = "manifests/release/base/abis/contracts/dojo_examples-mock_token-31599eb2.json" reads = [] diff --git a/examples/spawn-and-move/manifests/release/base/dojo-world.toml b/examples/spawn-and-move/manifests/release/base/dojo-world.toml index 7a9495cd20..9ed318065b 100644 --- a/examples/spawn-and-move/manifests/release/base/dojo-world.toml +++ b/examples/spawn-and-move/manifests/release/base/dojo-world.toml @@ -1,6 +1,6 @@ kind = "Class" -class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" -original_class_hash = "0x421b7e4f94c441f6249973a26ef528381689b3a35602b7b46e1439b6f81b61" +class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" +original_class_hash = "0x2bcf11feac030c5ec81496dfc73ae256568c5b7518f8542e25dd0e42938de7e" abi = "manifests/release/base/abis/dojo-world.json" tag = "dojo-world" manifest_name = "dojo-world" diff --git a/examples/spawn-and-move/src/actions.cairo b/examples/spawn-and-move/src/actions.cairo index 17136f073d..7ecb4f009d 100644 --- a/examples/spawn-and-move/src/actions.cairo +++ b/examples/spawn-and-move/src/actions.cairo @@ -8,6 +8,8 @@ trait IActions { fn move(ref world: IWorldDispatcher, direction: Direction); fn set_player_config(ref world: IWorldDispatcher, name: ByteArray); fn get_player_position(world: @IWorldDispatcher) -> Position; + fn update_player_name(ref world: IWorldDispatcher, name: ByteArray); + fn update_player_name_value(ref world: IWorldDispatcher, name: ByteArray); fn reset_player_config(ref world: IWorldDispatcher); fn set_player_server_profile(ref world: IWorldDispatcher, server_id: u32, name: ByteArray); #[cfg(feature: 'something')] @@ -27,8 +29,8 @@ mod actions { use starknet::{ContractAddress, get_caller_address}; use dojo_examples::models::{ - Position, Moves, Direction, Vec2, PlayerConfig, PlayerItem, ServerProfile, PositionModel, - MovesModel, MovesValues, MovesModelValues, PlayerConfigModel + Position, Moves, Direction, Vec2, PlayerConfig, PlayerItem, ServerProfile, PositionTrait, + MovesTrait, MovesEntityTrait, PlayerConfigTrait, PlayerConfigEntityTrait }; use dojo_examples::utils::next_position; #[cfg(feature: 'something')] @@ -83,13 +85,13 @@ mod actions { // instead of using the `get!` macro, you can directly use // the Model::get method - let mut position = PositionModel::get(world, player); + let mut position = PositionTrait::get(world, player); // you can also get entity values by entity ID with the `ModelValues` trait. // Note that it returns a `Values` struct which contains // model values only. - let move_id = MovesModel::entity_id_from_keys(player); - let mut moves = MovesModelValues::get(world, move_id); + let move_id = MovesTrait::entity_id_from_keys(player); + let mut moves = MovesEntityTrait::get(world, move_id); moves.remaining -= 1; moves.last_direction = direction; @@ -100,7 +102,7 @@ mod actions { next.set(world); // you can also update entity values by entity ID with the `ModelValues` trait. - moves.update(world, move_id); + moves.update(world); emit!(world, (Moved { player, direction })); } @@ -121,7 +123,7 @@ mod actions { let player = get_caller_address(); let (position, moves) = get!(world, player, (Position, Moves)); - let config = PlayerConfigModel::get(world, player); + let config = PlayerConfigTrait::get(world, player); delete!(world, (position, moves)); config.delete(world); @@ -156,6 +158,26 @@ mod actions { something.something(); } + + fn update_player_name(ref world: IWorldDispatcher, name: ByteArray) { + let player = get_caller_address(); + let config = PlayerConfigTrait::get(world, player); + config.set_name(world, name.clone()); + + let new_name = PlayerConfigTrait::get_name(world, player); + assert(new_name == name, 'unable to change name'); + } + + fn update_player_name_value(ref world: IWorldDispatcher, name: ByteArray) { + let player = get_caller_address(); + let config_id = PlayerConfigTrait::entity_id_from_keys(player); + + let config = PlayerConfigEntityTrait::get(world, config_id); + config.set_name(world, name.clone()); + + let new_name = PlayerConfigEntityTrait::get_name(world, config_id); + assert(new_name == name, 'unable to change name'); + } } // The `generate_trait` attribute is not compatible with `world` parameter expansion. @@ -208,6 +230,12 @@ mod tests { // System calls actions_system.spawn(); let initial_moves = get!(world, caller, Moves); + let initial_position = get!(world, caller, Position); + + assert( + initial_position.vec.x == 10 && initial_position.vec.y == 10, 'wrong initial position' + ); + actions_system.move(Direction::Right(())); let moves = get!(world, caller, Moves); @@ -217,7 +245,7 @@ mod tests { assert(moves.last_direction.into() == right_dir_felt, 'last direction is wrong'); let new_position = get!(world, caller, Position); - assert(new_position.vec.x == 11, 'position x is wrong'); - assert(new_position.vec.y == 10, 'position y is wrong'); + assert(new_position.vec.x == initial_position.vec.x + 1, 'position x is wrong'); + assert(new_position.vec.y == initial_position.vec.y, 'position y is wrong'); } } diff --git a/examples/spawn-and-move/src/mock_token.cairo b/examples/spawn-and-move/src/mock_token.cairo index 75b4c00e16..bd34916233 100644 --- a/examples/spawn-and-move/src/mock_token.cairo +++ b/examples/spawn-and-move/src/mock_token.cairo @@ -5,7 +5,6 @@ mod mock_token { fn dojo_init(world: @IWorldDispatcher) { let account: ContractAddress = get_caller_address(); - set!(world, MockToken { account: account, amount: 1000 }); } }