江湖梦网游戏服务平台

 找回密码
 免费注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 5825|回复: 2

[搬运汉化] 灯光插件

[复制链接]

449

帖子

41

精华

25

贡献

江湖英豪

检察者

Rank: 5Rank: 5Rank: 5

积分
7245
发表于 2020-12-2 02:41 | 显示全部楼层 |阅读模式

马上注册,享用更多精彩。

您需要 登录 才可以下载或查看,没有帐号?免费注册

x
本帖最后由 大魔王 于 2020-12-2 02:45 编辑

Community Lighting MV & MZ
https://forums.rpgmakerweb.com/i ... hting-mv-mz.124274/

Ultra Mini Community Lighting:

使用说明:打开以下链接
https://github.com/ImaginaryVillain/community_lights

這是附帶項目,在遊戲中使用的非常精簡的社區照明超快速版本。 (通過單擊我的簽名中的鏈接可以看到)。
此版本僅打開/關閉(默認為關閉),允許使用“ Light”標籤,播放器燈光和tint命令 而已。

但是好處是它比基本腳本要快得多。 因此,如果您對此感興趣,
可以在GitHub上以umc_Lighting.js或的形式獲得。
插件中包含操作說明。 我還想指出,我不擁有MZ,因此雖然MZ版本有效,但尚未經過廣泛測試。


  1. //=============================================================================
  2. // Community Plugins - MZ Ultra Mini Lighting system
  3. // umc_Lighting_mz.js
  4. // Version: 1.45
  5. /*=============================================================================
  6. Forked from Terrax Lighting
  7. =============================================================================*/
  8. var umc = umc || {};
  9. umc.Lighting = umc.Lighting || {};
  10. umc.Lighting.version = 1.45;
  11. /*:
  12. * @plugindesc v1.2 The smallest, fastest lighting plugin!
  13. * @author Terrax, iVillain, Aesica
  14. *
  15. * @param Lights Active Radius
  16. * @parent ---Offset and Sizes---
  17. * @desc The number of grid spaces away from the player that lights are turned on.
  18. * Default: 20
  19. * @default 20
  20. *
  21. * @param Player radius
  22. * @parent ---Offset and Sizes---
  23. * @desc Adjust the light radius around the player
  24. * Default: 300
  25. * @default 300
  26. *
  27. * @param Screensize X
  28. * @parent ---Offset and Sizes---
  29. * @desc Increase if your using a higher screen resolution then the default
  30. * Default : 866
  31. * @default 866
  32. *
  33. * @param Screensize Y
  34. * @parent ---Offset and Sizes---
  35. * @desc Increase if your using a higher screen resolution then the default
  36. * Default : 630
  37. * @default 630
  38. *
  39. * @help
  40. * --------------------------------------------------------------------------
  41. * Script Commands
  42. * --------------------------------------------------------------------------
  43. * umc.Lighting.tint('#333333'); //Sets the tint. #333333 can be any color.
  44. * --------------------------------------------------------------------------
  45. * Events Note Tag
  46. * --------------------------------------------------------------------------
  47. * Light radius color
  48. * - Light               
  49. * - radius      100, 250, etc
  50. * - color       #ffffff, #ff0000, etc
  51. */

  52. umc.Lighting = {
  53.     event_note: [],
  54.     event_id: [],
  55.     event_stacknumber: [],
  56.     event_eventcount: 0,
  57.     parameters: PluginManager.parameters('umc_Lighting_mz'),
  58.     oldmap: 0,
  59.     note_command: 0
  60. };

  61. umc.Lighting.getTag = function () {
  62.     let note = this.note;
  63.     let result = note.trim();
  64.     return result;
  65. };

  66. umc.Lighting.ReloadMapEvents = function () {
  67.     //**********************fill up new map-array *************************
  68.     this.event_note = [];
  69.     this.event_id = [];
  70.     this.event_stacknumber = [];
  71.     this.event_eventcount = $gameMap.events().length;

  72.     for (let i = 0, n = this.event_eventcount; i < n; i++) {
  73.         if ($gameMap.events()[i]) {
  74.             if ($gameMap.events()[i].event()) {
  75.                 let note = this.getTag.call($gameMap.events()[i].event());
  76.                 let note_args = note.split(" ");
  77.                 umc.Lighting.note_command = note_args.shift().toLowerCase();

  78.                 if (umc.Lighting.note_command == "light") {
  79.                     this.event_note.push(note);
  80.                     this.event_id.push($gameMap.events()[i]._eventId);
  81.                     this.event_stacknumber.push(i);
  82.                 }
  83.             }
  84.         }
  85.     }
  86. };

  87. // *******************  NORMAL LIGHT SHAPE ***********************************
  88. // Fill gradient circle
  89. Bitmap.prototype.radialgradientFillRect = function (x1, y1, r1, r2, color1, color2, brightness) {
  90.     let isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color1);
  91.     if (!isValidColor) {
  92.         color1 = '#000000'
  93.     }
  94.     let isValidColor2 = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color2);
  95.     if (!isValidColor2) {
  96.         color2 = '#000000'
  97.     }

  98.     x1 = x1 + 20;

  99.     if (!brightness) {
  100.         brightness = 0.0;
  101.     }

  102.     let context = this._context;
  103.     let grad;

  104.     grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
  105.     if (brightness) {
  106.         grad.addColorStop(0, '#FFFFFF');
  107.     }
  108.     grad.addColorStop(brightness, color1);
  109.     grad.addColorStop(1, color2);

  110.     context.save();
  111.     context.fillStyle = grad;
  112.     context.fillRect(x1 - r2, y1 - r2, r2 * 2, r2 * 2);
  113.     context.restore();
  114.     //this._setDirty();
  115. };

  116. umc.Lighting.tint = function (color) {
  117.     $gameVariables.SetTint(color);
  118. };

  119. umc.Lighting.hexToRgb = function (hex) {
  120.     let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  121.     result = result ? {
  122.         r: parseInt(result[1], 16),
  123.         g: parseInt(result[2], 16),
  124.         b: parseInt(result[3], 16)
  125.     } : null;
  126.     return result;
  127. };

  128. Game_Variables.prototype.SetTint = function (value) {
  129.     this._umc_Tint_Value = value;
  130. };
  131. Game_Variables.prototype.GetTint = function () {
  132.     return this._umc_Tint_Value || '#000000';
  133. };
  134. Game_Variables.prototype.SetPlayerColor = function (value) {
  135.     this._umc_Lighting_PlayerColor = value;
  136. };
  137. Game_Variables.prototype.GetPlayerColor = function () {
  138.     return this._umc_Lighting_PlayerColor || '#FFFFFF';
  139. };
  140. Game_Variables.prototype.SetPlayerBrightness = function (value) {
  141.     this._umc_Lighting_PlayerBrightness = value;
  142. };
  143. Game_Variables.prototype.GetPlayerBrightness = function (value) {
  144.     this._umc_Lighting_PlayerBrightness = value || 0.0;
  145. };
  146. Game_Variables.prototype.SetRadius = function (value) {
  147.     this._umc_Lighting_Radius = value;
  148. };
  149. Game_Variables.prototype.GetRadius = function () {
  150.     return this._umc_Lighting_Radius || 150;
  151. };

  152. Spriteset_Map.prototype.createLightmask = function () {
  153.     this._lightmask = new Lightmask();
  154.     this.addChild(this._lightmask);
  155. };

  156. function Lightmask() {
  157.     this.initialize.apply(this, arguments);
  158. }

  159. Lightmask.prototype = Object.create(PIXI.Container.prototype);
  160. Lightmask.prototype.constructor = Lightmask;

  161. Lightmask.prototype.initialize = function () {
  162.     PIXI.Container.call(this);
  163.     this._width = Graphics.width;
  164.     this._height = Graphics.height;
  165.     this._sprites = [];
  166.     this._createBitmap();
  167. };

  168. Lightmask.prototype._createBitmap = function() {
  169.     this._maskBitmap = new Bitmap(Number(umc.Lighting.parameters['Screensize X']) + 20, Number(umc.Lighting.parameters['Screensize Y']));   // one big bitmap to fill the intire screen with black
  170. };

  171. Lightmask.prototype.update = function () {
  172.     requestAnimationFrame(this._updateMask.bind(this));
  173. };

  174. Lightmask.prototype._updateMask = function () {
  175.     // Reload map events if map is changed.
  176.     let map_id = $gameMap.mapId();
  177.     if (map_id != umc.Lighting.oldmap) {
  178.         umc.Lighting.oldmap = map_id;
  179.         umc.Lighting.ReloadMapEvents();
  180.         player_radius = Number(umc.Lighting.parameters['Player radius']);
  181.         $gameVariables.SetRadius(player_radius);  
  182.     }

  183.     // reload mapevents if event_data has chanced (deleted or spawned events/saves)
  184.     if (umc.Lighting.event_eventcount != $gameMap.events().length) {
  185.         umc.Lighting.ReloadMapEvents();
  186.     }

  187.     // remove old sprites
  188.     for (let i = 0, n = this._sprites.length; i < n; i++) {        
  189.         this._removeSprite();
  190.     }
  191.     this.darkenscreen();

  192.     if ($gameMap.mapId() >= 0) {      
  193.         for (let i = 0, n = umc.Lighting.event_note.length; i < n; i++) {
  194.             var note = umc.Lighting.event_note[i];
  195.             var note_args = note.split(" ");
  196.             umc.Lighting.note_command = note_args.shift().toLowerCase();
  197.             this._addSprite(-20, 0, this._maskBitmap);
  198.             break;
  199.         }  
  200.     };
  201. };

  202. umc.Lighting.distance = function (x1, y1, x2, y2) {
  203.     return Math.abs(Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)));
  204. };

  205. Lightmask.prototype.darkenscreen = function () {
  206.     let maxX = Number(umc.Lighting.parameters['Screensize X']);
  207.     let maxY = Number(umc.Lighting.parameters['Screensize Y']);

  208.     player_radius = $gameVariables.GetRadius();
  209.     $gameVariables.SetRadius(player_radius);

  210.     // ****** PLAYER LIGHTGLOBE ********
  211.     let canvas = this._maskBitmap.canvas;
  212.     let ctx = canvas.getContext("2d");
  213.     this._maskBitmap.fillRect(0, 0, maxX + 20, maxY+20, '#000000');
  214.     ctx.globalCompositeOperation = 'lighter';

  215.     let playercolor = $gameVariables.GetPlayerColor();
  216.     let playerbrightness = $gameVariables.GetPlayerBrightness();
  217.     let iplayer_radius = Math.floor(player_radius);

  218.     try{
  219.     if (iplayer_radius > 0) {
  220.         this._maskBitmap.radialgradientFillRect($gamePlayer.screenX(),$gamePlayer.screenY(), 0, iplayer_radius, playercolor, '#000000', playerbrightness);
  221.     }}
  222.     catch (e){};

  223.     // ********** OTHER LIGHTSOURCES **************
  224.     for (let i = 0, n = umc.Lighting.event_note.length; i < n; i++) {
  225.         let note = umc.Lighting.event_note[i];
  226.         let note_args = note.split(" ");
  227.         umc.Lighting.note_command = note_args.shift().toLowerCase();

  228.         if (umc.Lighting.note_command == "light") {
  229.             let lightsOnRadius = Number(umc.Lighting.parameters['Lights Active Radius']);
  230.             let distanceApart = Math.round(umc.Lighting.distance($gamePlayer.x, $gamePlayer.y, $gameMap.events()[umc.Lighting.event_stacknumber[i]]._realX, $gameMap.events()[umc.Lighting.event_stacknumber[i]]._realY));
  231.             if (distanceApart <= lightsOnRadius) {
  232.                 let light_radius = 1;
  233.                 light_radius = note_args.shift();
  234.                 if (light_radius >= 0) {

  235.                     let colorvalue = note_args.shift();
  236.                     let isValidColor = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(colorvalue);
  237.                     if (!isValidColor) {
  238.                         colorvalue = '#FFFFFF'
  239.                     }

  240.                     try {
  241.                         let lx1 = $gameMap.events()[umc.Lighting.event_stacknumber[i]].screenX();
  242.                         let ly1 = $gameMap.events()[umc.Lighting.event_stacknumber[i]].screenY();
  243.                         this._maskBitmap.radialgradientFillRect(lx1, ly1 - 24, 0, light_radius, colorvalue, '#000000', 0.0);
  244.                     }
  245.                     catch (e) { continue };
  246.                 }
  247.             }
  248.         } else {
  249.             continue;
  250.         };
  251.     }
  252.     ctx.globalCompositeOperation = 'lighter';
  253.     let tint_value = $gameVariables.GetTint();

  254.     if (tint_value !== 0){
  255.         this._maskBitmap.FillRect(-20, 0, maxX + 20, maxY, tint_value);
  256.     }
  257.     // reset drawmode to normal
  258.     ctx.globalCompositeOperation = 'source-over';
  259. }

  260. /**
  261. * @method _addSprite
  262. * @private
  263. */
  264. Lightmask.prototype._addSprite = function (x1, y1, selectedbitmap) {
  265.     let sprite = new Sprite(this.viewport);
  266.     sprite.bitmap = selectedbitmap;
  267.     sprite.opacity = 255;
  268.     sprite.blendMode = 2;
  269.     sprite.x = x1;
  270.     sprite.y = y1;
  271.     this._sprites.push(sprite);
  272.     this.addChild(sprite);
  273. };

  274. Bitmap.prototype.FillRect = function (x1, y1, x2, y2, color1) {
  275.     x1 = x1 + 20;
  276.     let context = this._context;
  277.     context.save();
  278.     context.fillStyle = color1;
  279.     context.fillRect(x1, y1, x2, y2);
  280.     context.restore();
  281.     //this._setDirty();
  282. };

  283. Lightmask.prototype._removeSprite = function () {
  284.     this.removeChild(this._sprites.pop());
  285. };

  286. umc.Lighting.Spriteset_Map_prototype_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
  287. Spriteset_Map.prototype.createLowerLayer = function () {
  288.     umc.Lighting.Spriteset_Map_prototype_createLowerLayer.call(this);
  289.     this.createLightmask();
  290. };
