Skip to content

Commit

Permalink
Merge pull request #277 from OpenWebGAL/dev
Browse files Browse the repository at this point in the history
4.5.3
  • Loading branch information
MakinoharaShoko authored Jun 30, 2024
2 parents 5cee400 + 1160a44 commit 3085b40
Show file tree
Hide file tree
Showing 52 changed files with 1,031 additions and 767 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webgal-terre",
"version": "4.5.2",
"version": "4.5.3",
"private": true,
"scripts": {
"dev": "concurrently \"yarn dev:terre\" \"yarn dev:origine\" \"yarn dev:start-dev-server\"",
Expand Down
9 changes: 6 additions & 3 deletions packages/WebGAL-electron/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, globalShortcut, Menu } = require('electron');
const {app, BrowserWindow, globalShortcut, Menu} = require('electron');
const log = require('electron-log');

/**
Expand Down Expand Up @@ -26,7 +26,10 @@ const createWindow = () => {
height: 900
})

win.loadFile('./public/index.html').then(r => console.log(r));
win.loadFile('./public/index.html').then(r => {
console.log(r)
win.webContents.executeJavaScript('window.isElectron = true')
});

// 注册快捷键 Ctrl + F12 切换开发者工具
globalShortcut.register("Ctrl+F12", () => {
Expand Down Expand Up @@ -58,4 +61,4 @@ const createWindow = () => {
*/
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
})
2 changes: 1 addition & 1 deletion packages/origine2/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webgal-origine-2",
"private": true,
"version": "4.5.2",
"version": "4.5.3",
"license": "MPL-2.0",
"scripts": {
"dev": "lingui extract && lingui compile --typescript && vite --host",
Expand Down
85 changes: 45 additions & 40 deletions packages/origine2/src/components/Assets/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ import FileElement from "./FileElement";
import axios from "axios";
import { dirNameToExtNameMap } from "@/pages/editor/ChooseFile/chooseFileConfig";
import useSWR, { useSWRConfig } from "swr";
import {t} from '@lingui/macro';
import { t } from '@lingui/macro';
import Upload from "./Upload";

export interface IFile {
extName: string;
isDir: boolean;
name: string;
path: string;
pathFromBase?: string;
}

export type IFolderType = 'animation' | 'background' | 'bgm' | 'figure' | 'scene' | 'template' | 'tex' | 'video' | 'vocal'

export type IFileConfig = Map<
string,
{
desc?: string,
folderType?: IFolderType,
isProtected?: boolean,
}
string,
{
desc?: string,
folderType?: IFolderType,
isProtected?: boolean,
isHidden?: boolean,
}
>

export interface IFileFunction {
Expand All @@ -44,9 +46,9 @@ const MoreVerticalIcon = bundleIcon(MoreVerticalFilled, MoreVerticalRegular);
const ArrowExportUpIcon = bundleIcon(ArrowExportUpFilled, ArrowExportUpRegular);
const ArrowSyncIcon = bundleIcon(ArrowSyncFilled, ArrowSyncRegular);

export default function Assets({basePath, isProtected = false, fileConfig, fileFunction}:
{basePath: string[], isProtected?: boolean, fileConfig?: IFileConfig, fileFunction?: IFileFunction}) {
const {mutate} = useSWRConfig();
export default function Assets({ basePath, isProtected = false, fileConfig, fileFunction }:
{ basePath: string[], isProtected?: boolean, fileConfig?: IFileConfig, fileFunction?: IFileFunction }) {
const { mutate } = useSWRConfig();

const currentPath = useValue(basePath);
const currentPathString = useMemo(() => currentPath.value.join("/"), [currentPath]);
Expand All @@ -60,14 +62,14 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
if ('dirInfo' in data && data.dirInfo) {
const dirInfo = (data.dirInfo as IFile[]).map((item) => ({ ...item, path: currentPathString + '/' + item.name }));
const dirs = dirInfo.filter((item) => item.isDir);
const files = dirInfo.filter((item) => !item.isDir).filter(e=>e.name!=='.gitkeep');
const files = dirInfo.filter((item) => !item.isDir).filter(e => e.name !== '.gitkeep');
dirs.sort((a, b) => a.name.localeCompare(b.name));
files.sort((a, b) => a.name.localeCompare(b.name));
return [...dirs, ...files];
} else return [];
};

const {data: fileList} = useSWR(currentPathString, assetsFetcher);
const { data: fileList } = useSWR(currentPathString, assetsFetcher);

const handleRefresh = () => mutate(currentPathString);
const handleOpenFolder = () => api.assetsControllerOpenDict(currentPathString);
Expand All @@ -77,8 +79,9 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
if (file.isDir) {
currentPath.set([...currentPath.value, file.name]);
} else {
const pathFromBase = (currentPath.value.slice(basePath.length)).concat([file.name]).join('/');
const isScene = (folderType === 'scene') && file.name.endsWith('.txt');
fileFunction?.open && fileFunction.open(file, isScene ? 'scene' : 'asset');
fileFunction?.open && fileFunction.open({...file, pathFromBase}, isScene ? 'scene' : 'asset');
}
};

Expand All @@ -100,12 +103,12 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
handleRefresh();
};

const handleDeleteFile = async (source: string) =>{
const handleDeleteFile = async (source: string) => {
await api.assetsControllerDeleteFileOrDir({ source });
fileFunction?.delete && await fileFunction.delete(source);
handleRefresh();
};
const handlePreventDefault = async (e: any) =>{
const handlePreventDefault = async (e: any) => {
e.preventDefault();
};
const createNewFilePopoverOpen = useValue(false);
Expand All @@ -116,10 +119,10 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF

return (
<div style={{ display: 'flex', flexDirection: 'column', overflow: 'hidden', height: '100%' }}
onDragEnter={(e)=> handlePreventDefault(e)}
onDragLeave={(e)=>handlePreventDefault(e)}
onDragOver={(e)=> handlePreventDefault(e)}
onDrop={(e)=>{
onDragEnter={(e) => handlePreventDefault(e)}
onDragLeave={(e) => handlePreventDefault(e)}
onDragOver={(e) => handlePreventDefault(e)}
onDrop={(e) => {
handlePreventDefault(e);
const files = e.dataTransfer.files;
const formData = new FormData();
Expand All @@ -142,7 +145,7 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
style={{ flexGrow: 1, minWidth: 0 }}
/>

{ !isProtected && <>
{!isProtected && <>
<Popover
withArrow
open={createNewFilePopoverOpen.value}
Expand All @@ -159,7 +162,7 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
placeholder={t`新文件名`}
onChange={(_, data) => {
newFileName.set(data.value ?? "");
} } />
}} />
<Field label={t`扩展名`} size='small'>
<RadioGroup value={newFileExtensionName.value} onChange={(_, data) => newFileExtensionName.set(data.value)}>
<Radio value="" label={t`无`} />
Expand All @@ -174,7 +177,7 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
handleCreateNewFile(currentPathString, `${newFileName.value.trim()}${newFileExtensionName.value}`);
createNewFilePopoverOpen.set(false);
newFileName.set('');
} }
}}
>{t`创建`}</Button>
</div>
</PopoverSurface>
Expand All @@ -194,15 +197,15 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
placeholder={t`新文件夹名`}
onChange={(_, data) => {
newFileName.set(data.value ?? "");
} } />
}} />
<Button
appearance="primary"
disabled={newFileName.value.trim() === ''}
onClick={() => {
handleCreateNewFolder(currentPathString, newFileName.value.trim());
createNewFolderPopoverOpen.set(false);
newFileName.set('');
} }
}}
>{t`创建`}</Button>
</div>
</PopoverSurface>
Expand All @@ -225,7 +228,7 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF

