npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-slot-machines

v1.0.0

Published

slot machine for React

Downloads

20

Readme

react-slot-machines

A slot machine component for React

Installation

$ npm install react-slot-machines --save
$ yarn add react-slot-machines 

Usage

class App extends React.Component {
  state = {
    startEngine: false,
    giftAmount: 16,  //礼物种类
    giftPos1: 0,     //老虎机第1槽位停下的礼物索引
    giftPos2: 1,     //老虎机第2槽位停下的礼物索引
    giftPos3: 3,     //老虎机第3槽位停下的礼物索引 
    hasStart: false,
    giftImgUrlArr: []
  };

  componentDidMount() {
    const that = this;
    const { giftAmount } = that.state;

    let array = [];

    for (let i = 1; i <= giftAmount; i++) {
      array.push({ url: require(`../src/images/${i}.png`) });
    }

    that.setState({
      //重复添加奖品数组以拓宽奖池数组长度
      //自定义n圈就得添加n+1个礼物数组
      //多出来得一个是用于真实旋转后落位的

      // giftImgUrlArr: _.concat(array, array, array, array)
      giftImgUrlArr: _.concat(array)
    });
  }

  render() {
    const that = this;
    const {
      startEngine,
      hasStart,
      giftPos1,
      giftPos2,
      giftPos3,
      giftImgUrlArr,
      giftAmount
    } = that.state;
    const onClickEngineStart = () => {
      if (startEngine) {
        return;
      }

      that.setState({
        startEngine: true,
        hasStart: true
      });
    };

    const onEngineCompelet = () => {
      if (giftPos1 === giftPos2 && giftPos1 !== giftPos3) {
        console.log("实在太可惜,再来一次");
        that.setState({
          startEngine: false
        });
      }

      if (giftPos2 === giftPos3 && giftPos2 !== giftPos1) {
        console.log("实在太可惜,再来一次");
        that.setState({
          startEngine: false
        });
      }

      if (
        giftPos1 !== giftPos2 &&
        giftPos1 !== giftPos3 &&
        giftPos2 !== giftPos3
      ) {
        console.log("哇! 感谢参与");
        that.setState({
          startEngine: false
        });
      }
    };

    return (
      <div className="container">
        <Slot
          giftAmount={giftAmount}
          giftPos1={giftPos1}
          giftPos2={giftPos2}
          giftPos3={giftPos3}
          hasStart={hasStart}
          startEngine={startEngine}
          onClickEngineStart={onClickEngineStart}
          onEngineCompelet={onEngineCompelet}
          // backgroundImg={require("../src/images/sven.jpg")}
          giftImgUrlArr={giftImgUrlArr}
          // customTurns={3}
        />
      </div>
    );
  }
}

export default App;

Properties

  static propTypes = {
    giftPos1: PropTypes.number.isRequired,            //老虎机第1槽位停下的礼物索引
    giftPos2: PropTypes.number.isRequired,            //老虎机第2槽位停下的礼物索引
    giftPos3: PropTypes.number.isRequired,            //老虎机第3槽位停下的礼物索引
    giftType: PropTypes.number.isRequired,            //礼物种类
    startEngine: PropTypes.bool.isRequired,           //老虎机是否启动
    hasStart: PropTypes.bool.isRequired,              //老虎机是否启动过
    onClickEngineStart: PropTypes.func.isRequired,    //点击启动老虎机
    onEngineCompelet: PropTypes.func.isRequired,      //老虎机完全停下的回掉
    giftImgUrlArr: PropTypes.array.isRequired,        //传入的奖品url地址(数组)
    slotDelay2: PropTypes.number,                     //第2槽位的启动延迟(相对于第一槽位)
    slotDelay3: PropTypes.number,                     //第3槽位的启动延迟(相对于第一槽位)
    backgroundImg: PropTypes.string,                  //老虎机的图片(如果没传会有一张默认的圣诞老虎机图片)
    engineDuration: PropTypes.number,                 //老虎机的转动完成时间
    reWindowsContainer: PropTypes.string,             //老虎机的classname传入(包括图片样式)
    reWindows: PropTypes.string,                      //老虎机的槽位classname传入(包括图片样式)
    reGiftContainer: PropTypes.string,                //礼物的classname传入(包括图片样式)
    reStartBtn: PropTypes.string,                     //启动按钮的classname传入
    customTurns: PropTypes.number                     //老虎机旋转圈数
  };

  //提供的一些默认属性
  static defaultProps = {
    slotDelay2: 500,  
    slotDelay3: 1000,
    engineDuration: 8000,
    backgroundImg: require("./images/bg.png"),
    customTurns: 2
  };

License

MIT