diff --git a/examples/sources/codegen/components/multi_column.move b/examples/sources/codegen/components/multi_column.move index 3d9ffaf3..650f9982 100644 --- a/examples/sources/codegen/components/multi_column.move +++ b/examples/sources/codegen/components/multi_column.move @@ -11,10 +11,10 @@ module examples::multi_column_comp { // Systems friend examples::example_system; - const COMPONENT_NAME: vector = b"multi_column"; + const NAME: vector = b"multi_column"; public fun id(): address { - entity_key::from_bytes(COMPONENT_NAME) + entity_key::from_bytes(NAME) } // state @@ -28,35 +28,35 @@ module examples::multi_column_comp { } public fun register(world: &mut World, ctx: &mut TxContext) { - world::add_component>( + world::add_comp>( world, - COMPONENT_NAME, + NAME, table::new(ctx) ); } public(friend) fun add(world: &mut World, key: address, state: vector, last_update_time: u64) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); let data = encode(state, last_update_time); table::add(component, key, Field { data }); world::emit_add_event(id(), key, data) } public(friend) fun remove(world: &mut World, key: address) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); table::remove(component, key); world::emit_remove_event(id(), key) } public(friend) fun update(world: &mut World, key: address, state: vector, last_update_time: u64) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); let field = table::borrow_mut(component, key); let data = encode(state, last_update_time); field.data = data; world::emit_update_event(id(), some(key), data) } public(friend) fun update_state(world: &mut World, key: address, state: vector) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); let field = table::borrow_mut(component, key); let (_, last_update_time) = decode(field.data); let data = encode(state, last_update_time); @@ -65,7 +65,7 @@ module examples::multi_column_comp { } public(friend) fun update_last_update_time(world: &mut World, key: address, last_update_time: u64) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); let field = table::borrow_mut(component, key); let (state, _) = decode(field.data); let data = encode(state, last_update_time); @@ -74,27 +74,27 @@ module examples::multi_column_comp { } public fun get(world: &World, key: address): (vector,u64) { - let component = world::get_component>(world, id()); + let component = world::get_comp>(world, id()); let field = table::borrow(component, key); decode(field.data) } public fun get_state(world: &World, key: address): vector { - let component = world::get_component>(world, id()); + let component = world::get_comp>(world, id()); let field = table::borrow(component, key); let (state, _) = decode(field.data); state } public fun get_last_update_time(world: &World, key: address): u64 { - let component = world::get_component>(world, id()); + let component = world::get_comp>(world, id()); let field = table::borrow(component, key); let (_, last_update_time) = decode(field.data); last_update_time } public fun contains(world: &World, key: address): bool { - let component = world::get_component>(world, id()); + let component = world::get_comp>(world, id()); table::contains(component, key) } diff --git a/examples/sources/codegen/components/single_column.move b/examples/sources/codegen/components/single_column.move index 92fc858f..aa5ec8b1 100644 --- a/examples/sources/codegen/components/single_column.move +++ b/examples/sources/codegen/components/single_column.move @@ -11,10 +11,10 @@ module examples::single_column_comp { // Systems friend examples::example_system; - const COMPONENT_NAME: vector = b"single_column"; + const NAME: vector = b"single_column"; public fun id(): address { - entity_key::from_bytes(COMPONENT_NAME) + entity_key::from_bytes(NAME) } // value @@ -27,28 +27,28 @@ module examples::single_column_comp { } public fun register(world: &mut World, ctx: &mut TxContext) { - world::add_component>( + world::add_comp>( world, - COMPONENT_NAME, + NAME, table::new(ctx) ); } public(friend) fun add(world: &mut World, key: address, value: u64) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); let data = encode(value); table::add(component, key, Field { data }); world::emit_add_event(id(), key, data) } public(friend) fun remove(world: &mut World, key: address) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); table::remove(component, key); world::emit_remove_event(id(), key) } public(friend) fun update(world: &mut World, key: address, value: u64) { - let component = world::get_mut_component>(world, id()); + let component = world::get_mut_comp>(world, id()); let field = table::borrow_mut(component, key); let data = encode(value); field.data = data; @@ -56,13 +56,13 @@ module examples::single_column_comp { } public fun get(world: &World, key: address): u64 { - let component = world::get_component>(world, id()); + let component = world::get_comp>(world, id()); let field = table::borrow(component, key); decode(field.data) } public fun contains(world: &World, key: address): bool { - let component = world::get_component>(world, id()); + let component = world::get_comp>(world, id()); table::contains(component, key) } diff --git a/examples/sources/codegen/components/single_struct.move b/examples/sources/codegen/components/single_struct.move index 6a309688..58a200e8 100644 --- a/examples/sources/codegen/components/single_struct.move +++ b/examples/sources/codegen/components/single_struct.move @@ -9,10 +9,10 @@ module examples::single_struct_comp { // Systems friend examples::example_system; - const COMPONENT_NAME: vector = b"single_struct"; + const NAME: vector = b"single_struct"; public fun id(): address { - entity_key::from_bytes(COMPONENT_NAME) + entity_key::from_bytes(NAME) } // admin @@ -26,45 +26,45 @@ module examples::single_struct_comp { } public fun register(world: &mut World) { - world::add_component( + world::add_comp( world, - COMPONENT_NAME, + NAME, Field { data: encode(@0x1, 100) } ); } public(friend) fun update(world: &mut World, admin: address, fee: u64) { let data = encode(admin, fee); - world::get_mut_component(world, id()).data = data; + world::get_mut_comp(world, id()).data = data; world::emit_update_event(id(), none(), data) } public(friend) fun update_admin(world: &mut World, admin: address) { - let field = world::get_mut_component(world, id()); + let field = world::get_mut_comp(world, id()); let (_, fee) = decode(field.data); field.data = encode(admin, fee); world::emit_update_event(id(), none(), field.data) } public(friend) fun update_fee(world: &mut World, fee: u64) { - let field = world::get_mut_component(world, id()); + let field = world::get_mut_comp(world, id()); let (admin, _) = decode(field.data); field.data = encode(admin, fee); world::emit_update_event(id(), none(), field.data) } public fun get(world: &World): (address,u64) { - let data = world::get_component(world, id()).data; + let data = world::get_comp(world, id()).data; decode(data) } public fun get_admin(world: &World): address { - let data = world::get_component(world, id()).data; + let data = world::get_comp(world, id()).data; let (admin, _) = decode(data); admin } public fun get_fee(world: &World): u64 { - let data = world::get_component(world, id()).data; + let data = world::get_comp(world, id()).data; let (_, fee) = decode(data); fee } diff --git a/examples/sources/codegen/components/single_value.move b/examples/sources/codegen/components/single_value.move index c9f6a03f..f55a7038 100644 --- a/examples/sources/codegen/components/single_value.move +++ b/examples/sources/codegen/components/single_value.move @@ -9,10 +9,10 @@ module examples::single_value_comp { // Systems friend examples::example_system; - const COMPONENT_NAME: vector = b"single_value"; + const NAME: vector = b"single_value"; public fun id(): address { - entity_key::from_bytes(COMPONENT_NAME) + entity_key::from_bytes(NAME) } // value @@ -25,21 +25,21 @@ module examples::single_value_comp { } public fun register(world: &mut World) { - world::add_component( + world::add_comp( world, - COMPONENT_NAME, + NAME, Field { data: encode(1000) } ); } public(friend) fun update(world: &mut World, value: u64) { let data = encode(value); - world::get_mut_component(world, id()).data = data; + world::get_mut_comp(world, id()).data = data; world::emit_update_event(id(), none(), data) } public fun get(world: &World): u64 { - let data = world::get_component(world, id()).data; + let data = world::get_comp(world, id()).data; decode(data) } diff --git a/examples/sources/codegen/eps/world.move b/examples/sources/codegen/eps/world.move index bcaf5430..1dc3c0b0 100644 --- a/examples/sources/codegen/eps/world.move +++ b/examples/sources/codegen/eps/world.move @@ -34,9 +34,9 @@ module examples::world { /// Description of the world description: String, /// Components of the world - components: Bag, + comps: Bag, /// Component names of the world - component_names: vector, + compnames: vector, /// admin of the world admin: ID, /// Components of the world @@ -68,8 +68,8 @@ module examples::world { id: object::new(ctx), name, description, - components: bag::new(ctx), - component_names: vector::empty(), + comps: bag::new(ctx), + compnames: vector::empty(), admin: object::id(&admin), version: VERSION }; @@ -81,33 +81,33 @@ module examples::world { (world.name, world.description, world.version) } - public fun component_names(world: &World): vector { - world.component_names + public fun compnames(world: &World): vector { + world.compnames } - public fun get_component(world: &World, id: address): &T { + public fun get_comp(world: &World, id: address): &T { assert!(world.version == VERSION, EWrongVersion); - assert!(bag::contains(&world.components, id), ECompDoesNotExist); - bag::borrow(&world.components, id) + assert!(bag::contains(&world.comps, id), ECompDoesNotExist); + bag::borrow(&world.comps, id) } - public fun get_mut_component(world: &mut World, id: address): &mut T { + public fun get_mut_comp(world: &mut World, id: address): &mut T { assert!(world.version == VERSION, EWrongVersion); - assert!(bag::contains(&world.components, id), ECompDoesNotExist); - bag::borrow_mut(&mut world.components, id) + assert!(bag::contains(&world.comps, id), ECompDoesNotExist); + bag::borrow_mut(&mut world.comps, id) } - public fun add_component(world: &mut World, component_name: vector, component: T){ + public fun add_comp(world: &mut World, component_name: vector, component: T){ assert!(world.version == VERSION, EWrongVersion); let id = entity_key::from_bytes(component_name); - assert!(!bag::contains(&world.components, id), ECompAlreadyExists); - vector::push_back(&mut world.component_names, string(component_name)); - bag::add(&mut world.components, id, component); + assert!(!bag::contains(&world.comps, id), ECompAlreadyExists); + vector::push_back(&mut world.compnames, string(component_name)); + bag::add(&mut world.comps, id, component); } public fun contains(world: &mut World, id: address): bool { assert!(world.version == VERSION, EWrongVersion); - bag::contains(&mut world.components, id) + bag::contains(&mut world.comps, id) } public fun emit_remove_event(comp: address, key: address) { diff --git a/examples/sources/system/example_system.move b/examples/sources/system/example_system.move index a4eadf95..40416c14 100644 --- a/examples/sources/system/example_system.move +++ b/examples/sources/system/example_system.move @@ -51,7 +51,7 @@ module examples::example_system { assert!(description == string(b"Examples description"), 0); assert!(version == 1, 0); - let names = world::component_names(&world); + let names = world::compnames(&world); assert!(names == vector[ string(b"single_column"), string(b"multi_column"),