diff --git a/components/Move.lock b/components/Move.lock deleted file mode 100644 index c4f9119f..00000000 --- a/components/Move.lock +++ /dev/null @@ -1,31 +0,0 @@ -# @generated by Move, please check-in and do not edit manually. - -[move] -version = 0 -manifest_digest = "2608AC11CF4740E3FE6AE71B1A6E2F1B935FF212C237F436E2FF65760BE2C7AA" -deps_digest = "81EE7D908A2BA4534DF95DFABF1575906EBF2C8A6BFC89DB065E6324A9C45ED4" - -dependencies = [ - { name = "Eps" }, - { name = "Sui" }, -] - -[[move.package]] -name = "Eps" -source = { local = "../eps" } - -dependencies = [ - { name = "Sui" }, -] - -[[move.package]] -name = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet-v1.8.0", subdir = "crates/sui-framework/packages/move-stdlib" } - -[[move.package]] -name = "Sui" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet-v1.8.0", subdir = "crates/sui-framework/packages/sui-framework" } - -dependencies = [ - { name = "MoveStdlib" }, -] diff --git a/components/Move.toml b/components/Move.toml deleted file mode 100644 index 451d8348..00000000 --- a/components/Move.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "Components" -version = "0.0.1" -published-at = "0x75b65f518fb45c4d9fedd5541948ae4ebef462a013c26764a20099c1dac84e75" - - -[dependencies] -Eps = { local = "../eps" } -Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "testnet-v1.8.0" } - -[addresses] -eps = "0xcd81c2e6f3589375c1a01f64034dcb3c1819a40c773d7f2ddf667a8d2683c104" -sui = "0x2" -components = "0x75b65f518fb45c4d9fedd5541948ae4ebef462a013c26764a20099c1dac84e75" -#components = "0x0" diff --git a/components/sources/birth_time.move b/components/sources/birth_time.move deleted file mode 100644 index 004ed5ad..00000000 --- a/components/sources/birth_time.move +++ /dev/null @@ -1,31 +0,0 @@ -module components::birth_time_component { - use components::utils::generate_component_id; - use sui::clock::Clock; - use sui::clock; - - const COMPONENT_NAME: vector = b"Obelisk birth_time component"; - - struct BirthTimeComponent has store { - value: u64 - } - - public fun new_birth_time(clock: &Clock): BirthTimeComponent { - BirthTimeComponent { - value : clock::timestamp_ms(clock) - } - } - - public fun get_birth_time(birth_time: &BirthTimeComponent): u64 { - birth_time.value - } - - public fun get_age_timestamp(birth_time: &BirthTimeComponent, clock: &Clock): u64 { - let current_time = clock::timestamp_ms(clock); - let birth_time = get_birth_time(birth_time); - current_time - birth_time - } - - public fun get_component_id() : vector { - generate_component_id(COMPONENT_NAME) - } -} \ No newline at end of file diff --git a/components/sources/name.move b/components/sources/name.move deleted file mode 100644 index 037f7b12..00000000 --- a/components/sources/name.move +++ /dev/null @@ -1,27 +0,0 @@ -module components::name_component { - use components::utils::generate_component_id; - - const COMPONENT_NAME: vector = b"Obelisk name component"; - - struct NameComponent has store { - value: vector - } - - public fun new_name(name: vector): NameComponent { - NameComponent { - value : name - } - } - - public fun update_name(name_component: &mut NameComponent, name: vector) { - name_component.value = name; - } - - public fun get_name(name_component: &NameComponent): vector { - name_component.value - } - - public fun get_component_id() : vector { - generate_component_id(COMPONENT_NAME) - } -} \ No newline at end of file diff --git a/components/sources/sex.move b/components/sources/sex.move deleted file mode 100644 index 3e54c069..00000000 --- a/components/sources/sex.move +++ /dev/null @@ -1,23 +0,0 @@ -module components::sex_component { - use components::utils::generate_component_id; - - const COMPONENT_NAME: vector = b"Obelisk sex component"; - - struct SexComponent has store { - value: bool - } - - public fun new_sex(sex: bool): SexComponent { - SexComponent { - value : sex - } - } - - public fun get_sex(sex_component: &SexComponent) : bool { - sex_component.value - } - - public fun get_component_id() : vector { - generate_component_id(COMPONENT_NAME) - } -} \ No newline at end of file diff --git a/components/sources/utils.move b/components/sources/utils.move deleted file mode 100644 index d5c8be66..00000000 --- a/components/sources/utils.move +++ /dev/null @@ -1,12 +0,0 @@ -module components::utils { - - use sui::hash::keccak256; - - const Hour:u64 = 3600000u64; - const Minute:u64 = 60000u64; - const Second:u64 = 1000u64; - - public fun generate_component_id(component_name: vector): vector { - keccak256(&component_name) - } -} \ No newline at end of file diff --git a/eps/.gitignore b/eps/.gitignore deleted file mode 100644 index 49783609..00000000 --- a/eps/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/build -.idea diff --git a/eps/sources/entity.move b/eps/sources/entity.move deleted file mode 100644 index 6b902a1c..00000000 --- a/eps/sources/entity.move +++ /dev/null @@ -1,43 +0,0 @@ -module eps::entity { - use sui::bag::Bag; - use sui::bag; - use sui::tx_context::TxContext; - - struct Entity has store { - components: Bag - } - - public fun create_entity(ctx: &mut TxContext): Entity { - Entity { - components: bag::new(ctx) - } - } - - public fun add_component(entity: &mut Entity, component_id: vector, component:T){ - let components = get_mut_components(entity); - bag::add(components, component_id, component); - } - - public fun remove_component(entity: &mut Entity, component_id: vector){ - let components= get_mut_components(entity); - bag::remove,T>(components, component_id); - } - - public fun get_mut_components(entity: &mut Entity): &mut Bag { - &mut entity.components - } - - public fun get_component(entity: &Entity, component_id: vector): &T { - assert!(bag::contains(&entity.components, component_id),0); - bag::borrow,T>(&entity.components, component_id) - } - - public fun get_mut_component(entity: &mut Entity, component_id: vector): &mut T { - assert!(bag::contains(&entity.components, component_id),0); - bag::borrow_mut,T>(&mut entity.components,component_id) - } - - public fun components_length(entity: &mut Entity) : u64 { - bag::length(get_mut_components(entity)) - } -} diff --git a/eps/sources/world.move b/eps/sources/world.move deleted file mode 100644 index 64aee304..00000000 --- a/eps/sources/world.move +++ /dev/null @@ -1,84 +0,0 @@ -module eps::world { - use sui::object::{UID, ID}; - use sui::object; - use sui::tx_context::TxContext; - use sui::bag::Bag; - use sui::bag; - use eps::entity::Entity; - use sui::tx_context; - use sui::hash::keccak256; - - struct World has key, store{ - id: UID, - /// Owner of the world - owner: address, - /// Name for the world - name: vector, - /// Description of the world - description: vector, - /// entity set - entities: Bag - } - - - public fun create_world(ctx: &mut TxContext, name: vector, description: vector): World{ - World { - id: object::new(ctx), - owner: tx_context::sender(ctx), - name, - description, - entities:bag::new(ctx) - } - } - - public fun get_world_owner(world: &World): address { - world.owner - } - - public fun get_world_name(world: &World): vector { - world.name - } - - public fun get_world_description(world: &World): vector { - world.description - } - - public fun get_entity(world: &World, obj_id: ID): &Entity { - bag::borrow(&world.entities, obj_id) - } - - public fun get_mut_entity(world: &mut World, obj: &T): &mut Entity { - let entity_key = object::id(obj); - bag::borrow_mut(&mut world.entities, entity_key) - } - - public fun add_entity_in_world(world: &mut World, obj: &T, entity: Entity){ - let entity_key = object::id(obj); - bag::add(&mut world.entities, entity_key, entity); - } - - public fun get_mut_custom_entity(world: &mut World, entity_key: vector, ctx: &mut TxContext): &mut T { - let owner = get_world_owner(world); - assert!(tx_context::sender(ctx) == owner, 0); - let entity_key = keccak256(&entity_key); - let entity_id = object::id_from_bytes(entity_key); - bag::borrow_mut(&mut world.entities, entity_id) - } - - public fun add_custom_entity_in_world(world: &mut World, entity_key: vector, obj: T, ctx: &mut TxContext){ - let owner = get_world_owner(world); - assert!(tx_context::sender(ctx) == owner, 0); - let entity_key = keccak256(&entity_key); - let entity_id = object::id_from_bytes(entity_key); - bag::add(&mut world.entities, entity_id, obj); - } - - public fun remove_entity(world: &mut World, obj: &T) : Entity { - let entity_key = object::id(obj); - bag::remove(&mut world.entities,entity_key) - } - - public fun entities_length(world: &mut World) : u64 { - bag::length(&mut world.entities) - } -} diff --git a/components/.gitignore b/examples/.gitignore similarity index 100% rename from components/.gitignore rename to examples/.gitignore diff --git a/eps/Move.lock b/examples/Move.lock similarity index 75% rename from eps/Move.lock rename to examples/Move.lock index 0170327e..8eff5f24 100644 --- a/eps/Move.lock +++ b/examples/Move.lock @@ -2,6 +2,8 @@ [move] version = 0 +manifest_digest = "29EBC8EEB6008703DCFCFC4C49D84765A6C3F555229A11B3917FD950A89CBD15" +deps_digest = "112928C94A84031C09CD9B9D1D44B149B73FC0EEA5FA8D8B2D7CA4D91936335A" dependencies = [ { name = "Sui" }, diff --git a/eps/Move.toml b/examples/Move.toml similarity index 52% rename from eps/Move.toml rename to examples/Move.toml index a4355c6d..a9005a8b 100644 --- a/eps/Move.toml +++ b/examples/Move.toml @@ -1,13 +1,10 @@ [package] -name = "Eps" +name = "examples" version = "0.0.1" -published-at = "0xcd81c2e6f3589375c1a01f64034dcb3c1819a40c773d7f2ddf667a8d2683c104" - [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "testnet-v1.8.0" } [addresses] -eps = "0xcd81c2e6f3589375c1a01f64034dcb3c1819a40c773d7f2ddf667a8d2683c104" -#eps = '0x0' sui = "0x2" +examples = "0x0" diff --git a/examples/sources/codegen/components/counter.move b/examples/sources/codegen/components/counter.move new file mode 100644 index 00000000..572773a8 --- /dev/null +++ b/examples/sources/codegen/components/counter.move @@ -0,0 +1,34 @@ +module examples::counter_component { + use examples::world::{Self , World}; + + // Systems + friend examples::counter_system; + + const COMPONENT_NAME: vector = b"Counter Component"; + + struct CounterData has drop, store { + value: u64 + } + + public fun new(value: u64): CounterData { + CounterData { + value + } + } + + public fun register(world: &mut World) { + world::add_component( + world, + COMPONENT_NAME, + new(0) + ); + } + + public(friend) fun update(world: &mut World, value: u64) { + world::get_mut_component(world, COMPONENT_NAME).value = value; + } + + public fun get(world: &World): u64 { + world::get_component(world, COMPONENT_NAME).value + } +} diff --git a/examples/sources/codegen/eps/world.move b/examples/sources/codegen/eps/world.move new file mode 100644 index 00000000..02ebf2bb --- /dev/null +++ b/examples/sources/codegen/eps/world.move @@ -0,0 +1,40 @@ +module examples::world { + use sui::tx_context::TxContext; + use sui::hash::keccak256; + use sui::bag::{ Self, Bag }; + use sui::object::{ Self, UID }; + + struct World has key, store{ + id: UID, + /// Components of the world + /// K256(component_name) <=> Table + components: Bag, + } + + public fun create_world(ctx: &mut TxContext): World { + World { + id: object::new(ctx), + components: bag::new(ctx), + } + } + + public fun get_component(world: &World, component_name: vector): &T { + let component_id = keccak256(&component_name); + bag::borrow, T>(&world.components, component_id) + } + + public fun get_mut_component(world: &mut World, component_name: vector): &mut T { + let component_id = keccak256(&component_name); + bag::borrow_mut, T>(&mut world.components, component_id) + } + + public fun add_component(world: &mut World, component_name: vector, component: T){ + let component_id = keccak256(&component_name); + bag::add,T>(&mut world.components, component_id, component); + } + + public fun contains(world: &mut World, component_name: vector): bool { + let component_id = keccak256(&component_name); + bag::contains(&mut world.components, component_id) + } +} diff --git a/examples/sources/codegen/init.move b/examples/sources/codegen/init.move new file mode 100644 index 00000000..69daa5cb --- /dev/null +++ b/examples/sources/codegen/init.move @@ -0,0 +1,22 @@ +module examples::init { + use sui::transfer; + use sui::tx_context::TxContext; + use examples::world; + + use examples::counter_component; + + fun init(ctx: &mut TxContext) { + let world = world::create_world(ctx); + + // Add Component + + counter_component::register(&mut world); + + transfer::public_share_object(world); + } + + #[test_only] + public fun init_world_for_testing(ctx: &mut TxContext){ + init(ctx) + } +} diff --git a/examples/sources/entity_key.move b/examples/sources/entity_key.move new file mode 100644 index 00000000..b0d19ab3 --- /dev/null +++ b/examples/sources/entity_key.move @@ -0,0 +1,7 @@ +module examples::entity_key { + use sui::object; + + public fun object_to_entity_key(object: &T): vector { + object::id_bytes(object) + } +} diff --git a/examples/sources/system/counter_system.move b/examples/sources/system/counter_system.move new file mode 100644 index 00000000..eac18a1b --- /dev/null +++ b/examples/sources/system/counter_system.move @@ -0,0 +1,10 @@ +module examples::counter_system { + use examples::world::World; + use examples::counter_component; + + public entry fun increase(world: &mut World) { + let old_number = counter_component::get(world); + let new_number = old_number + 1; + counter_component::update(world, new_number); + } +}