Skip to content

Commit

Permalink
2.0.0 シーンが切り替わるとテキストが消える不具合を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
elleonard committed Apr 21, 2024
1 parent aa5f7ae commit 2a3e165
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/codes/CharacterText/CharacterText.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ declare interface Game_Temp {

declare interface Game_Character {
mustShowText(): boolean;
hasText(): boolean;
requestSetupCharacterText(): void;
}

declare interface Spriteset_Map {
_characterTexts: Sprite_CharacterText[];
createCharacterText(request: Game_SetupCharacterTextRequest): void;
createCharacterText(character: Game_Character): void;
setupCharacterText(request: Game_SetupCharacterTextRequest): void;
hideAllCharacterTexts(): void;
updateCharacterTexts(): void;
}

declare interface Sprite_CharacterText extends Sprite {
isCharacter(character: Game_Character): boolean;
setup(text: string, offsetX: number, offsetY: number): void;
}
58 changes: 46 additions & 12 deletions src/codes/CharacterText/DarkPlasma_CharacterText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function Game_Character_CharacterTextMixIn(gameCharacter: Game_Character) {
gameCharacter.mustShowText = function () {
return false;
};

gameCharacter.hasText = function () {
return false;
};

gameCharacter.requestSetupCharacterText = function () {};
}

Game_Character_CharacterTextMixIn(Game_Character.prototype);
Expand All @@ -67,7 +73,19 @@ function Game_Event_CharacterTextMixIn(gameEvent: Game_Event) {
const _setupPageSettings = gameEvent.setupPageSettings;
gameEvent.setupPageSettings = function () {
_setupPageSettings.call(this);
if (this.event().meta.characterText) {
this.requestSetupCharacterText();
};

gameEvent.mustShowText = function () {
return $gameTemp.mustShowCharacterTextCache(this._mapId, this._eventId) && !this.isTransparent();
};

gameEvent.hasText = function () {
return !!this.event().meta.characterText;
};

gameEvent.requestSetupCharacterText = function () {
if (this.hasText()) {
const registerCommand = this.list()
.find(command => command.code === 357
&& Utils.extractFileName(command.parameters[0]) === pluginName
Expand All @@ -88,26 +106,34 @@ function Game_Event_CharacterTextMixIn(gameEvent: Game_Event) {
}
}
};

gameEvent.mustShowText = function () {
return $gameTemp.mustShowCharacterTextCache(this._mapId, this._eventId) && !this.isTransparent();
};
}

Game_Event_CharacterTextMixIn(Game_Event.prototype);

function Spriteset_Map_CharacterTextMixIn(spritesetMap: Spriteset_Map) {
const _initialize = spritesetMap.initialize;
spritesetMap.initialize = function() {
_initialize.call(this);
this._characterTexts = [];
_initialize.call(this);
};

spritesetMap.createCharacterText = function (request) {
const sprite = new Sprite_CharacterText();
sprite.setup(request.text, request.character, request.offset.x, request.offset.y);
const _createCharacters = spritesetMap.createCharacters;
spritesetMap.createCharacters = function () {
_createCharacters.call(this);
$gameMap.events().filter(event => event.hasText()).forEach(event => this.createCharacterText(event));
};

spritesetMap.createCharacterText = function (character) {
const sprite = new Sprite_CharacterText(character);
this._characterTexts.push(sprite);
this._tilemap.addChild(sprite);
character.requestSetupCharacterText();
};

spritesetMap.setupCharacterText = function (request) {
this._characterTexts
.find(sprite => sprite.isCharacter(request.character))
?.setup(request.text, request.offset.x, request.offset.y);
};

const _update = spritesetMap.update;
Expand All @@ -122,7 +148,7 @@ function Spriteset_Map_CharacterTextMixIn(spritesetMap: Spriteset_Map) {
$gameTemp.clearHideAllCharacterTextsRequest();
}
const setupRequests = $gameTemp.setupCharacterTextRequests();
setupRequests.forEach(request => this.createCharacterText(request));
setupRequests.forEach(request => this.setupCharacterText(request));
$gameTemp.clearSetupCharacterTextRequests();
};

Expand All @@ -140,10 +166,18 @@ class Sprite_CharacterText extends Sprite {
_offsetY: number;
_forceHidden: boolean;

setup(text: string, character: Game_Character, offsetX: number, offsetY: number) {
constructor(character: Game_Character) {
super();
this._character = character;
}

isCharacter(character: Game_Character) {
return this._character === character;
}

setup(text: string, offsetX: number, offsetY: number) {
this.anchor.x = 0.5;
this._text = text;
this._character = character;
this._offsetX = offsetX;
this._offsetY = offsetY;
this.createBitmap();
Expand Down
6 changes: 5 additions & 1 deletion src/codes/CharacterText/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ DarkPlasma_CharacterText:
year: 2023
license: MIT
histories:
- date: 2024/04/21
version: 2.0.0
description: 'シーンが切り替わるとテキストが消える不具合を修正'
- description: 'Spriteset_Mapの一部メソッドのインターフェースに関する破壊的な変更'
- date: 2024/02/15
version: 1.0.1
description: '有効なページがないイベントにメタタグを設定するとエラーになる不具合を修正'
Expand Down Expand Up @@ -60,5 +64,5 @@ DarkPlasma_CharacterText:
表示したいイベントのメモ欄に <characterText> と記述し、
表示したいページにテキストを登録するプラグインコマンドを記述してください。
一時的に非表示にするプラグインコマンド一度非表示になったテキストは
一時的に非表示にするプラグインコマンドで一度非表示になったテキストは
マップ移動を行うと再度表示されます。

0 comments on commit 2a3e165

Please sign in to comment.