Commit 21e11058 authored by Chunchi Che's avatar Chunchi Che

handle damage msg in rust-src

parent 95b51bd0
Pipeline #20648 failed with stages
in 7 minutes and 36 seconds
......@@ -89,6 +89,7 @@ name = "rust-src"
version = "0.1.0"
dependencies = [
"console_error_panic_hook",
"js-sys",
"wasm-bindgen",
"wasm-bindgen-test",
"wee_alloc",
......
......@@ -10,10 +10,11 @@ crate-type = ["cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["console_error_panic_hook"]
default = ["console_error_panic_hook", "wee_alloc"]
[dependencies]
wasm-bindgen = "0.2.63"
js-sys = "0.3.61"
console_error_panic_hook = { version = "0.1.6", optional = true }
wee_alloc = { version = "0.4.5", optional = true }
......
#![allow(non_snake_case)]
mod buffer;
mod utils;
use wasm_bindgen::prelude::*;
use std::convert::TryInto;
use wasm_bindgen::prelude::wasm_bindgen;
pub use utils::set_panic_hook;
......@@ -11,11 +15,20 @@ pub use utils::set_panic_hook;
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
pub struct MsgUpdateHp {
pub player: Option<u8>,
pub value: Option<i32>,
}
#[wasm_bindgen]
pub fn greet() {
alert("Hello, {{project-name}}!");
pub fn ocgDamageAdapter(data: js_sys::Uint8Array) -> MsgUpdateHp {
let data = data.to_vec();
let player = data[0];
let value = data[1..5].try_into().map(i32::from_le_bytes).ok();
MsgUpdateHp {
player: Some(player),
value,
}
}
import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO";
import { ocgDamageAdapter } from "rust-src";
/*
* Msg Damage
......@@ -8,14 +8,7 @@ import { BufferReader } from "../../bufferIO";
* @param value - 减少的Hp数值
* */
export default (data: Uint8Array) => {
const reader = new BufferReader(data, true);
const damage = ocgDamageAdapter(data);
const player = reader.readUint8();
const value = reader.readInt32();
return new ygopro.StocGameMessage.MsgUpdateHp({
player,
type_: ygopro.StocGameMessage.MsgUpdateHp.ActionType.DAMAGE,
value,
});
return new ygopro.StocGameMessage.MsgUpdateHp(damage);
};
import React, { Suspense } from "react";
import { Routes, Route } from "react-router-dom";
import LazyLoad, { Loading } from "./LazyLoad";
import { greet } from "rust-src";
const Login = React.lazy(() => import("./Login"));
const WaitRoom = React.lazy(() => import("./WaitRoom"));
......@@ -9,8 +8,6 @@ const Mora = React.lazy(() => import("./Mora"));
const NeosDuel = React.lazy(() => import("./Duel/main"));
export default function () {
greet();
return (
<Routes>
<Route path="/" element={<LazyLoad lazy={<Login />} />} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment