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

pomelo-red-dot

v1.0.4

Published

pomelo GM red-dot plugin

Downloads

7

Readme

red-dot

pomelo GM red-dot plugin

用途分析

  • 对于手游来讲,如果将所有信息直接推送,则会耗费玩家大量的流量.
  • 于是有人就发明了红点系统,用很小的流量提示玩家某些模块的改变,让玩家自己决定是否去获取新的改变.

设计思路

1.定义模块红点

  • 每个游戏的模块不同,也不是所有的模块均需要变更提示,那么,我们需要定义出红点系统会用到的模块(redDot.json).如下:

|用英文id会方便研发者直观的看出作用模块,未用数字id,是因为该id并不参与运算|红点代表功能| |:---------:|:--:| |id |desc| |mail |邮件 | |camp |阵营 | |guild |公会 | |active1 |活动1| |active2 |活动2| |active3 |活动3|

  • 注:系统红点和个人红点很容易混淆,俩种红点的实现方式不同.
  • 如背包新增了一个东西的红点提示,或者免费抽卡红点均是个人红点,个人红点不缓存,用后即消失,可直接用push方式搞定.

2.定义红点面板

  • 由于不同游戏的ui排版不同,不可能在某一ui下固定的存在某些模块(研发过程中也可能会更改ui排版),
  • 甚至不同游戏大区的面板由一个红点系统控制,那么我们需要配置模块红点的所在ui面板(redBoard.json).如下:

|红点面板 |所含红点模块 |最大版本 |红点面板说明| |:-------------:|:---------------------:|:---------:|:-------:| |id | redDot | maxVersion| desc | |red-dot-ui |mail,camp,guild | 10 | 主ui红点 | |red-dot-active |active1,active2,active3| 10 | 活动红点 |

  • 红点系统是做提示用的,我们不必须保留所有历史变更,通常来讲,够用即可,多了反而乱而无用.
  • 当version达到最大值,就从0重新赋值,那么缓存多少个版本最好?默认10个,不合适就自己调整.

3.静态数据已经定义好了,那么动态数据存放在哪?

  • mysql么?不,我们选择redis.
  • 因为我们希望GM在管理后台可以更新活动,玩家在游戏服可以看到.
  • 鉴于redis对server天生的友好,恰好用在此处.

4.红点面板的动态数据格式

  • 某个面板下会有几个模块,需要存储这几个模块是否有变化(true|false).
  • 仅有2种结果的数值,用位存储最为合适.于是我在红点系统中引入了二进制开关.
  • 之后,便可用一个十进制数表示一个红点面板的一个version内容.达到模块变更提示,而且耗费的流量很少.
  • 注:这里仅仅是服务端的设计,前端拿到十进制数后需解析(位运算)后才能真正将红点展示到对应面板上.

如何使用

  1. 进入pomelo项目的game-server下
npm install pomelo-red-dot --save
  1. 将我们上面设计的两张表用倒表工具导出json.
  2. 在服务配置中加上如下代码:
app.use(require('pomelo-red-dot'), {
        red : {
                host: '192.168.1.xxx',                // redis host
                port: 6379,                           // redis port
                redBoardPath:'xx/redBoard.json'       // 上文我们导出的json位置
            }
        });
  1. 如何新增红点
  • redBoardId:自定义的红点面板id
  • idxArr:面板中状态改变的模块下标
pomelo.app.event.emit(redBoardId, idxArr);
  • 例如:
pomelo.app.event.emit(red-dot-active, [0,1]);
  • 表示活动面板下的活动1和活动2有变更.
  1. 查看所有红点状态则调用
pomelo.app.get('redDot').getAllRedDot(cb);

返回如下:

{"data":{"red-dot-ui":{"version":3,"value":7},"red-dot-active":{"version":2,"value":7}}}
  1. 查看某一特定面板下的红点状态则调用
pomelo.app.get('redDot').getRedBinary(redBoardId, version, cb);

返回如下:

{"version":3,"value":7}
  • 注:该方法中传入了一个version参数,客户端需要维护每个面板的version,取新状态的时候也要将该version传入,默认为0;