<Menu>
<MenuTrigger>
<Button icon={<MoreVerticalIcon />} size='small'/>
<Button icon={<MoreVerticalIcon />} size='small' />
</MenuTrigger>
<MenuPopover>
<MenuList>
Expand All @@ -237,15 +240,15 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
</div>
{
extName && extName.length > 0 &&
<div style={{display: 'flex', padding: '4px 8px', gap: '4px'}}>
<div style={{ display: 'flex', padding: '4px 8px', gap: '4px' }}>
{extName.map(item => <Badge appearance='outline' key={item}>{item}</Badge>)}
</div>
}
<div style={{ overflow: 'auto', padding: '4px' }}
onDragEnter={(e)=>handlePreventDefault(e)}
onDragLeave={(e)=> handlePreventDefault(e)}
onDragOver={(e)=> handlePreventDefault(e)}
onDrop={(e)=>{
onDragEnter={(e) => handlePreventDefault(e)}
onDragLeave={(e) => handlePreventDefault(e)}
onDragOver={(e) => handlePreventDefault(e)}
onDrop={(e) => {
handlePreventDefault(e);
const files = e.dataTransfer.files;
const formData = new FormData();
Expand All @@ -262,16 +265,18 @@ export default function Assets({basePath, isProtected = false, fileConfig, fileF
}}>
{
fileList?.map(file =>
<FileElement
key={file.name}
file={file}
desc={fileConfig?.get(`${currentPathString}/${file.name}`)?.desc ?? undefined}
currentPath={currentPath}
isProtected={fileConfig?.get(`${currentPathString}/${file.name}`)?.isProtected ?? isProtected}
handleOpenFile={handleOpenFile}
handleRenameFile={handleRenameFile}
handleDeleteFile={handleDeleteFile}
/>
(fileConfig?.get(`${currentPathString}/${file.name}`)?.isHidden) // 判断是否隐藏
? null
: <FileElement
key={file.name}
file={file}
desc={fileConfig?.get(`${currentPathString}/${file.name}`)?.desc ?? undefined}
currentPath={currentPath}
isProtected={fileConfig?.get(`${currentPathString}/${file.name}`)?.isProtected ?? isProtected}
handleOpenFile={handleOpenFile}
handleRenameFile={handleRenameFile}
handleDeleteFile={handleDeleteFile}
/>
)
}
</div>
Expand Down
53 changes: 27 additions & 26 deletions packages/origine2/src/components/Assets/FileElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IFile } from "./Assets";
import styles from "./FileElement.module.scss";
import { useValue } from '../../hooks/useValue';
import { bundleIcon, RenameFilled, RenameRegular, DeleteFilled, DeleteRegular, DesktopMacFilled, DesktopMacRegular } from "@fluentui/react-icons";
import {t} from "@lingui/macro";
import { t } from "@lingui/macro";
import { useRef } from "react";

const RenameIcon = bundleIcon(RenameFilled, RenameRegular);
Expand All @@ -25,9 +25,9 @@ export default function FileElement(
}) {
const newFileName = useValue(file.name);
const ShowThumbPopoverOpen = useValue(false);
const FileItemSelfRef = useRef(null);
const FileItemSelfRef = useRef(null);

const is_picture = (extName:string)=> extractExtension(extName) === 'image' ? true : false;
const is_picture = (extName: string) => extractExtension(extName) === 'image' ? true : false;

return (
<div
Expand All @@ -46,12 +46,12 @@ export default function FileElement(
}}
>
<span
onMouseEnter={(e)=>{
if(is_picture(file.extName)) ShowThumbPopoverOpen.value = true;
onMouseEnter={(e) => {
if (is_picture(file.extName)) ShowThumbPopoverOpen.value = true;
}}
onMouseOut={(e)=>{
onMouseOut={(e) => {
ShowThumbPopoverOpen.value = false;
}}>{file.name}</span> {desc && <span style={{color:'var(--text-weak)', fontSize: '12px', fontStyle: 'italic', }}>{desc}</span>}
}}>{file.name}</span> {desc && <span style={{ color: 'var(--text-weak)', fontSize: '12px', fontStyle: 'italic', }}>{desc}</span>}
</div>

{
Expand Down Expand Up @@ -91,7 +91,7 @@ export default function FileElement(
onClick={(e) => e.stopPropagation()} />
</PopoverTrigger>
<PopoverSurface onClick={(e) => e.stopPropagation()}>
<div style={{ display: "flex", flexFlow: "column", gap: "16px"}}>
<div style={{ display: "flex", flexFlow: "column", gap: "16px" }}>
<Subtitle1>{t`删除`}</Subtitle1>
<Button
appearance="primary"
Expand All @@ -103,26 +103,27 @@ export default function FileElement(
</div>
</PopoverSurface>
</Popover>
{is_picture(file.extName) ? <Popover
withArrow
open={ShowThumbPopoverOpen.value}
onOpenChange={() => ShowThumbPopoverOpen.set(!ShowThumbPopoverOpen.value)}
>
<PopoverTrigger>
<Button
icon={<ThumbIcon style={{ width: '16px' }} />} size='small' appearance='subtle'
onClick={(e) => e.stopPropagation()} />
</PopoverTrigger>
<PopoverSurface>
<div style={{width:"200px",display:"inline-block"}}>
<img src={file.path} style={{objectFit:"cover"}} alt={file.path}
decoding="async" loading="lazy" width={200} />
</div>
</PopoverSurface>
</Popover>: ''
}
</>
}
{
is_picture(file.extName) ? <Popover
withArrow
open={ShowThumbPopoverOpen.value}
onOpenChange={() => ShowThumbPopoverOpen.set(!ShowThumbPopoverOpen.value)}
>
<PopoverTrigger>
<Button
icon={<ThumbIcon style={{ width: '16px' }} />} size='small' appearance='subtle'
onClick={(e) => e.stopPropagation()} />
</PopoverTrigger>
<PopoverSurface style={{ padding: '8px', }}>
<div style={{ width: "200px", maxHeight: "300px", overflow: 'hidden', display: "inline-block" }}>
<img src={file.path} style={{ objectFit: "cover" }} alt={file.path}
decoding="async" loading="lazy" width='100%' height='100%' />
</div>
</PopoverSurface>
</Popover> : ''
}
</div>
);
}
2 changes: 1 addition & 1 deletion packages/origine2/src/config/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export interface Info {
}

export const __INFO: Info = {
version: '4.5.2',
version: '4.5.3',
buildTime: '2024-06-14T15:46:25.585Z', // 编译时会通过 version-sync.js 自动更新
};
Loading

0 comments on commit 3085b40

Please sign in to comment.