1 bug remaining described at lign 228
This commit is contained in:
parent
b43b661606
commit
a0c7069dce
@ -1 +0,0 @@
|
||||
{}
|
@ -25,7 +25,7 @@ app.listen(3000, () => {
|
||||
*
|
||||
* @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 subFolders = await fs.readdir(Path)
|
||||
|
||||
@ -41,7 +41,7 @@ async function filesList(Path: string): Promise<Array<string>> {
|
||||
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) => {
|
||||
const files = await filesList(dirPath)
|
||||
@ -74,13 +74,13 @@ app.get('/program', (_req, res) => {
|
||||
await fs.writeFile('output.json', JSON.stringify(json))
|
||||
try{
|
||||
const image = await Jimp.read(readI)
|
||||
image.sepia()
|
||||
image.rgba(true)
|
||||
image.contain(256, 256)
|
||||
image.sepia() // turn images to sepia
|
||||
image.rgba(true) // activate Alfa channel
|
||||
image.contain(256, 256) // put in a 256x256 square
|
||||
const index = bFile.lastIndexOf('.')
|
||||
const newBaseName = bFile.slice(0, index) + '.png'
|
||||
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){
|
||||
console.log('this file is not an image')
|
||||
}
|
||||
@ -91,7 +91,7 @@ app.get('/program', (_req, res) => {
|
||||
})('./assets')
|
||||
})
|
||||
|
||||
async function listToSend() {
|
||||
async function listToSend() { // returns sorted and filtered list to be displayed at url '/'
|
||||
const listFiles = readdirSync('./assets')
|
||||
const listFinal: Array<Array<string>> = []
|
||||
|
||||
@ -106,7 +106,7 @@ async function listToSend() {
|
||||
return listToSend
|
||||
}
|
||||
|
||||
app.get('/code', async (_, res) => {
|
||||
app.get('/code', async (_, res) => { // sends previous list to '/code'
|
||||
const data = await listToSend()
|
||||
const lenght = data.length
|
||||
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 outerListFinal: Array<Array<string>> = []
|
||||
const innerListFinal: Array<string> = []
|
||||
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){
|
||||
const bName = path.basename(image)
|
||||
if(bName.startsWith('.base')){
|
||||
@ -129,7 +129,7 @@ async function base() {
|
||||
}
|
||||
}
|
||||
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) => {
|
||||
@ -178,7 +178,7 @@ app.get('/', async (_, res) => {
|
||||
})
|
||||
.then(function(data) {
|
||||
let notSoRandomList = []
|
||||
function runIntervals() {
|
||||
function runIntervals() { // counts are used by the program to keep track of itself in the displaying
|
||||
intervalIds.forEach(clearInterval);
|
||||
intervalIds = [];
|
||||
let timeOuter = 3000;
|
||||
@ -193,7 +193,7 @@ app.get('/', async (_, res) => {
|
||||
let perso = notSoRandomList[countPerso]
|
||||
|
||||
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
|
||||
}
|
||||
countPerso = countPerso + 1;
|
||||
@ -201,8 +201,9 @@ app.get('/', async (_, res) => {
|
||||
if (imgElement){
|
||||
intervalIds.push(setInterval(function() {
|
||||
let anim = countAnim ++;
|
||||
console.log(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
|
||||
}
|
||||
let imgElement = document.getElementById(perso);
|
||||
@ -216,7 +217,7 @@ app.get('/', async (_, res) => {
|
||||
}, timeOuter);
|
||||
}
|
||||
}
|
||||
function notSoRandomPerso(){
|
||||
function notSoRandomPerso(){ // creates rabdomized list that will choose which perso to anim
|
||||
for (let i = listToRandom.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[listToRandom[i], listToRandom[j]] = [listToRandom[j], listToRandom[i]];
|
||||
@ -224,11 +225,7 @@ app.get('/', async (_, res) => {
|
||||
console.log(listToRandom)
|
||||
return listToRandom
|
||||
}
|
||||
function stopIntervals() {
|
||||
intervalIds.forEach(clearInterval);
|
||||
intervalIds = [];
|
||||
}
|
||||
runIntervals();
|
||||
runIntervals(); // program is supposed to wait until it reaches base before changing perso but it apears that in rare cases it doesn't
|
||||
});
|
||||
`}}></script> }
|
||||
</div>
|
||||
|
15
test.js
15
test.js
@ -1,7 +1,6 @@
|
||||
let intervalIds = [];
|
||||
let listToRandom = [0, 1, 2, 3, 4, 5]
|
||||
let countPerso = 0;
|
||||
console.log('ouaip')
|
||||
fetch('http://localhost:3000/code')
|
||||
.then(function(response) {
|
||||
return response.json();
|
||||
@ -14,23 +13,19 @@ fetch('http://localhost:3000/code')
|
||||
let timeOuter = 3000;
|
||||
let timeInner = 500;
|
||||
let countAnim = 1;
|
||||
if(countPerso === 5){
|
||||
if(countPerso === 6){
|
||||
countPerso = 0
|
||||
|
||||
}
|
||||
if(countPerso === 0){
|
||||
notSoRandomList = notSoRandomPerso()
|
||||
|
||||
}
|
||||
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
|
||||
if(length*timeInner > timeOuter){
|
||||
timeOuter = length*timeInner + timeInner
|
||||
}
|
||||
countPerso = countPerso + 1;
|
||||
let imgElement = document.getElementById(perso);
|
||||
if (imgElement){
|
||||
intervalIds.push(setInterval(function() {
|
||||
@ -58,9 +53,5 @@ fetch('http://localhost:3000/code')
|
||||
console.log(listToRandom)
|
||||
return listToRandom
|
||||
}
|
||||
function stopIntervals() {
|
||||
intervalIds.forEach(clearInterval);
|
||||
intervalIds = [];
|
||||
}
|
||||
runIntervals();
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user