Giter VIP home page Giter VIP logo

react-gbajs's Introduction

GBA emulator on your React project - easy and powerful to use!

Just three steps to set it up โœจ

1 - Apply GbaProvider

import { GbaProvider } from 'react-gbajs'

const App = () => (
  <GbaProvider>
    ...
  </GbaProvider>
)

2 - Get play function from GbaContext and call it with the game ROM

import { useContext } from 'react'
import { GbaContext } from 'react-gbajs'

const ButtonStartEmulator = () => {
  const {
    play,
  } = useContext(GbaContext)

  const startEmulator = () => {
    const gameRom = getGameRom()
    play({ newRomBuffer: gameRom })
  }

  return (
    <button onClick={() => startEmulator()}>
      Start Emulator
    </button>
  )
}

3 - And render the emulator using the default export

import ReactGbaJs from 'react-gbajs'

const Emulator = () => (
  <ReactGbaJs />
)

Done! ๐ŸŽ‰
Check a full example in /sample.

How it works

This package is a React wrapper for GBA.js.

GBA.js is vendored, with new features over the original version:

  • save and restore state
  • freeze address with a given value

Who is using


klo-gba.js, level editor for Klonoa: Empire of Dreams
Add your project here

Features

GbaContext

GbaContext exports the following properties:

play({ newRomBuffer, restoreState }): boolean

Use this function to start or restart the emulator.

Pass at newRomBuffer the game's ROM to load it:

play({ newRomBuffer: myGameRom })

You can also fill the property restoreState to restore to a previous state saved using saveState. If both are present, the emulator will be reset loading the ROM, and then restored to the given state:

play({ newRomBuffer: myGameRom, restoreState: someState })

If you pass only restoreState, the previous ROM will be re-loaded and will start on the given state. If there is no ROM previously loaded, it won't work.

play({ restoreState: someState })

saveState()

Return the serializable state of the emulator.

addFreezeAddress({ address: number, size: 8 | 16 | 32, value: number })

Freeze an address with the given value.

removeFreezeAddress(address: number)

Remove the freeze value on the given address.

frozenAddresses()

Return the list of the addresses frozen in the following format:

{
  [address in number]: { size: 8 | 16 | 32, value: number }
}

<ReactGbaJs />

<ReactGbaJs /> has the following props:

volume={number} (optional)

Should be a number between 0 (default, muted) or 1 (max volume).

onFpsReported={((fps: number) => void)} (optional)

Callback called every time that an FPS is reported.

scale={number} (optional)

Set the emulator scale. Default value is 1, which has width 240px and height 160px.

onLogReceived={(level: 'error' | 'warn' | 'stub' | 'info', message: string) => void} (optional)

Callback called every time that a log is received within the levels set as true by the prop watchLogLevels.

watchLogLevels={{ error?: boolean, warn?: boolean, stub?: boolean, info?: boolean }} (optional)

Set when the callback onLogReceived should be called. By default the value is { error: true }.

Contribution

1 - Clone this repository

> git clone [email protected]:macabeus/react-gbajs.git
> cd react-gbajs

2 - Install its dependencies

> npm i

3 - Build and watch the project

> npm run start

4 - In another terminal window, go to the /sample project, install its dependencies, and then build and watch it

> cd sample
> npm i
> npm run start

Finished! Now you can develop the package and test it in real-time ๐ŸŽ‰

Thanks

@endrift for GBA.js.
@felix.rodent for the logo.

react-gbajs's People

Contributors

lofoz avatar macabeus avatar vladcuciureanu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-gbajs's Issues

Uncaught ReferenceError: FlashSavedata is not defined

Hi

Sorry to bother you again, but from the issue 14 now i'm getting this error, i don't know if it is a problem with the .gba file but i've tried multiple and i'm getting the same error:

Uncaught (in promise) ReferenceError: FlashSavedata is not defined
    at window.GameBoyAdvanceMMU.GameBoyAdvanceMMU.loadRom (react-gbajs.js?323e:10)
    at G.setRom (react-gbajs.js?323e:10)
    at G.loadRomFromFile (react-gbajs.js?323e:10)
    at H (react-gbajs.js?323e:10)
    at play (react-gbajs.js?323e:10)
    at _callee$ (emulator.js?a22c:33)
    at tryCatch (runtime.js?c56e:45)
    at Generator.invoke [as _invoke] (runtime.js?c56e:274)
    at Generator.prototype.<computed> [as next] (runtime.js?c56e:97)
    at asyncGeneratorStep (emulator.js?a22c:1)
    at _next (emulator.js?a22c:1)

I've also cloned your example and it seems that it gives me the same error

Let me know if i can provide more information

Thank you

Squeak on emulator when running on Chrome

On this PR we added the GBA emulator.
It works very well, but when it starts on Chrome, it plays some squeak for short time, even when the volume is set to 0.
It only plays this squeak on Chrome, and if we to comment the function writeSoundControlHi, we don't have anymore the squeak, but the sound will not work very well while running the game.

Issues cloning & reproducing Sample

After cloning even after npm installing -g react-gbajs I run into both issues:
Cannot find module 'react-gbajs' or its corresponding type declarations.
and
Parameter 'level' implicitly has an 'any' type. TS7006: Parameter 'message' implicitly has an 'any' type.

Is this package no-longer updated or am I doing something horribly wrong.
Thank you - Getting used to React

Wrong type for GBAProvider

Trying to wrap a JSX node inside GBAProvider results in the following error:
Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes'.

This is due to GBAProvider being typed as FunctionComponent instead of FunctionComponent<{children:ReactNode}> or similar types.

NextJS module not found

Hi

Do you have any idea why nextjs is giving me module not found with this library?

here's the error (there's nothing else really)

// _app.tsx
import { GbaProvider } from "react-gbajs"

const AppWrapper = ({ Component, pageProps }: Props) => {
  console.log(GbaProvider)
  return (
    <I18nextProvider i18n={i18n}>
      <GlobalContextProvider>
        <App {...{ Component, pageProps }}></App>
      </GlobalContextProvider>
    </I18nextProvider>
  )
}
error - ./pages/_app.tsx:17:0
Module not found: Can't resolve 'react-gbajs'
  15 | import { env } from "../infrastructure/utils/environment"
  16 | import { themes } from "../infrastructure/theme"
> 17 | import { GbaProvider } from "react-gbajs"
  18 | 
  19 | const AppWrapper = ({ Component, pageProps }: Props) => {
  20 |   console.log(GbaProvider)

I'm using NextJS 12.0.7 with typscript

Thank you for your hard work

Have a nice day

Can't run with Vite & React 17

Hey,
I'm getting the following error:

arm.js:1 Uncaught ReferenceError: ARMCoreArm is not defined
    at Object.<anonymous> (arm.js:1:1)
    at i2 (bootstrap:19:22)
    at Module.<anonymous> (util.js:245:20)
    at i2 (bootstrap:19:22)
    at bootstrap:83:10
    at node_modules/react-gbajs/dist/react-gbajs.js (bootstrap:83:54)
    at __require (chunk-NCIHTZFX.js?v=f314ad2b:3:50)
    at index.ts:6:16

My project:

{
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-gbajs": "^1.0.3"
  },
  "devDependencies": {
    "@types/react": "^17.0.9",
    "@types/react-dom": "^17.0.9",
    "@vitejs/plugin-react": "^4.0.0",
    "eslint": "^8.38.0",
    "eslint-plugin-react": "^7.32.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.3.4",
    "vite": "^4.3.9"
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.