Skip to content

Commit

Permalink
各種TypeScript移行
Browse files Browse the repository at this point in the history
  • Loading branch information
elleonard committed Mar 17, 2024
1 parent 4ea77f1 commit ae5c8ee
Show file tree
Hide file tree
Showing 57 changed files with 513 additions and 150 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"fs-extra": "^11.2.0",
"glob": "^10.3.10",
"husky": "^4.2.5",
"jiti": "^1.21.0",
"lint-staged": "^12.3.8",
Expand Down
27 changes: 18 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import { globSync } from 'glob';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import applyTemplate from './extensions/rollup/rollup-apply-template';
Expand All @@ -14,26 +14,35 @@ const targetJsList = (() => {
const configTsPath = path.join(__dirname, 'src', dir, `${plugin}${versionDir}`, 'config', 'config.ts');
const pluginDir = fs.existsSync(configTsPath) ? '/plugin' : '';
return plugin
? glob.sync(path.join(__dirname, 'src', dir, `${plugin}${versionDir}${pluginDir}`, 'DarkPlasma*.js'))
? globSync(path.join(__dirname, 'src', dir, `${plugin}${versionDir}${pluginDir}`, 'DarkPlasma*.js').replace(/\\/g, "/"))
: null;
})();
return targetFile
? [targetFile].flat()
: [
glob.sync(path.join(__dirname, 'src', 'codes', '*', 'DarkPlasma*.js')),
glob.sync(path.join(__dirname, 'src', 'codes', '*', 'config', 'DarkPlasma*.js')),
glob.sync(path.join(__dirname, 'src', 'excludes', '*', 'DarkPlasma*.js')),
globSync(path.join(__dirname, 'src', 'codes', '*', 'DarkPlasma*.js')),
globSync(path.join(__dirname, 'src', 'codes', '*', 'config', 'DarkPlasma*.js')),
globSync(path.join(__dirname, 'src', 'excludes', '*', 'DarkPlasma*.js')),
].flat();
})();

