Skip to content

Commit

Permalink
Merge branch 'v2' of private.github.com:0xobelisk/obelisk-engine into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vladilen11 committed Sep 8, 2023
2 parents d341a8b + da1b8af commit 68d7950
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 273 deletions.
31 changes: 0 additions & 31 deletions components/Move.lock

This file was deleted.

15 changes: 0 additions & 15 deletions components/Move.toml

This file was deleted.

31 changes: 0 additions & 31 deletions components/sources/birth_time.move

This file was deleted.

27 changes: 0 additions & 27 deletions components/sources/name.move

This file was deleted.

23 changes: 0 additions & 23 deletions components/sources/sex.move

This file was deleted.

12 changes: 0 additions & 12 deletions components/sources/utils.move

This file was deleted.

2 changes: 0 additions & 2 deletions eps/.gitignore

This file was deleted.

43 changes: 0 additions & 43 deletions eps/sources/entity.move

This file was deleted.

84 changes: 0 additions & 84 deletions eps/sources/world.move

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions eps/Move.lock → examples/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[move]
version = 0
manifest_digest = "29EBC8EEB6008703DCFCFC4C49D84765A6C3F555229A11B3917FD950A89CBD15"
deps_digest = "112928C94A84031C09CD9B9D1D44B149B73FC0EEA5FA8D8B2D7CA4D91936335A"

dependencies = [
{ name = "Sui" },
Expand Down
7 changes: 2 additions & 5 deletions eps/Move.toml → examples/Move.toml
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions examples/sources/codegen/components/counter.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module examples::counter_component {
use examples::world::{Self , World};

// Systems
friend examples::counter_system;

const COMPONENT_NAME: vector<u8> = 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<CounterData>(
world,
COMPONENT_NAME,
new(0)
);
}

public(friend) fun update(world: &mut World, value: u64) {
world::get_mut_component<CounterData>(world, COMPONENT_NAME).value = value;
}

public fun get(world: &World): u64 {
world::get_component<CounterData>(world, COMPONENT_NAME).value
}
}
40 changes: 40 additions & 0 deletions examples/sources/codegen/eps/world.move
Original file line number Diff line number Diff line change
@@ -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<entity_key,T>
components: Bag,
}

public fun create_world(ctx: &mut TxContext): World {
World {
id: object::new(ctx),
components: bag::new(ctx),
}
}

public fun get_component<T : store>(world: &World, component_name: vector<u8>): &T {
let component_id = keccak256(&component_name);
bag::borrow<vector<u8>, T>(&world.components, component_id)
}

public fun get_mut_component<T : store>(world: &mut World, component_name: vector<u8>): &mut T {
let component_id = keccak256(&component_name);
bag::borrow_mut<vector<u8>, T>(&mut world.components, component_id)
}

public fun add_component<T : store>(world: &mut World, component_name: vector<u8>, component: T){
let component_id = keccak256(&component_name);
bag::add<vector<u8>,T>(&mut world.components, component_id, component);
}

public fun contains(world: &mut World, component_name: vector<u8>): bool {
let component_id = keccak256(&component_name);
bag::contains(&mut world.components, component_id)
}
}
Loading

0 comments on commit 68d7950

Please sign in to comment.