1 bug remaining described at lign 228
This commit is contained in:
@ -1 +0,0 @@
|
|||||||
{}
|
|
@ -25,7 +25,7 @@ app.listen(3000, () => {
|
|||||||
*
|
*
|
||||||
* @return the list of files included in this folder/subfolders
|
* @return the list of files included in this folder/subfolders
|
||||||
*/
|
*/
|
||||||
async function filesList(Path: string): Promise<Array<string>> {
|
async function filesList(Path: string): Promise<Array<string>> { // serach returns all the files in a folder and all its subfolders
|
||||||
const files: Array<string> = []
|
const files: Array<string> = []
|
||||||
const subFolders = await fs.readdir(Path)
|
const subFolders = await fs.readdir(Path)
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ async function filesList(Path: string): Promise<Array<string>> {
|
|||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/program', (_req, res) => {
|
app.get('/program', (_req, res) => { // process the images after checking by hash that they were not processed before
|
||||||
|
|
||||||
(async (dirPath: string) => {
|
(async (dirPath: string) => {
|
||||||
const files = await filesList(dirPath)
|
const files = await filesList(dirPath)
|
||||||
@ -55,7 +55,7 @@ app.get('/program', (_req, res) => {
|
|||||||
console.log('handeling...')
|
console.log('handeling...')
|
||||||
}
|
}
|
||||||
|
|
||||||
for await (const file of files) {
|
for await (const file of files) {
|
||||||
const bFile = path.basename(file)
|
const bFile = path.basename(file)
|
||||||
const pName = path.dirname(file)
|
const pName = path.dirname(file)
|
||||||
const hash = crypto.createHash('sha256')
|
const hash = crypto.createHash('sha256')
|
||||||
@ -74,13 +74,13 @@ app.get('/program', (_req, res) => {
|
|||||||
await fs.writeFile('output.json', JSON.stringify(json))
|
await fs.writeFile('output.json', JSON.stringify(json))
|
||||||
try{
|
try{
|
||||||
const image = await Jimp.read(readI)
|
const image = await Jimp.read(readI)
|
||||||
image.sepia()
|
image.sepia() // turn images to sepia
|
||||||
image.rgba(true)
|
image.rgba(true) // activate Alfa channel
|
||||||
image.contain(256, 256)
|
image.contain(256, 256) // put in a 256x256 square
|
||||||
const index = bFile.lastIndexOf('.')
|
const index = bFile.lastIndexOf('.')
|
||||||
const newBaseName = bFile.slice(0, index) + '.png'
|
const newBaseName = bFile.slice(0, index) + '.png'
|
||||||
const newFileName = pName + '/.' + newBaseName
|
const newFileName = pName + '/.' + newBaseName
|
||||||
await image.writeAsync(`${newFileName}`)
|
await image.writeAsync(`${newFileName}`) // processed images are renamed as hidden files and put back next to originals
|
||||||
}catch (err){
|
}catch (err){
|
||||||
console.log('this file is not an image')
|
console.log('this file is not an image')
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ app.get('/program', (_req, res) => {
|
|||||||
})('./assets')
|
})('./assets')
|
||||||
})
|
})
|
||||||
|
|
||||||
async function listToSend() {
|
async function listToSend() { // returns sorted and filtered list to be displayed at url '/'
|
||||||
const listFiles = readdirSync('./assets')
|
const listFiles = readdirSync('./assets')
|
||||||
const listFinal: Array<Array<string>> = []
|
const listFinal: Array<Array<string>> = []
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ async function listToSend() {
|
|||||||
return listToSend
|
return listToSend
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/code', async (_, res) => {
|
app.get('/code', async (_, res) => { // sends previous list to '/code'
|
||||||
const data = await listToSend()
|
const data = await listToSend()
|
||||||
const lenght = data.length
|
const lenght = data.length
|
||||||
if (lenght !== 0){
|
if (lenght !== 0){
|
||||||
@ -115,12 +115,12 @@ app.get('/code', async (_, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
async function base() {
|
async function base() { // returns list to be displayed when url '/' is refreshed
|
||||||
const listFiles = readdirSync('./assets')
|
const listFiles = readdirSync('./assets')
|
||||||
const outerListFinal: Array<Array<string>> = []
|
const outerListFinal: Array<Array<string>> = []
|
||||||
const innerListFinal: Array<string> = []
|
const innerListFinal: Array<string> = []
|
||||||
for(const perso of listFiles){
|
for(const perso of listFiles){
|
||||||
const listPerso = await filesList('./assets/' + perso)
|
const listPerso = await filesList('./assets/' + perso) // takes all files in folder and subfolder and return those starting with .base
|
||||||
for(const image of listPerso){
|
for(const image of listPerso){
|
||||||
const bName = path.basename(image)
|
const bName = path.basename(image)
|
||||||
if(bName.startsWith('.base')){
|
if(bName.startsWith('.base')){
|
||||||
@ -129,7 +129,7 @@ async function base() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
outerListFinal.push(innerListFinal)
|
outerListFinal.push(innerListFinal)
|
||||||
return outerListFinal
|
return outerListFinal // returns list of list because images and anims are choosen through specific coordinates based on their rank in list
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', async (_, res) => {
|
app.get('/', async (_, res) => {
|
||||||
@ -167,7 +167,7 @@ app.get('/', async (_, res) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className='row23'>
|
<div className='row23'>
|
||||||
<img id='5' src={listBase[0][5]} width={620} />
|
<img id='5' src={listBase[0][5]} width={620} />
|
||||||
</div>
|
</div>
|
||||||
{<script dangerouslySetInnerHTML={{__html:`
|
{<script dangerouslySetInnerHTML={{__html:`
|
||||||
let intervalIds = [];
|
let intervalIds = [];
|
||||||
let listToRandom = [0, 1, 2, 3, 4, 5]
|
let listToRandom = [0, 1, 2, 3, 4, 5]
|
||||||
@ -178,7 +178,7 @@ app.get('/', async (_, res) => {
|
|||||||
})
|
})
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
let notSoRandomList = []
|
let notSoRandomList = []
|
||||||
function runIntervals() {
|
function runIntervals() { // counts are used by the program to keep track of itself in the displaying
|
||||||
intervalIds.forEach(clearInterval);
|
intervalIds.forEach(clearInterval);
|
||||||
intervalIds = [];
|
intervalIds = [];
|
||||||
let timeOuter = 3000;
|
let timeOuter = 3000;
|
||||||
@ -193,7 +193,7 @@ app.get('/', async (_, res) => {
|
|||||||
let perso = notSoRandomList[countPerso]
|
let perso = notSoRandomList[countPerso]
|
||||||
|
|
||||||
let length = data[perso].length
|
let length = data[perso].length
|
||||||
if(length*timeInner > timeOuter){
|
if(length*timeInner > timeOuter){ // sets an adaptive delay >= (timeouter) to let all anim display before changing perso
|
||||||
timeOuter = length*timeInner + timeInner
|
timeOuter = length*timeInner + timeInner
|
||||||
}
|
}
|
||||||
countPerso = countPerso + 1;
|
countPerso = countPerso + 1;
|
||||||
@ -201,8 +201,9 @@ app.get('/', async (_, res) => {
|
|||||||
if (imgElement){
|
if (imgElement){
|
||||||
intervalIds.push(setInterval(function() {
|
intervalIds.push(setInterval(function() {
|
||||||
let anim = countAnim ++;
|
let anim = countAnim ++;
|
||||||
|
console.log(anim)
|
||||||
let check = (data[perso][anim]);
|
let check = (data[perso][anim]);
|
||||||
if(check === undefined){
|
if(check === undefined){ // checks if the program attempts to diplay an image that doesn't exist
|
||||||
anim = 0
|
anim = 0
|
||||||
}
|
}
|
||||||
let imgElement = document.getElementById(perso);
|
let imgElement = document.getElementById(perso);
|
||||||
@ -216,7 +217,7 @@ app.get('/', async (_, res) => {
|
|||||||
}, timeOuter);
|
}, timeOuter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function notSoRandomPerso(){
|
function notSoRandomPerso(){ // creates rabdomized list that will choose which perso to anim
|
||||||
for (let i = listToRandom.length - 1; i > 0; i--) {
|
for (let i = listToRandom.length - 1; i > 0; i--) {
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
[listToRandom[i], listToRandom[j]] = [listToRandom[j], listToRandom[i]];
|
[listToRandom[i], listToRandom[j]] = [listToRandom[j], listToRandom[i]];
|
||||||
@ -224,15 +225,11 @@ app.get('/', async (_, res) => {
|
|||||||
console.log(listToRandom)
|
console.log(listToRandom)
|
||||||
return listToRandom
|
return listToRandom
|
||||||
}
|
}
|
||||||
function stopIntervals() {
|
runIntervals(); // program is supposed to wait until it reaches base before changing perso but it apears that in rare cases it doesn't
|
||||||
intervalIds.forEach(clearInterval);
|
|
||||||
intervalIds = [];
|
|
||||||
}
|
|
||||||
runIntervals();
|
|
||||||
});
|
});
|
||||||
`}}></script> }
|
`}}></script> }
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
19
test.js
19
test.js
@ -1,7 +1,6 @@
|
|||||||
let intervalIds = [];
|
let intervalIds = [];
|
||||||
let listToRandom = [0, 1, 2, 3, 4, 5]
|
let listToRandom = [0, 1, 2, 3, 4, 5]
|
||||||
let countPerso = 0;
|
let countPerso = 0;
|
||||||
console.log('ouaip')
|
|
||||||
fetch('http://localhost:3000/code')
|
fetch('http://localhost:3000/code')
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
@ -14,23 +13,19 @@ fetch('http://localhost:3000/code')
|
|||||||
let timeOuter = 3000;
|
let timeOuter = 3000;
|
||||||
let timeInner = 500;
|
let timeInner = 500;
|
||||||
let countAnim = 1;
|
let countAnim = 1;
|
||||||
if(countPerso === 5){
|
if(countPerso === 6){
|
||||||
countPerso = 0
|
countPerso = 0
|
||||||
|
|
||||||
}
|
}
|
||||||
if(countPerso === 0){
|
if(countPerso === 0){
|
||||||
notSoRandomList = notSoRandomPerso()
|
notSoRandomList = notSoRandomPerso()
|
||||||
|
|
||||||
}
|
}
|
||||||
let perso = notSoRandomList[countPerso]
|
let perso = notSoRandomList[countPerso]
|
||||||
countPerso = countPerso + 1;
|
|
||||||
// let minPerso = 0;
|
|
||||||
// let maxPerso = 5;
|
|
||||||
// let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
|
|
||||||
let length = data[perso].length
|
let length = data[perso].length
|
||||||
if(length*timeInner > timeOuter){
|
if(length*timeInner > timeOuter){
|
||||||
timeOuter = length*timeInner + timeInner
|
timeOuter = length*timeInner + timeInner
|
||||||
}
|
}
|
||||||
|
countPerso = countPerso + 1;
|
||||||
let imgElement = document.getElementById(perso);
|
let imgElement = document.getElementById(perso);
|
||||||
if (imgElement){
|
if (imgElement){
|
||||||
intervalIds.push(setInterval(function() {
|
intervalIds.push(setInterval(function() {
|
||||||
@ -58,9 +53,5 @@ fetch('http://localhost:3000/code')
|
|||||||
console.log(listToRandom)
|
console.log(listToRandom)
|
||||||
return listToRandom
|
return listToRandom
|
||||||
}
|
}
|
||||||
function stopIntervals() {
|
|
||||||
intervalIds.forEach(clearInterval);
|
|
||||||
intervalIds = [];
|
|
||||||
}
|
|
||||||
runIntervals();
|
runIntervals();
|
||||||
});
|
});
|
Reference in New Issue
Block a user