const config = targetJsList.map((input) => {
const name = path.basename(input, '.js');
/**
* configのts化をする場合、1段ディレクトリがズレる
* src/codes/プラグイン名 -> _dist/codes
* src/excludes/プラグイン名/(DarkPlasma_*.js|plugin/DarkPlasma_*.js) -> _dist/excludes
* src/excludes/(グループ名)/プラグイン名/(DarkPlasma_*.js|plugin/DarkPlasma_*.js) -> _dist/(グループ名)
*/
const dir = path.dirname(input).split('/').slice(-2)[0] === process.env.TARGET.split('/').slice(-1)[0]
? path.dirname(input).split('/').slice(-3)[0]
: path.dirname(input).split('/').slice(-2)[0];
const dir = (() => {
if (/\\src\\codes/.test(path.dirname(input))) {
return "codes";
}
const match = /\\src\\excludes\\(.+?)\\(.+)(\\plugin)?/.exec(path.dirname(input));
if (match) {
return match[1];
}
return "excludes";
})();
const versionIndex = process.argv.findIndex(n => n === '-V');
const versionDir = versionIndex >= 0 ? `/v${process.argv[versionIndex+1]}` : "";
return {
Expand Down
21 changes: 21 additions & 0 deletions scripts/buildDispatcher/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@
// noFinalize: true or false

import * as fs from 'fs';
import { globSync } from 'glob';

const target = argv.target;
if (!target) {
const prefix = argv.exclude ? "src/excludes" : "src/codes";
const targets = (argv.exclude ? globSync(`./src/excludes/**/DarkPlasma_*.ts`) : globSync(`./src/codes/**/DarkPlasma_*.ts`))
.filter(path => !path.includes("_build"))
.map(path => {
path = path.replace(/\\/g, "/");
console.log(path);
const match = new RegExp(`${prefix}/(.+)/DarkPlasma_.+\.ts`).exec(path);
if (!match) {
return "";
}
return match[1].replace(/\/plugin/,"");
});
console.log(targets);
await Promise.all(
targets.map(target => $([`yarn build:config --target`, ` ${target}${argv.exclude ? " --exclude" : ""}`], ''))
);
process.exit(0);
}

const pluginTitle = target.split("/").slice(-1)[0];
const path = argv.exclude ? `./src/excludes/${target}` : `./src/codes/${target}`;

Expand Down
3 changes: 3 additions & 0 deletions scripts/generateFromConfig/generateFromConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { generateParameterReader, generateParameterReaderFunction } from './gene
import { generatePluginCommand } from './generatePluginCommand.js';
import { generateParameterType } from './generateParameterType.js';
import { generateCommandType } from './generateCommandType.js';
import { generateVersion, generateVersionType } from './generateVersion.js';

export async function generateFromConfig(file) {
const config = loadConfig(file);
Expand All @@ -26,6 +27,8 @@ export async function generateFromConfig(file) {
fs.writeFileSync(path.resolve(distDir, `${key}_parameters.d.ts`), parameterType);
const commandType = await generateCommandType(currentConfig, key.replace(`DarkPlasma_`, ''));
fs.writeFileSync(path.resolve(distDir, `${key}_commands.d.ts`), commandType);
fs.writeFileSync(path.resolve(distDir, `${key}_version.js`), generateVersion(currentConfig));
fs.writeFileSync(path.resolve(distDir, `${key}_version.d.ts`), generateVersionType(currentConfig));
}

console.log(`build config: ${file}`);
Expand Down
7 changes: 7 additions & 0 deletions scripts/generateFromConfig/generateVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function generateVersion(config) {
return `export const versionOf${config.name} = '${config.histories[0].version}'`;
}

export function generateVersionType(config) {
return `export const versionOf${config.name}: string;`;
}
2 changes: 1 addition & 1 deletion scripts/generateFromConfig/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import glob from 'glob';
import { glob } from 'glob';
import chokidar from 'chokidar';
import { fileURLToPath } from 'url';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { generateParameterReader, generateParameterReaderFunction } from './gene
import { generateParameterType } from './generateParameterType.js';
import { generatePluginCommand } from './generatePluginCommand.js';
import { generateCommandType } from './generateCommandType.js';
import { generateVersion, generateVersionType } from './generateVersion.js';

export async function generateFromTypeScriptConfig(file: string) {
const config = parseConfig(file);
Expand All @@ -27,6 +28,8 @@ export async function generateFromTypeScriptConfig(file: string) {
fs.writeFileSync(path.resolve(distDir, `${config.name}_commands.js`), pluginCommands);
const commandType = await generateCommandType(config, config.name.replace(`DarkPlasma_`, ''));
fs.writeFileSync(path.resolve(distDir, `${config.name}_commands.d.ts`), commandType);
fs.writeFileSync(path.resolve(distDir, `${config.name}_version.ts`), generateVersion(config));
fs.writeFileSync(path.resolve(distDir, `${config.name}_version.d.ts`), generateVersionType(config));

console.log(`build config: ${file}`);
console.log('');
Expand Down
9 changes: 9 additions & 0 deletions scripts/generateFromTypeScript/generateVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PluginConfigSchema } from "../../modules/config/configSchema";

export function generateVersion(config: PluginConfigSchema) {
return `export const versionOf${config.name} = '${config.histories.find(history => history.version)?.version}'`
}

export function generateVersionType(config: PluginConfigSchema) {
return `export const versionOf${config.name}: string;`;
}
2 changes: 1 addition & 1 deletion scripts/generateFromTypeScript/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import glob from 'glob';
import { glob } from 'glob';
import chokidar from 'chokidar';
import { fileURLToPath } from 'url';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="../../typings/rmmz.d.ts" />

declare interface Game_Action {
baseDebuffSuccessRate(): number;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @param {Game_Action.prototype} gameAction
*/
function Game_Action_DebuffSuccessRateMixIn(gameAction) {
function Game_Action_DebuffSuccessRateMixIn(gameAction: Game_Action) {
gameAction.baseDebuffSuccessRate = function () {
return Number(this.item().meta.debuffSuccessRate || 100) / 100;
return Number(this.item()?.meta.debuffSuccessRate || 100) / 100;
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/codes/ActionDebuffSuccessRate/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ DarkPlasma_ActionDebuffSuccessRate:
year: 2022
license: MIT
histories:
- date: 2024/03/17
version: 1.0.1
description: 'TypeScript移行'
- date: 2022/06/12
version: 1.0.0
description: '公開'
Expand Down
17 changes: 17 additions & 0 deletions src/codes/AdditionalAttackAnimation/AdditionalAttackAnimation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference path="../../typings/rmmz.d.ts" />

type AdditionalAnimation = {
animation: number;
onlyForSomeEnemies: boolean;
enemies: number[];
onlyForSomeStates: boolean;
states: number[];
};

declare interface Game_Battler {
isAdditionalAnimationTarget(additionalAnimation: AdditionalAnimation): boolean;
}

declare interface Window_BattleLog {
showAdditionalAnimation(subject: Game_Battler, targets: Game_Battler[]): void;
}
5 changes: 5 additions & 0 deletions src/codes/AdditionalAttackAnimation/MinimumDamageValue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="../../typings/rmmz.d.ts" />

declare interface Game_Action {
minimumDamageValue(target: Game_Battler): number;
}
23 changes: 13 additions & 10 deletions src/codes/AdditionalAttackAnimation/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ DarkPlasma_AdditionalAttackAnimation:
year: 2020
license: MIT
histories:
- date: '2021/07/05'
version: '2.0.3'
- date: 2024/03/17
version: 2.0.4
description: 'TypeScript移行'
- date: 2021/07/05
version: 2.0.3
description: 'MZ 1.3.2に対応'
- date: '2021/06/22'
version: '2.0.2'
- date: 2021/06/22
version: 2.0.2
description: 'サブフォルダからの読み込みに対応'
- date: '2020/11/10'
version: '2.0.1'
- date: 2020/11/10
version: 2.0.1
description: '全体化プラグインとの順序を明記'
- date: '2020/09/08'
version: '2.0.0'
- date: 2020/09/08
version: 2.0.0
description: 'パラメータ名変更'
- date: '2020/08/27'
version: '1.0.0'
- date: 2020/08/27
version: 1.0.0
description: 'MZ版公開'

locates:
Expand Down
24 changes: 24 additions & 0 deletions src/codes/AnimeLight/AnimeLight.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="../../typings/rmmz.d.ts" />

declare interface Game_Temp {
_requestedAnimeLightCharacters: Game_CharacterBase[];

requestedAnimeLightCharacter(): Game_CharacterBase|undefined;
requestAnimeLight(character: Game_CharacterBase): void;
}

declare interface Game_CharacterBase {
animeLightSetting(): Data_AnimeLight|null;
}

declare interface Game_Event {
hasAnimeLight(): boolean;
isMarkedAsAnimeLight(): boolean;
}

declare interface Spriteset_Map {
_animeLightSprites: Sprite_AnimeLight[];

initAnimeLights(): void;
updateAnimeLight(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ const DEFAULT_OPACITY = 255;
const DEFAULT_OFFSET = 0;

class Data_AnimeLight {
_filename: string;
_opacity: number;
_scale: number;
_z: number;
_offsetX: number;
_offsetY: number;
_frameLength: number;
_sinTable: number[];

/**
* @param {string} filename
* @param {number} opacity
Expand All @@ -15,7 +24,7 @@ class Data_AnimeLight {
* @param {number} scale
* @param {number} frameLength
*/
constructor(filename, opacity, offsetX, offsetY, z, scale, frameLength) {
constructor(filename: string, opacity: number, offsetX: number, offsetY: number, z: number, scale: number, frameLength: number) {
this._filename = filename;
this._opacity = opacity;
this._scale = scale || settings.defaultScale;
Expand All @@ -32,7 +41,7 @@ class Data_AnimeLight {
* @param {string} meta
* @return {Data_AnimeLight}
*/
static fromEventMeta(meta) {
static fromEventMeta(meta: string): Data_AnimeLight {
const data = meta.split(' ');
return new Data_AnimeLight(
`system/${data[0]}`,
Expand Down Expand Up @@ -86,7 +95,7 @@ PluginManager.registerCommand(pluginName, command_markAsLight, function () {});
/**
* @param {Game_Temp.prototype} gameTemp
*/
function Game_Temp_AnimeLightMixIn(gameTemp) {
function Game_Temp_AnimeLightMixIn(gameTemp: Game_Temp) {
const _initialize = gameTemp.initialize;
gameTemp.initialize = function () {
_initialize.call(this);
Expand All @@ -107,7 +116,7 @@ Game_Temp_AnimeLightMixIn(Game_Temp.prototype);
/**
* @param {Game_CharacterBase.prototype} gameCharacterBase
*/
function Game_CharacterBase_AnimeLightMixIn(gameCharacterBase) {
function Game_CharacterBase_AnimeLightMixIn(gameCharacterBase: Game_CharacterBase) {
gameCharacterBase.animeLightSetting = function () {
return null;
};
Expand All @@ -118,7 +127,7 @@ Game_CharacterBase_AnimeLightMixIn(Game_CharacterBase.prototype);
/**
* @param {Game_Event.prototype} gameEvent
*/
function Game_Event_AnimeLightMixIn(gameEvent) {
function Game_Event_AnimeLightMixIn(gameEvent: Game_Event) {
gameEvent.hasAnimeLight = function () {
return !!this.event() && !!this.event().meta.animeLight;
};
Expand Down Expand Up @@ -149,7 +158,7 @@ function Game_Event_AnimeLightMixIn(gameEvent) {
);
}
} else {
return Data_AnimeLight.fromEventMeta(this.event().meta.animeLight);
return Data_AnimeLight.fromEventMeta(String(this.event().meta.animeLight));
}
}
return null;
Expand All @@ -161,7 +170,7 @@ Game_Event_AnimeLightMixIn(Game_Event.prototype);
/**
* @param {Spriteset_Map.prototype} spritesetMap
*/
function Spriteset_Map_AnimeLightMixIn(spritesetMap) {
function Spriteset_Map_AnimeLightMixIn(spritesetMap: Spriteset_Map) {
const _initialize = spritesetMap.initialize;
spritesetMap.initialize = function () {
_initialize.call(this);
Expand Down Expand Up @@ -195,10 +204,15 @@ function Spriteset_Map_AnimeLightMixIn(spritesetMap) {
Spriteset_Map_AnimeLightMixIn(Spriteset_Map.prototype);

class Sprite_AnimeLight extends Sprite {
_animationFrame: number;
_character: Game_CharacterBase;
_setting: Data_AnimeLight;
_stopped: boolean;

/**
* @param {Game_CharacterBase} character
*/
initialize(character) {
initialize(character: Game_CharacterBase) {
super.initialize();
this.anchor.x = 0.5;
this.anchor.y = 0.5;
Expand Down
8 changes: 8 additions & 0 deletions src/codes/AreaEvent/AreaEvent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference path="../../typings/rmmz.d.ts" />

declare interface Game_Event {
_area: Game_EventArea;

isAreaEvent(): boolean;
setupArea(): void;
}
Loading

0 comments on commit ae5c8ee

Please sign in to comment.