Skip to content

Commit 9910481

Browse files
committed
fixing queue and snake/paint
1 parent f937d2b commit 9910481

File tree

7 files changed

+29
-39
lines changed

7 files changed

+29
-39
lines changed

contracts/Scarb.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ source = "git+https://github.com/dojoengine/dojo?tag=v1.2.1#3d4b1a3e662f70679813
2424

2525
[[package]]
2626
name = "pixelaw"
27-
version = "0.6.14"
27+
version = "0.6.15"
2828
dependencies = [
2929
"dojo",
3030
"dojo_cairo_test",

contracts/dojo_dev.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ world_address = "0x005a247732e3a59737fea5504ed776c6e79eae8b6b2317402ab36b6d3cc50
3030
"pixelaw-RTree" = ["pixelaw-actions"]
3131
"pixelaw-Area" = ["pixelaw-actions"]
3232
"pixelaw-SnakeSegment" = ["pixelaw-snake_actions"]
33+

contracts/src/apps/paint/app.cairo

+16-9
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub mod paint_actions {
6565

6666
use pixelaw::core::actions::{IActionsDispatcherTrait as ICoreActionsDispatcherTrait};
6767

68-
use pixelaw::core::models::pixel::{Pixel, PixelUpdate};
68+
use pixelaw::core::models::pixel::{Pixel, PixelUpdate, PixelUpdateResultTrait};
6969
use pixelaw::core::models::registry::App;
7070
use pixelaw::core::utils::{
7171
DefaultParameters, decode_rgba, encode_rgba, get_callers, get_core_actions, subu8,
@@ -190,7 +190,7 @@ pub mod paint_actions {
190190

191191
// TODO: Load Paint App Settings like the fade step time
192192
// For example for the cooldown feature
193-
let COOLDOWN_SECS = 5;
193+
let COOLDOWN_SECS = 0;
194194

195195
// Check if 5 seconds have passed or if the sender is the owner
196196
assert!(
@@ -316,19 +316,19 @@ pub mod paint_actions {
316316
// If the color is 0,0,0, fading is done.
317317
if r == 0 && g == 0 && b == 0 {
318318
world.erase_model(@pixel);
319-
//delete!(world, (pixel));
320319
return;
321320
}
322321

323322
// Fade the color
324-
let FADE_STEP = 5;
323+
let FADE_STEP = 50;
325324

326325
let new_color = encode_rgba(
327326
subu8(r, FADE_STEP), subu8(g, FADE_STEP), subu8(b, FADE_STEP), a,
328327
);
329328

330329
// Update color of the pixel
331-
let _ = core_actions
330+
// TODO check results?
331+
let _result = core_actions
332332
.update_pixel(
333333
player,
334334
system,
@@ -340,13 +340,15 @@ pub mod paint_actions {
340340
text: Option::None,
341341
app: Option::Some(system),
342342
owner: Option::Some(player),
343-
action: Option::None // Not using this feature for paint
343+
action: Option::None
344344
},
345345
Option::None,
346346
false,
347-
);
347+
).unwrap();
348348

349-
let FADE_SECONDS = 4;
349+
350+
351+
let FADE_SECONDS = 0;
350352

351353
// Implement fading by scheduling a new fade call
352354
let queue_timestamp = starknet::get_block_timestamp() + FADE_SECONDS;
@@ -355,12 +357,17 @@ pub mod paint_actions {
355357
let THIS_CONTRACT_ADDRESS = get_contract_address();
356358

357359
// Prepare calldata
358-
// Calldata[0]: Calling player
360+
// Calldata[0]: player_override option:None
361+
calldata.append(0x0);
359362
calldata.append(player.into());
360363

361364
// Calldata[1]: Calling system
365+
calldata.append(0x0);
362366
calldata.append(THIS_CONTRACT_ADDRESS.into());
363367

368+
// Calldata[2]: Area Hint
369+
calldata.append(0x1);
370+
364371
// Calldata[2,3]: Position[x,y]
365372
calldata.append(position.x.into());
366373
calldata.append(position.y.into());

contracts/src/apps/snake/app.cairo

-23
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ pub trait ISnakeActions<T> {
132132

133133
#[dojo::contract]
134134
pub mod snake_actions {
135-
use dojo::event::EventStorage;
136135
use dojo::model::{ModelStorage};
137136
use dojo::world::storage::WorldStorage;
138137
use dojo::world::{IWorldDispatcherTrait};
@@ -156,23 +155,6 @@ pub mod snake_actions {
156155
use super::{Snake, SnakeSegment};
157156

158157

159-
#[derive(Copy, Drop, Serde)]
160-
#[dojo::event]
161-
pub struct Died {
162-
#[key]
163-
owner: ContractAddress,
164-
x: u16,
165-
y: u16,
166-
}
167-
168-
#[derive(Copy, Drop, Serde)]
169-
#[dojo::event]
170-
pub struct Moved {
171-
#[key]
172-
pub owner: ContractAddress,
173-
pub direction: Direction,
174-
}
175-
176158
const SNAKE_MAX_LENGTH: u8 = 255;
177159

178160

@@ -364,11 +346,6 @@ pub mod snake_actions {
364346
let position = Position { x: first_segment.x, y: first_segment.y };
365347
core_actions.alert_player(position, snake.owner, 'Snake died here');
366348

367-
world
368-
.emit_event(
369-
@Died { owner: snake.owner, x: first_segment.x, y: first_segment.y },
370-
);
371-
372349
// Delete the snake
373350
world.erase_model(@snake);
374351
return;

contracts/src/core/actions/pixel.cairo

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub fn update_pixel(
107107
}
108108
// Store the Pixel
109109
world.write_model(@pixel);
110+
110111
// Call on_post_update if the pixel has an app
111112
if pixel.app != contract_address_const::<0>() {
112113
let mut caller_app: App = world.read_model(for_system);

contracts/src/core/utils.cairo

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use pixelaw::core::models::{
66
pixel::{Pixel},
77
{area::{BoundsTraitImpl, ChildrenPackableImpl, RTreeNodePackableImpl, RTreeTraitImpl}},
88
};
9-
use starknet::{ContractAddress, contract_address_const, get_contract_address, get_tx_info};
9+
use starknet::{ContractAddress, contract_address_const, get_caller_address,get_contract_address, get_tx_info};
1010

1111

1212
pub const POW_2_96: u128 = 0x1000000000000000000000000_u128;
@@ -120,16 +120,19 @@ pub fn get_callers(
120120
let mut system = contract_address_const::<0>();
121121

122122
let core_address = get_core_actions_address(ref world);
123+
// let caller_contract = get_caller_address();
123124
let caller_contract = get_contract_address();
124-
125+
125126
if let Option::Some(override) = params.player_override {
126-
assert(caller_contract == core_address, 'only core can override');
127+
// TODO this doesnt work when queue
128+
assert(get_caller_address() == core_address, 'only core can override');
127129
player = override;
128130
} else {
129131
player = get_tx_info().unbox().account_contract_address;
130132
}
133+
131134
if let Option::Some(override) = params.system_override {
132-
assert(caller_contract == core_address, 'only core can override');
135+
assert(get_caller_address() == core_address, 'only core can override');
133136
system = override;
134137
} else {
135138
system = caller_contract;
@@ -185,7 +188,7 @@ pub fn subu8(nr: u8, sub: u8) -> u8 {
185188
if nr >= sub {
186189
return nr - sub;
187190
} else {
188-
return 0x000000FF;
191+
return 0;
189192
}
190193
}
191194

contracts/src/tests/test_helpers.cairo

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use pixelaw::{
1616
core::{
1717
actions::{IActionsDispatcher, IActionsDispatcherTrait, actions},
1818
models::{
19-
area::{m_Area, m_RTree}, pixel::{m_Pixel},
19+
area::{m_Area, m_RTree}, pixel::{m_Pixel},queue::{m_QueueItem},
2020
registry::{m_App, m_AppName, m_CoreActionsAddress},
2121
},
2222
utils::{Position},
@@ -63,6 +63,7 @@ fn namespace_def() -> NamespaceDef {
6363
TestResource::Model(m_Area::TEST_CLASS_HASH),
6464
TestResource::Model(m_Snake::TEST_CLASS_HASH),
6565
TestResource::Model(m_SnakeSegment::TEST_CLASS_HASH),
66+
TestResource::Model(m_QueueItem::TEST_CLASS_HASH),
6667
TestResource::Event(pixelaw::core::events::e_QueueScheduled::TEST_CLASS_HASH),
6768
TestResource::Event(pixelaw::core::events::e_QueueProcessed::TEST_CLASS_HASH),
6869
TestResource::Event(pixelaw::core::events::e_Alert::TEST_CLASS_HASH),

0 commit comments

Comments
 (0)