Compare commits

..

No commits in common. "e6c5fd4fde8a0651d7dea2a12721d1eee3cedd10" and "1a8b1f9a0efc2281ef158da69cf9030a0bef1181" have entirely different histories.

3 changed files with 606 additions and 393 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,6 @@ import { ExitFullscreen, Fullscreen, SoundVolume } from '../components';
import { mainSetting, triggerFullscreen } from '@motajs/legacy-ui'; import { mainSetting, triggerFullscreen } from '@motajs/legacy-ui';
import { saveLoad } from './save'; import { saveLoad } from './save';
import { MainSceneUI } from './main'; import { MainSceneUI } from './main';
import { adjustCover } from '../utils';
const enum TitleButton { const enum TitleButton {
StartGame, StartGame,
@ -60,12 +59,19 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
const bg = core.material.images.images['bg.webp']; const bg = core.material.images.images['bg.webp'];
//#region 计算背景图 //#region 计算背景图
const [width, height] = adjustCover( const aspect = bg.width / bg.height;
bg.width, const canvasAspect = MAIN_WIDTH / MAIN_HEIGHT;
bg.height, const [width, height] = (() => {
MAIN_WIDTH, if (canvasAspect > aspect) {
MAIN_HEIGHT const width = MAIN_WIDTH;
); const height = width / aspect;
return [width, height];
} else {
const height = MAIN_HEIGHT;
const width = height * aspect;
return [width, height];
}
})();
//#region 标题设置 //#region 标题设置

View File

@ -57,30 +57,3 @@ export function adjustGrid(
locs locs
}; };
} }
/**
* `object-fit: cover`
* @param itemWidth
* @param itemHeight
* @param targetWidth
* @param targetHeight
* @returns
*/
export function adjustCover(
itemWidth: number,
itemHeight: number,
targetWidth: number,
targetHeight: number
): Readonly<LocArr> {
const aspect = itemWidth / itemHeight;
const canvasAspect = targetWidth / targetHeight;
if (canvasAspect > aspect) {
const width = targetWidth;
const height = width / aspect;
return [width, height];
} else {
const height = targetHeight;
const width = height * aspect;
return [width, height];
}
}