-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v2' of private.github.com:0xobelisk/obelisk-engine into v2
- Loading branch information
Showing
17 changed files
with
117 additions
and
273 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.