Skip to content

Commit

Permalink
1.0.0 画像の変更で向きやパターンを設定する
Browse files Browse the repository at this point in the history
  • Loading branch information
elleonard committed Jun 6, 2024
1 parent 9a1501b commit 639b5e7
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 0 deletions.
119 changes: 119 additions & 0 deletions src/codes/ChangeImageWithPattern/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { ConfigDefinitionBuilder } from '../../../../modules/config/configDefinitionBuilder.js';
import { PluginCommandSchema, PluginHistorySchema } from '../../../../modules/config/configSchema.js';
import { createBooleanParam, createCommand, createNumberParam, createSelectParam } from '../../../../modules/config/createParameter.js';
import { dedent } from '@qnighy/dedent';

const histories: PluginHistorySchema[] = [
{
date: "2024/06/07",
version: "1.0.0",
description: "公開",
}
];

const targetSelectParam = createSelectParam("target", {
text: "対象",
description: "画像の変更をカスタマイズする対象を選びます。",
options: [
{
name: "プレイヤー",
value: -1
},
{
name: "このイベント",
value: 0,
},
{
name: "他のイベント",
value: 1,
},
],
default: 0,
});

const targetEventIdParam = createNumberParam("targetEventId", {
text: "対象イベントID",
description: "対象が他のイベントの場合のみ、対象となるイベントIDを設定します。",
default: 0,
});

const commands: PluginCommandSchema[] = [
createCommand("hackChangeImage", {
text: "画像の変更カスタム",
description: "対象の画像の変更コマンドをカスタマイズします。",
args: [
targetSelectParam,
targetEventIdParam,
createSelectParam("direction", {
text: "向き",
description: "画像の変更によって、キャラクターの向きを設定します。",
options: [
{
name: "変更しない",
value: 0,
},
{
name: "下",
value: 2,
},
{
name: "左",
value: 4,
},
{
name: "右",
value: 6,
},
{
name: "上",
value: 8,
},
],
default: 0,
}),
createSelectParam("pattern", {
text: "パターン",
description: "画像の変更によって、キャラクターのパターンを設定します。",
options: [
{
name: "左",
value: 0,
},
{
name: "真ん中",
value: 1,
},
{
name: "右",
value: 2,
},
],
default: 1,
}),
createBooleanParam("fixPattern", {
text: "パターンを固定する",
description: "画像の変更によってキャラクターのパターンを固定します。",
default: true,
}),
],
}),
createCommand("unfixPattern", {
text: "パターン固定の解除",
description: "パターン固定状態を解除します。",
args: [
targetSelectParam,
targetEventIdParam,
],
}),
];

export const config = new ConfigDefinitionBuilder(
"ChangeImageWithPattern",
2024,
"画像の変更で向きやパターンを設定する"
)
.withHistories(histories)
.withLicense("MIT")
.withCommands(commands)
.withHelp(dedent`画像の変更で向きやパターンを設定できるようにします。`)
.build();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path="../../../typings/rmmz.d.ts" />

type ChangeImageWith = {
direction: number;
pattern: number;
fixPattern: boolean;
};

declare interface Game_Character {
_changeImageWith: ChangeImageWith;
_isPatternFixed: boolean;

setChangeImageWith(changeImageWith: ChangeImageWith): void;
setChangeImageWithDirection(direction: number): void;
setChangeImageWithPattern(pattern: number): void;
setChangeImageWithFixPattern(fixPattern: boolean): void;

isPatternFixed(): boolean;
fixPattern(): void;
unfixPattern(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/// <reference path="./ChangeImageWithPattern.d.ts" />

import { pluginName } from '../../../common/pluginName';
import { command_hackChangeImage, command_unfixPattern, parseArgs_hackChangeImage, parseArgs_unfixPattern } from '../config/_build/DarkPlasma_ChangeImageWithPattern_commands';

PluginManager.registerCommand(pluginName, command_hackChangeImage, function (this: Game_Interpreter, args) {
const parsedArgs = parseArgs_hackChangeImage(args);
const target = parsedArgs.target === 1
? this.character(parsedArgs.targetEventId)
: this.character(parsedArgs.target);
target?.setChangeImageWith({
direction: parsedArgs.direction,
pattern: parsedArgs.pattern,
fixPattern: parsedArgs.fixPattern,
});
});

PluginManager.registerCommand(pluginName, command_unfixPattern, function (this: Game_Interpreter, args) {
const parsedArgs = parseArgs_unfixPattern(args);
const target = parsedArgs.target === 1
? this.character(parsedArgs.targetEventId)
: this.character(parsedArgs.target);
target?.unfixPattern();
});

function Game_Character_ChangeImageWithPatternMixIn(gameCharacter: Game_Character) {
const _initMembers = gameCharacter.initMembers;
gameCharacter.initMembers = function () {
_initMembers.call(this);
this._changeImageWith = {
direction: 0,
pattern: 1,
fixPattern: false,
};
this._isPatternFixed = false;
};

gameCharacter.setChangeImageWith = function (changeImageWith) {
this.setChangeImageWithDirection(changeImageWith.direction);
this.setChangeImageWithPattern(changeImageWith.pattern);
this.setChangeImageWithFixPattern(changeImageWith.fixPattern);
};

gameCharacter.setChangeImageWithDirection = function (direction) {
this._changeImageWith.direction = direction;
};

gameCharacter.setChangeImageWithPattern = function (pattern) {
this._changeImageWith.pattern = pattern;
};

gameCharacter.setChangeImageWithFixPattern = function (fixPattern) {
this._changeImageWith.fixPattern = fixPattern;
};

const _processMoveCommand = gameCharacter.processMoveCommand;
gameCharacter.processMoveCommand = function (command) {
_processMoveCommand.call(this, command);
if (command.code === Game_Character.ROUTE_CHANGE_IMAGE) {
if (this._changeImageWith.direction) {
/**
* 明示的に指定するため、向き固定を貫通する
*/
const isDirectionFixed = this.isDirectionFixed();
this.setDirectionFix(false);
this.setDirection(this._changeImageWith.direction);
this.setDirectionFix(isDirectionFixed);
}
this.setPattern(this._changeImageWith.pattern);
if (this._changeImageWith.fixPattern) {
this.fixPattern();
}
}
};

const _updatePattern = gameCharacter.updatePattern;
gameCharacter.updatePattern = function () {
if (this.isPatternFixed()) {
return;
}
_updatePattern.call(this);
};

gameCharacter.isPatternFixed = function () {
return this._isPatternFixed;
};

gameCharacter.fixPattern = function () {
this._isPatternFixed = true;
};

gameCharacter.unfixPattern = function () {
this._isPatternFixed = false;
};
}

Game_Character_ChangeImageWithPatternMixIn(Game_Character.prototype);

0 comments on commit 639b5e7

Please sign in to comment.