复制代码
同樣,與普通的Community Lighting插件一樣,您可以自由編輯或添加到該插件。
只需了解此插件的目標就不是要具有豐富的功能,而是要使其盡可能快。 因此,如果您要添加它,請記住這一點。 謝謝,讓我知道如何!


CommunityLightingMZDemo.zip

795.4 KB, 阅读权限: 10, 下载次数: 33

QQ群:135474765游戏群 [img]http://img2.17getfun.com/FhlesUf3VWxvhVFuc0qdBwYuanyt?imageMogr2/auto-orient/thumbnail/1080x%3E/format/jpg/

449

帖子

41

精华

25

贡献

江湖英豪

检察者

Rank: 5Rank: 5Rank: 5

积分
7245
 楼主| 发表于 2020-12-2 02:51 | 显示全部楼层
本帖最后由 大魔王 于 2020-12-2 02:53 编辑

更新使用说明


  1. <CL: Fire 100 #663300 B15>

复制代码

  1. <cl: Flashlight 6 8 #ffffff>
复制代码
在备注测试效果

详细使用方法 请看上传的范列
@WU(LJQ`9WK[_RU@61}79LE.png
JM8%VRS7%`AWCW$B`M4LHA3.png
1]2J48}ATVD1%@)RCDRYCUC.png
QQ群:135474765游戏群 [img]http://img2.17getfun.com/FhlesUf3VWxvhVFuc0qdBwYuanyt?imageMogr2/auto-orient/thumbnail/1080x%3E/format/jpg/

15

帖子

0

精华

0

贡献

江湖散人

Rank: 2Rank: 2

积分
58
发表于 2021-1-22 12:02 | 显示全部楼层
感谢大佬
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

QQ|手机版|Archiver|小黑屋|江湖梦网 ( 粤ICP备18126133号-1 )

GMT+8, 2024-12-5 10:20 , Processed in 0.274633 second(s), 28 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表