Skip to content

Commit

Permalink
✨ Add a built-in asset gallery of CC0/WTFPL assets
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoMyzrailGorynych committed Feb 22, 2022
1 parent 0c9d5cc commit ddb8301
Show file tree
Hide file tree
Showing 141 changed files with 597 additions and 227 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "docs"]
path = docs
url = https://github.com/ct-js/docs.ctjs.rocks.git
[submodule "bundledAssets"]
path = bundledAssets
url = https://github.com/ct-js/bundled-assets.git
27 changes: 26 additions & 1 deletion app/data/i18n/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@
"addToNotes": "Add to notes",
"noRooms": "You need at least one room to compile your app.",
"tileLayer": "tile layer",
"ctSite": "ct.js homepage"
"ctSite": "ct.js homepage",
"openAssetGallery": "Gallery",
"assetTypes": {
"textures": ["texture", "textures", "textures"],
"templates": ["template", "templates", "templates"],
"emitterTandems": ["emitter tandem", "emitter tandems", "emitter tandems"],
"rooms": ["room", "rooms", "rooms"],
"fonts": ["font", "fonts", "fonts"],
"styles": ["style", "styles", "styles"],
"sounds": ["sound", "sounds", "sounds"],
"skeletons": ["skeletal sprite", "skeletal sprites", "skeletal sprites"]
}
},
"assetInput": {
"changeAsset": "Press to change the asset",
Expand All @@ -92,6 +103,20 @@
"newGroupName": "New group",
"groupDeletionConfirmation": "Are you sure you want to delete this group? All its assets will be ungrouped."
},
"builtinAssetGallery": {
"galleryTip": "This is a free, built-in gallery of various textures and sounds. All the assets are CC0 or WTFPL, or are released under special terms for use in ct.js. In any way, you can use these assets however you like, in commercial and other projects.",
"assetGalleryHeader": "Assets",
"importIntoProject": "Import into the current project",
"importAll": "Import all",
"byAuthorPrefix": "by",
"cannotImportExplanation": "The name that this asset would take is taken by some other asset. You may need to rename existing assets; or maybe you've already imported this asset?",
"nameOccupied": "Name occupied",
"cannotImportNameOccupied": "Cannot import $1 as such name is already occupied.",
"visitSource": "Open the store page of this asset pack",
"visitAuthorsItch": "Visit author's itch.io page",
"visitAuthorsTwitter": "Visit author's Twitter page",
"tipAuthor": "Tip the author for their hard work :D"
},
"colorPicker": {
"current": "New",
"globalPalette": "Global Palette",
Expand Down
Binary file removed app/data/particles/Circle_01.png
Binary file not shown.
Binary file removed app/data/particles/Circle_02.png
Binary file not shown.
Binary file removed app/data/particles/Circle_03.png
Binary file not shown.
Binary file removed app/data/particles/Circle_04.png
Binary file not shown.
Binary file removed app/data/particles/Circle_05.png
Binary file not shown.
Binary file removed app/data/particles/Circle_06.png
Binary file not shown.
Binary file removed app/data/particles/Circle_07.png
Binary file not shown.
Binary file removed app/data/particles/Circle_08.png
Binary file not shown.
Binary file removed app/data/particles/Confetti_01.png
Binary file not shown.
Binary file removed app/data/particles/Confetti_02.png
Binary file not shown.
Binary file removed app/data/particles/Confetti_03.png
Binary file not shown.
Binary file removed app/data/particles/Confetti_04.png
Binary file not shown.
Binary file removed app/data/particles/Confetti_2x2.png
Binary file not shown.
Binary file removed app/data/particles/Dirt_01.png
Binary file not shown.
Binary file removed app/data/particles/Dirt_02.png
Binary file not shown.
Binary file removed app/data/particles/Dirt_03.png
Binary file not shown.
Binary file removed app/data/particles/Dirt_3x1.png
Binary file not shown.
Binary file removed app/data/particles/FireCartoon_01.png
Binary file not shown.
Binary file removed app/data/particles/FireCartoon_02.png
Binary file not shown.
Binary file removed app/data/particles/FireCartoon_03.png
Binary file not shown.
Binary file removed app/data/particles/FireCartoon_04.png
Binary file not shown.
Binary file removed app/data/particles/FireCartoon_2x2.png
Binary file not shown.
Binary file removed app/data/particles/Fire_01.png
Binary file not shown.
Binary file removed app/data/particles/Fire_02.png
Binary file not shown.
Binary file removed app/data/particles/Fire_2x1.png
Binary file not shown.
Binary file removed app/data/particles/FlameLeaks_2x1.png
Diff not rendered.
Binary file removed app/data/particles/Flame_01.png
Diff not rendered.
Binary file removed app/data/particles/Flame_02.png
Diff not rendered.
Binary file removed app/data/particles/Flame_03.png
Diff not rendered.
Binary file removed app/data/particles/Flame_04.png
Diff not rendered.
Binary file removed app/data/particles/Flame_05.png
Diff not rendered.
Binary file removed app/data/particles/Flame_06.png
Diff not rendered.
Binary file removed app/data/particles/Flame_2x2.png
Diff not rendered.
Binary file removed app/data/particles/Flare_01.png
Diff not rendered.
Binary file removed app/data/particles/Light_01.png
Diff not rendered.
Binary file removed app/data/particles/Light_02.png
Diff not rendered.
Binary file removed app/data/particles/Light_03.png
Diff not rendered.
Binary file removed app/data/particles/Magic_01.png
Diff not rendered.
Binary file removed app/data/particles/Magic_02.png
Diff not rendered.
Binary file removed app/data/particles/Magic_03.png
Diff not rendered.
Binary file removed app/data/particles/Magic_04.png
Diff not rendered.
Binary file removed app/data/particles/Magic_05.png
Diff not rendered.
Binary file removed app/data/particles/Muzzle_01.png
Diff not rendered.
Binary file removed app/data/particles/Muzzle_02.png
Diff not rendered.
Binary file removed app/data/particles/Muzzle_03.png
Diff not rendered.
Binary file removed app/data/particles/Muzzle_04.png
Diff not rendered.
Binary file removed app/data/particles/Muzzle_05.png
Diff not rendered.
Binary file removed app/data/particles/[email protected]
Diff not rendered.
Binary file removed app/data/particles/Scorch_01.png
Diff not rendered.
Binary file removed app/data/particles/Scorch_02.png
Diff not rendered.
Binary file removed app/data/particles/Scorch_03.png
Diff not rendered.
Binary file removed app/data/particles/Scorch_3x1.png
Diff not rendered.
Binary file removed app/data/particles/Scratch_01.png
Diff not rendered.
Binary file removed app/data/particles/Slash_01.png
Diff not rendered.
Binary file removed app/data/particles/Slash_02.png
Diff not rendered.
Binary file removed app/data/particles/Slash_03.png
Diff not rendered.
Binary file removed app/data/particles/Slash_04.png
Diff not rendered.
Binary file removed app/data/particles/SmokeRing_2x1.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_01.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_02.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_03.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_04.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_05.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_06.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_07.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_08.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_09.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_10.png
Diff not rendered.
Binary file removed app/data/particles/Smoke_4x2.png
Diff not rendered.
Binary file removed app/data/particles/Spark_01.png
Diff not rendered.
Binary file removed app/data/particles/Spark_02.png
Diff not rendered.
Binary file removed app/data/particles/Spark_03.png
Diff not rendered.
Binary file removed app/data/particles/Spark_04.png
Diff not rendered.
Binary file removed app/data/particles/Spark_05.png
Diff not rendered.
Binary file removed app/data/particles/Spark_06.png
Diff not rendered.
Binary file removed app/data/particles/Spark_07.png
Diff not rendered.
Binary file removed app/data/particles/Spark_2x2.png
Diff not rendered.
Binary file removed app/data/particles/Star_01.png
Diff not rendered.
Binary file removed app/data/particles/Star_02.png
Diff not rendered.
Binary file removed app/data/particles/Star_03.png
Diff not rendered.
Binary file removed app/data/particles/Star_04.png
Diff not rendered.
Binary file removed app/data/particles/Star_05.png
Diff not rendered.
Binary file removed app/data/particles/Star_06.png
Diff not rendered.
Binary file removed app/data/particles/Star_07.png
Diff not rendered.
Binary file removed app/data/particles/Star_08.png
Diff not rendered.
Binary file removed app/data/particles/Star_09.png
Diff not rendered.
Binary file removed app/data/particles/Star_10.png
Diff not rendered.
Binary file removed app/data/particles/Star_11.png
Diff not rendered.
Binary file removed app/data/particles/Symbol_01.png
Diff not rendered.
Binary file removed app/data/particles/Symbol_02.png
Diff not rendered.
Binary file removed app/data/particles/Symbol_03.png
Diff not rendered.
Binary file removed app/data/particles/Symbol_04.png
Diff not rendered.
Binary file removed app/data/particles/Trace_01.png
Diff not rendered.
Binary file removed app/data/particles/Trace_02.png
Diff not rendered.
Binary file removed app/data/particles/Trace_03.png
Diff not rendered.
Binary file removed app/data/particles/Trace_04.png
Diff not rendered.
Binary file removed app/data/particles/Trace_05.png
Diff not rendered.
Binary file removed app/data/particles/Trace_06.png
Diff not rendered.
Binary file removed app/data/particles/Trace_07.png
Diff not rendered.
Binary file removed app/data/particles/Trace_3x1.png
Diff not rendered.
Binary file removed app/data/particles/Twirl_01.png
Diff not rendered.
Binary file removed app/data/particles/Twirl_02.png
Diff not rendered.
Binary file removed app/data/particles/Twirl_03.png
Diff not rendered.
Binary file removed app/data/particles/Vertigo_01.png
Diff not rendered.
Binary file removed app/data/particles/Vertigo_02.png
Diff not rendered.
Binary file removed app/data/particles/Vertigo_03.png
Diff not rendered.
Binary file removed app/data/particles/Vertigo_04.png
Diff not rendered.
Binary file removed app/data/particles/Vertigo_2x2.png
Diff not rendered.
Binary file removed app/data/particles/Window_01.png
Diff not rendered.
Binary file removed app/data/particles/Window_02.png
Diff not rendered.
Binary file removed app/data/particles/Window_03.png
Diff not rendered.
Binary file removed app/data/particles/Window_04.png
Diff not rendered.
1 change: 1 addition & 0 deletions bundledAssets
Submodule bundledAssets added at 29b377
1 change: 1 addition & 0 deletions src/icons/log-in.svg
1 change: 1 addition & 0 deletions src/icons/log-out.svg
23 changes: 18 additions & 5 deletions src/node_requires/extendGlobals.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
// eslint-disable-next-line spaced-comment
/// <reference types="../../app/node_modules/pixi.js/" />

export {};
declare global {
var signals: any;
var orders: any;
var alertify: any;
var languageJSON: any;
var monaco: any;
var currentProject: IProject;
var projdir: string;
function showOpenDialog(options: any): Promise<string | false>;
function showSaveDialog(options: any): Promise<string | false>;
interface Window {
signals: any;
orders: any;
alertify: any;
currentProject: any;
currentProject: IProject;
languageJSON: any;
monaco: any;
projdir: string;
showOpenDialog(options: any): Promise<string | false>;
showSaveDialog(options: any): Promise<string | false>;
}
var signals: any;
var orders: any;
var alertify: any;
var currentProject: any;
}
declare namespace PIXI {
var Texture: any;
Expand Down
2 changes: 1 addition & 1 deletion src/node_requires/imageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const outputCanvasToFile = function (canvas: HTMLCanvasElement, targetFile: stri
return fs.outputFile(targetFile, buffer);
};

module.exports = {
export {
imageCover,
imageContain,
imagePlaceInRect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const isWin = (/win[0-9]+/).test(os.platform());
const isLinux = os.platform() === 'linux';
const isMac = !(isWin || isLinux);

// We compute a directory once and store it forever
let exportDir: string,
exportDirPromise: Promise<string>,
buildDir: string,
buildDirPromise: Promise<string>,
projectsDir: string,
projectsDirPromise: Promise<string>;

const mod = {
isWin,
isWindows: isWin,
Expand All @@ -18,10 +26,10 @@ const mod = {
* @param {String} way A path to check against
* @returns {Promise<Boolean>} Resolves into either `true` (if writable) or `false`
*/
checkWritable(way) {
checkWritable(way: string): Promise<boolean> {
return new Promise(resolve => {
// eslint-disable-next-line no-bitwise
fs.access(way, fs.constants.R_OK | fs.constants.W_OK, err => {
fs.access(way, fs.constants.R_OK | fs.constants.W_OK, (err: Error) => {
if (err) {
resolve(false);
} else {
Expand All @@ -36,7 +44,7 @@ const mod = {
*
* @returns {Promise<String>} A writable directory
*/
async getWritableDir() {
async getWritableDir(): Promise<string> {
if (localStorage.customWritableDir) {
if (!(await mod.checkWritable(localStorage.customWritableDir))) {
throw new Error(`Custom data folder ${localStorage.customWritableDir} is read-only`);
Expand Down Expand Up @@ -72,71 +80,16 @@ const mod = {
}
return exec;
},
async getTempDir() {
async getTempDir(): Promise<{dir: string, remove: () => void}> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'ctjs-'));
return {
dir,
remove() {
return fs.remove(dir);
}
};
}
};

{
let exportDir,
exportDirPromise,
buildDir,
buildDirPromise,
projectsDir,
projectsDirPromise;
// We compute a directory once and store it forever
mod.getExportDir = () => {
if (exportDir) {
return Promise.resolve(exportDir);
}
if (exportDirPromise) {
return exportDirPromise;
}
exportDirPromise = mod.getWritableDir().then(async ctjsDir => {
const dir = require('path').join(ctjsDir, 'Exported');
await fs.ensureDir(dir);
exportDir = dir;
return exportDir;
});
return exportDirPromise;
};
mod.getBuildDir = () => {
if (buildDir) {
return Promise.resolve(buildDir);
}
if (buildDirPromise) {
return buildDirPromise;
}
buildDirPromise = mod.getWritableDir().then(async ctjsDir => {
const dir = require('path').join(ctjsDir, 'Builds');
await fs.ensureDir(dir);
buildDir = dir;
return buildDir;
});
return buildDirPromise;
};
mod.getProjectsDir = () => {
if (projectsDir) {
return Promise.resolve(projectsDir);
}
if (projectsDirPromise) {
return projectsDirPromise;
}
projectsDirPromise = mod.getWritableDir().then(async ctjsDir => {
const dir = require('path').join(ctjsDir, 'Projects');
await fs.ensureDir(dir);
projectsDir = dir;
return projectsDir;
});
return projectsDirPromise;
};
mod.requestWritableDir = async () => {
},
requestWritableDir: async (): Promise<boolean> => {
const voc = window.languageJSON.writableFolderSelector;
const folder = await window.showOpenDialog({
openDirectory: true,
Expand All @@ -161,7 +114,58 @@ const mod = {
window.alertify.error(voc.folderDoesNotExist);
}
return false;
};
}

module.exports = mod;
},
getGalleryDir(createHref?: boolean): string {
const path = require('path');
if (createHref) {
return ('file://' + path.posix.normalize(path.join((nw.App as any).startPath, 'bundledAssets')));
}
return path.join((nw.App as any).startPath, 'bundledAssets');
},
getProjectsDir(): Promise<string> {
if (projectsDir) {
return Promise.resolve(projectsDir);
}
if (projectsDirPromise) {
return projectsDirPromise;
}
projectsDirPromise = mod.getWritableDir().then(async (ctjsDir: string) => {
const dir = require('path').join(ctjsDir, 'Projects');
await fs.ensureDir(dir);
projectsDir = dir;
return projectsDir;
});
return projectsDirPromise;
},
getBuildDir(): Promise<string> {
if (buildDir) {
return Promise.resolve(buildDir);
}
if (buildDirPromise) {
return buildDirPromise;
}
buildDirPromise = mod.getWritableDir().then(async (ctjsDir: string) => {
const dir = require('path').join(ctjsDir, 'Builds');
await fs.ensureDir(dir);
buildDir = dir;
return buildDir;
});
return buildDirPromise;
},
getExportDir(): Promise<string> {
if (exportDir) {
return Promise.resolve(exportDir);
}
if (exportDirPromise) {
return exportDirPromise;
}
exportDirPromise = mod.getWritableDir().then(async ctjsDir => {
const dir = require('path').join(ctjsDir, 'Exported');
await fs.ensureDir(dir);
exportDir = dir;
return exportDir;
});
return exportDirPromise;
}
};
export = mod;
1 change: 1 addition & 0 deletions src/node_requires/resources/IAsset.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ interface IAsset {
readonly type: resourceType;
readonly uid: string;
lastmod: number;
group?: string;
}
2 changes: 1 addition & 1 deletion src/node_requires/resources/emitterTandems/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const getThumbnail = function getThumbnail(): string {
return 'sparkles';
};
const getById = function getById(id: string): ITandem {
const tandem = global.currentProject.tandems.find((t: ITandem) => t.uid === id);
const tandem = (window as Window).currentProject.tandems.find((t: ITandem) => t.uid === id);
if (!tandem) {
throw new Error(`Attempt to get a non-existent tandem with ID ${id}`);
}
Expand Down
9 changes: 9 additions & 0 deletions src/node_requires/resources/projects/IProject.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare interface IProject {
textures: ITexture[];
templates: ITemplate[];
sounds: ISound[];
rooms: IRoom[];
tandems: ITandem[];
fonts: IFont[];
[key: string]: any;
}
6 changes: 3 additions & 3 deletions src/node_requires/resources/sounds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const getById = function getById(id: string): ISound {
return sound;
};

const createNewSound = function (): ISound {
const createNewSound = function (name?: string): ISound {
const generateGUID = require('./../../generateGUID');
var id = generateGUID(),
slice = id.slice(-6);
var newSound = {
name: 'Sound_' + slice,
name: name || ('Sound_' + slice),
uid: id,
isMusic: false,
type: 'sound' as resourceType,
Expand All @@ -36,7 +36,7 @@ const addSoundFile = async function addSoundFile(sound: ISound, file: string): P
sound.lastmod = Number(new Date());
} catch (e) {
console.error(e);
alertify.error(e);
(window as Window).alertify.error(e);
throw e;
}
};
Expand Down
26 changes: 26 additions & 0 deletions src/node_requires/resources/textures/ITexture.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
interface ITexture extends IAsset {
type: 'texture';
uid: string;
name: string;
origname: string;
grid: [number, number];
axis: [number, number];
width: number;
height: number;
imgWidth: number;
imgHeight: number;
offx: number;
offy: number;
marginx: number;
marginy: number;
padding: number;
untill: number;
lastmod: number;
source?: string;
shape: 'rect' | 'strip' | 'circle',
left?: number;
right?: number;
top?: number;
bottom?: number;
tiled?: boolean;
}
Loading

0 comments on commit ddb8301

Please sign in to comment.