From 8e4c33b6348c8507d6a9997c35d3b239f46a825c Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 28 Jul 2018 08:43:31 -0400 Subject: [PATCH 01/12] Changed tabs to be consisitent with conventions --- Source/Bar.hx | 102 +++++++++---------- Source/Calendar.hx | 151 ++++++++++++++-------------- Source/Day.hx | 14 +-- Source/Main.hx | 206 +++++++++++++++++++------------------- Source/Schedule.hx | 244 ++++++++++++++++++++++----------------------- 5 files changed, 357 insertions(+), 360 deletions(-) diff --git a/Source/Bar.hx b/Source/Bar.hx index cf4a341..c055878 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -23,71 +23,71 @@ class Bar extends Sprite // interestRate is the proportion of the total that increases per day public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Array, gameDate:Date, color:Int=0x000000) { - super(); - - movable = new Sprite(); - movable.x = movable.y = 0; - column = new Shape(); - column.graphics.lineStyle(0); - column.graphics.beginFill(color, 1); - column.graphics.drawRect(Math.round(barWidth/2),0,barWidth,1000); - column.graphics.endFill(); - movable.addChild(column); - - nameField = new TextField(); - nameField.text = nameStr; - nameField.x = Math.round(barWidth/2); - nameField.y = -nameHeight; - movable.addChild(nameField); - - addChild(movable); - movable.x = 0; - movable.y = -startHeight; - movable.addEventListener(MouseEvent.MOUSE_DOWN, - function (e:MouseEvent) - {working=true;}); - movable.addEventListener(MouseEvent.MOUSE_UP, - function (e:MouseEvent) - {working=false;}); - movable.addEventListener(MouseEvent.MOUSE_OUT, - function (e:MouseEvent) - {working=false;}); - - this.interestRate = interestRate; - this.workRate = workRate; - this.lectures = lectures; - lectureNum = 0; - initGameDate = gameDate; - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + super(); + + movable = new Sprite(); + movable.x = movable.y = 0; + column = new Shape(); + column.graphics.lineStyle(0); + column.graphics.beginFill(color, 1); + column.graphics.drawRect(Math.round(barWidth/2),0,barWidth,1000); + column.graphics.endFill(); + movable.addChild(column); + + nameField = new TextField(); + nameField.text = nameStr; + nameField.x = Math.round(barWidth/2); + nameField.y = -nameHeight; + movable.addChild(nameField); + + addChild(movable); + movable.x = 0; + movable.y = -startHeight; + movable.addEventListener(MouseEvent.MOUSE_DOWN, + function (e:MouseEvent) + {working=true;}); + movable.addEventListener(MouseEvent.MOUSE_UP, + function (e:MouseEvent) + {working=false;}); + movable.addEventListener(MouseEvent.MOUSE_OUT, + function (e:MouseEvent) + {working=false;}); + + this.interestRate = interestRate; + this.workRate = workRate; + this.lectures = lectures; + lectureNum = 0; + initGameDate = gameDate; + lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); } public function update(gameDate:Date, delta:Float) { - accrueInterest(delta); - if (working){ - work(delta); - } - getHomework(gameDate); + accrueInterest(delta); + if (working){ + work(delta); + } + getHomework(gameDate); } private function accrueInterest(delta:Float) { - //trace(interestRate+" "+delta/(3600*24)+" "+movable.y); - movable.y += interestRate*(delta/(3600*24))*movable.y; // make movable.y more negative + //trace(interestRate+" "+delta/(3600*24)+" "+movable.y); + movable.y += interestRate*(delta/(3600*24))*movable.y; // make movable.y more negative } private function work(delta:Float) { - //trace(workRate * delta/(3600*24)); + //trace(workRate * delta/(3600*24)); movable.y += workRate * delta/(3600*24); } private function getHomework(gameDate:Date){ - if (lectureNum < lectures.length){ - if (gameDate.getTime() > lectureEndDate.getTime()){ - movable.y -= lectures[lectureNum].size; - lectureNum++; if (lectureNum < lectures.length){ - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + if (gameDate.getTime() > lectureEndDate.getTime()){ + movable.y -= lectures[lectureNum].size; + lectureNum++; + if (lectureNum < lectures.length){ + lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + } + } } - } - } } } diff --git a/Source/Calendar.hx b/Source/Calendar.hx index f4b11f0..53d1728 100644 --- a/Source/Calendar.hx +++ b/Source/Calendar.hx @@ -19,95 +19,94 @@ class Calendar extends Sprite { private var endDate:Date; //first date not in calendar public function new(width, height, date:Date){ - super(); - today = Day.fromDate(date); - //round down to nearest Sunday to get endDate because nothing in calendar yet - endDate = DateTools.delta(date, -DateTools.days(date.getDay())); - - xOffset = 0; - yOffset = weekdayHeight; - cellWidth = Math.round(width/7); - cellHeight = Math.round((height-weekdayHeight)/2); - rows = 2; - - makeGrid(); - makeWeekdays(); - cells.get(today).backgroundColor = 0xEE5D15; + super(); + today = Day.fromDate(date); + //round down to nearest Sunday to get endDate because nothing in calendar yet + endDate = DateTools.delta(date, -DateTools.days(date.getDay())); + + xOffset = 0; + yOffset = weekdayHeight; + cellWidth = Math.round(width/7); + cellHeight = Math.round((height-weekdayHeight)/2); + rows = 2; + + makeGrid(); + makeWeekdays(); + cells.get(today).backgroundColor = 0xEE5D15; } private function makeRow (rowNum){ - for (j in 0...7){ - - var cell:TextField = new TextField(); - addChild(cell); - - cell.x = xOffset + j*cellWidth; - cell.y = yOffset + rowNum*cellHeight; - cell.text = Std.string(endDate.getDate()); - trace(endDate); - if (endDate.getDate()==1){ - var ms:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - var m = ms[endDate.getMonth()]; - trace(ms); - trace(m); - cell.text += " "+m; - } - - cell.background = true; - cell.backgroundColor = 0xFFFFFF; - cell.border = true; - cell.borderColor = 0x000000; - cell.width = cellWidth; - cell.height = cellHeight; - - cells.set(Day.fromDate(endDate),cell); - - endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); - } + for (j in 0...7){ + + var cell:TextField = new TextField(); + addChild(cell); + + cell.x = xOffset + j*cellWidth; + cell.y = yOffset + rowNum*cellHeight; + cell.text = Std.string(endDate.getDate()); + trace(endDate); + if (endDate.getDate()==1){ + var ms:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + var m = ms[endDate.getMonth()]; + trace(ms); + trace(m); + cell.text += " "+m; + } + + cell.background = true; + cell.backgroundColor = 0xFFFFFF; + cell.border = true; + cell.borderColor = 0x000000; + cell.width = cellWidth; + cell.height = cellHeight; + + cells.set(Day.fromDate(endDate),cell); + + endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); + } } - private function makeGrid() - { - for (i in 0...rows){ - makeRow(i); - } + private function makeGrid(){ + for (i in 0...rows){ + makeRow(i); + } } private function advanceGrid(){ - for (cell in cells){ - if (cell.y <= yOffset){ - removeChild(cell); - } else { - cell.y -= cellHeight; - } - } - makeRow(rows-1); + for (cell in cells){ + if (cell.y <= yOffset){ + removeChild(cell); + } else { + cell.y -= cellHeight; + } + } + makeRow(rows-1); } private function makeWeekdays() { - var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - for (i in 0...7) { - var weekday:TextField = new TextField(); - addChild(weekday); - - weekday.text = names[i]; - weekday.x = xOffset + i*cellWidth; - weekday.y = yOffset - 15; - } + var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + for (i in 0...7) { + var weekday:TextField = new TextField(); + addChild(weekday); + + weekday.text = names[i]; + weekday.x = xOffset + i*cellWidth; + weekday.y = yOffset - 15; + } } public function update(gameDate:Date) { - //trace("hi"); - var day = Day.fromDate(gameDate); - //trace(today.month+" "+today.day); - //trace(day.month+" "+day.day); - if (!today.equals(day)){ - if (gameDate.getDay()==0){ - advanceGrid(); - } - cells.get(day).backgroundColor = 0xEE5D15; - cells.get(today).backgroundColor = 0xFFFFFF; - today=day; - } + //trace("hi"); + var day = Day.fromDate(gameDate); + //trace(today.month+" "+today.day); + //trace(day.month+" "+day.day); + if (!today.equals(day)){ + if (gameDate.getDay()==0){ + advanceGrid(); + } + cells.get(day).backgroundColor = 0xEE5D15; + cells.get(today).backgroundColor = 0xFFFFFF; + today=day; + } } } diff --git a/Source/Day.hx b/Source/Day.hx index 24edaba..fef2e39 100644 --- a/Source/Day.hx +++ b/Source/Day.hx @@ -5,20 +5,20 @@ class Day { public var day:Int; public function new (month:Int, day:Int){ - this.month = month; - this.day = day; + this.month = month; + this.day = day; } public static function fromDate(date:Date){ - return new Day(date.getMonth(), date.getDate()); + return new Day(date.getMonth(), date.getDate()); } public function equals(other:Day){ - return this.hashCode() == other.hashCode(); + return this.hashCode() == other.hashCode(); } - public function hashCode():Int - { - return month*8+day; + + public function hashCode():Int{ + return month*8+day; } } diff --git a/Source/Main.hx b/Source/Main.hx index 86b0f8a..92a45c4 100644 --- a/Source/Main.hx +++ b/Source/Main.hx @@ -37,113 +37,111 @@ class Main extends Sprite { public var colors:Array; public function new () { - - super (); - - var scheduleJson = Assets.getText("assets/schedule.json"); - scheduleObject = Json.parse(scheduleJson); - - colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; - - /* - var bitmapData = Assets.getBitmapData ("assets/openfl.png"); - var bitmap = new Bitmap (bitmapData); - addChild (bitmap); - - bitmap.x = (stage.stageWidth - bitmap.width) / 2; - bitmap.y = (stage.stageHeight - bitmap.height) / 2; - */ - gameDate = new Date(2018, 9, 28, 0, 0, 0); - var gameDay = new Date(2018, 9, 28, 12, 0, 0); - //This is for the purpose of daylight savings. Some days are 23 or 25 hours, so putting the time as noon will be stable WRT these changes. - - //trace(gameDate.getDay()); //Should be 0 - initialTimestamp = Timer.stamp(); - initialGameTimestamp = gameDate.getTime()/1000; - //trace(gameDate.getTime()); - trace(initialTimestamp); - trace(Date.now().getTime()/1000); - trace(Timer.stamp()); - mscheduleSpr = new Calendar(x2,y1, gameDay); - mscheduleSpr.x=2*xM+x1; - mscheduleSpr.y=yM; - var avatarSpr = new Sprite(); - avatarSpr.x=xM; - avatarSpr.y=2*yM+y1; - var classesSpr = new Sprite(); - classesSpr.x=2*xM+x1; - classesSpr.y=2*yM+y1; - wscheduleSpr = new Schedule(x3,y2, gameDay, scheduleObject, colors); - wscheduleSpr.x=3*xM+x1+x2; - wscheduleSpr.y=2*yM+y1; - - // var rectangle1 = new Shape(); - var rectangle2 = new Shape(); - var rectangle3 = new Shape(); - //var rectangle4 = new Shape(); - //rectangle1.graphics.lineStyle(2); - rectangle2.graphics.lineStyle(2); - rectangle3.graphics.lineStyle(2); - //rectangle4.graphics.lineStyle(2); - - //rectangle1.graphics.drawRect(0,0, x2, y1); - rectangle2.graphics.drawRect(0,0, x1, y2); - rectangle3.graphics.drawRect(0,0, x2, y2); - // rectangle4.graphics.drawRect(0,0, x3, y2); - - //mscheduleSpr.addChild(rectangle1); - avatarSpr.addChild(rectangle2); - classesSpr.addChild(rectangle3); - //wscheduleSpr.addChild(rectangle4); - - this.addChild(mscheduleSpr); - this.addChild(avatarSpr); - this.addChild(classesSpr); - this.addChild(wscheduleSpr); - - bar1 = new Bar(0.01, 100, 50, "Drawing", scheduleObject[0], gameDate, colors[0]); - bar1.x = Math.round(x2/7); - bar1.y = y2; - bar2 = new Bar(0.04, 100, 50, "Evolution and Ecology", scheduleObject[1], gameDate, colors[1]); - bar2.x = Math.round(2*x2/7); - bar2.y = y2; - bar3 = new Bar(0.04, 100, 50, "EE Lab", scheduleObject[2], gameDate, colors[2]); - bar3.x = Math.round(3*x2/7); - bar3.y = y2; - bar4 = new Bar(0.04, 100, 50, "Chem", scheduleObject[3], gameDate, colors[3]); - bar4.x = Math.round(4*x2/7); - bar4.y = y2; - bar5 = new Bar(0.04, 100, 50, "Chem Lab", scheduleObject[4], gameDate, colors[4]); - bar5.x = Math.round(5*x2/7); - bar5.y = y2; - bar6 = new Bar(0.01, 100, 50, "How Things Work", scheduleObject[5], gameDate, colors[5]); - bar6.x = Math.round(6*x2/7); - bar6.y = y2; - classesSpr.addChild(bar1); - classesSpr.addChild(bar2); - classesSpr.addChild(bar3); - classesSpr.addChild(bar4); - classesSpr.addChild(bar5); - classesSpr.addChild(bar6); - - stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); - + super (); + + var scheduleJson = Assets.getText("assets/schedule.json"); + scheduleObject = Json.parse(scheduleJson); + + colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; + + /* + var bitmapData = Assets.getBitmapData ("assets/openfl.png"); + var bitmap = new Bitmap (bitmapData); + addChild (bitmap); + + bitmap.x = (stage.stageWidth - bitmap.width) / 2; + bitmap.y = (stage.stageHeight - bitmap.height) / 2; + */ + gameDate = new Date(2018, 9, 28, 0, 0, 0); + var gameDay = new Date(2018, 9, 28, 12, 0, 0); + //This is for the purpose of daylight savings. Some days are 23 or 25 hours, so putting the time as noon will be stable WRT these changes. + + //trace(gameDate.getDay()); //Should be 0 + initialTimestamp = Timer.stamp(); + initialGameTimestamp = gameDate.getTime()/1000; + //trace(gameDate.getTime()); + trace(initialTimestamp); + trace(Date.now().getTime()/1000); + trace(Timer.stamp()); + mscheduleSpr = new Calendar(x2,y1, gameDay); + mscheduleSpr.x=2*xM+x1; + mscheduleSpr.y=yM; + var avatarSpr = new Sprite(); + avatarSpr.x=xM; + avatarSpr.y=2*yM+y1; + var classesSpr = new Sprite(); + classesSpr.x=2*xM+x1; + classesSpr.y=2*yM+y1; + wscheduleSpr = new Schedule(x3,y2, gameDay, scheduleObject, colors); + wscheduleSpr.x=3*xM+x1+x2; + wscheduleSpr.y=2*yM+y1; + + // var rectangle1 = new Shape(); + var rectangle2 = new Shape(); + var rectangle3 = new Shape(); + //var rectangle4 = new Shape(); + //rectangle1.graphics.lineStyle(2); + rectangle2.graphics.lineStyle(2); + rectangle3.graphics.lineStyle(2); + //rectangle4.graphics.lineStyle(2); + + //rectangle1.graphics.drawRect(0,0, x2, y1); + rectangle2.graphics.drawRect(0,0, x1, y2); + rectangle3.graphics.drawRect(0,0, x2, y2); + // rectangle4.graphics.drawRect(0,0, x3, y2); + + //mscheduleSpr.addChild(rectangle1); + avatarSpr.addChild(rectangle2); + classesSpr.addChild(rectangle3); + //wscheduleSpr.addChild(rectangle4); + + this.addChild(mscheduleSpr); + this.addChild(avatarSpr); + this.addChild(classesSpr); + this.addChild(wscheduleSpr); + + bar1 = new Bar(0.01, 100, 50, "Drawing", scheduleObject[0], gameDate, colors[0]); + bar1.x = Math.round(x2/7); + bar1.y = y2; + bar2 = new Bar(0.04, 100, 50, "Evolution and Ecology", scheduleObject[1], gameDate, colors[1]); + bar2.x = Math.round(2*x2/7); + bar2.y = y2; + bar3 = new Bar(0.04, 100, 50, "EE Lab", scheduleObject[2], gameDate, colors[2]); + bar3.x = Math.round(3*x2/7); + bar3.y = y2; + bar4 = new Bar(0.04, 100, 50, "Chem", scheduleObject[3], gameDate, colors[3]); + bar4.x = Math.round(4*x2/7); + bar4.y = y2; + bar5 = new Bar(0.04, 100, 50, "Chem Lab", scheduleObject[4], gameDate, colors[4]); + bar5.x = Math.round(5*x2/7); + bar5.y = y2; + bar6 = new Bar(0.01, 100, 50, "How Things Work", scheduleObject[5], gameDate, colors[5]); + bar6.x = Math.round(6*x2/7); + bar6.y = y2; + classesSpr.addChild(bar1); + classesSpr.addChild(bar2); + classesSpr.addChild(bar3); + classesSpr.addChild(bar4); + classesSpr.addChild(bar5); + classesSpr.addChild(bar6); + + stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame (e:Event){ - //initialTimeStamp is in seconds, but Date.fromTime takes milliseconds - var newGameDate = Date.fromTime(1000*(initialGameTimestamp+timeScale*(Timer.stamp()-initialTimestamp))); - // trace(timeScale*(wut-initialTimeStamp)); - var delta = (newGameDate.getTime() - gameDate.getTime())/1000; - gameDate = newGameDate; - mscheduleSpr.update(gameDate); - wscheduleSpr.update(gameDate); - bar1.update(gameDate, delta); - bar2.update(gameDate, delta); - bar3.update(gameDate, delta); - bar4.update(gameDate, delta); - bar5.update(gameDate, delta); - bar6.update(gameDate, delta); + //initialTimeStamp is in seconds, but Date.fromTime takes milliseconds + var newGameDate = Date.fromTime(1000*(initialGameTimestamp+timeScale*(Timer.stamp()-initialTimestamp))); + // trace(timeScale*(wut-initialTimeStamp)); + var delta = (newGameDate.getTime() - gameDate.getTime())/1000; + gameDate = newGameDate; + mscheduleSpr.update(gameDate); + wscheduleSpr.update(gameDate); + bar1.update(gameDate, delta); + bar2.update(gameDate, delta); + bar3.update(gameDate, delta); + bar4.update(gameDate, delta); + bar5.update(gameDate, delta); + bar6.update(gameDate, delta); } } diff --git a/Source/Schedule.hx b/Source/Schedule.hx index 258458c..b34e942 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -25,144 +25,144 @@ class Schedule extends Sprite { private var colors:Array; public function new (width, height, date:Date, scheduleObject:Array>, colors:Array=null){ - super(); - - this.scheduleObject = scheduleObject; - this.colors = colors; - - if (colors == null || colors.lengthweek){ - break; + week++; + + for (j in 0...7){ + var col:TextField = new TextField(); + addChild(col); + + col.x = xOffset + j*colWidth; + col.y = yOffset; + col.text = Std.string(endDate.getDate()); + + col.background = true; + col.backgroundColor = 0xFFFFFF; + col.border = true; + col.borderColor = 0x000000; + col.width = colWidth; + col.height = colHeight; + + cols.set(Day.fromDate(endDate),col); + endDate = DateTools.delta(endDate, DateTools.days(1)); } - //trace("there"); - var startFrac = (startNums[2]+startNums[3]/60)/24; - var yPos = yOffset + colHeight*startFrac; - var xPos = xOffset + startNums[1]*colWidth; - var endNums = Util.splitAndParseInt(times[1], "/"); - var endFrac = (endNums[2]+endNums[3]/60)/24; - // We don't look at endNums[0] or endNums[1] - var h = colHeight*(endFrac-startFrac); - var lectureCol = new TextField(); - addChild(lectureCol); - - lectureCol.x = xPos; - lectureCol.y = yPos; - lectureCol.text = lecture.title; - - lectureCol.background = true; - lectureCol.backgroundColor = colors[colorNum]; - lectureCol.border = true; - lectureCol.borderColor = 0x000000; - lectureCol.width = colWidth; - lectureCol.height = h; - lectureCols.push(lectureCol); - } - colorNum++; - } - this.addChild(cursor); + var colorNum = 0; + for (lectures in scheduleObject){ + for (lecture in lectures){ + var times = lecture.times.split(" "); + var startNums = Util.splitAndParseInt(times[0], "/"); + //trace("hey"); + if (startNums[0]week){ + break; + } + //trace("there"); + var startFrac = (startNums[2]+startNums[3]/60)/24; + var yPos = yOffset + colHeight*startFrac; + var xPos = xOffset + startNums[1]*colWidth; + var endNums = Util.splitAndParseInt(times[1], "/"); + var endFrac = (endNums[2]+endNums[3]/60)/24; + // We don't look at endNums[0] or endNums[1] + var h = colHeight*(endFrac-startFrac); + var lectureCol = new TextField(); + addChild(lectureCol); + + lectureCol.x = xPos; + lectureCol.y = yPos; + lectureCol.text = lecture.title; + + lectureCol.background = true; + lectureCol.backgroundColor = colors[colorNum]; + lectureCol.border = true; + lectureCol.borderColor = 0x000000; + lectureCol.width = colWidth; + lectureCol.height = h; + + lectureCols.push(lectureCol); + } + colorNum++; + } + this.addChild(cursor); } private function makeWeekdays() { - var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - for (i in 0...7) { - var weekday:TextField = new TextField(); - addChild(weekday); - - weekday.text = names[i]; - weekday.x = xOffset + i*colWidth; - weekday.y = yOffset - 15; - } + var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + for (i in 0...7) { + var weekday:TextField = new TextField(); + addChild(weekday); + + weekday.text = names[i]; + weekday.x = xOffset + i*colWidth; + weekday.y = yOffset - 15; + } } private function advanceCols(){ - for (col in cols){ - removeChild(col); - } - for (lectureCol in lectureCols){ - removeChild(lectureCol); - } - makeCols(); + for (col in cols){ + removeChild(col); + } + for (lectureCol in lectureCols){ + removeChild(lectureCol); + } + makeCols(); } public function update(gameDate:Date) { -// trace("hi"); - var day = Day.fromDate(gameDate); -// trace(today.month+" "+today.day); -// trace(day.month+" "+day.day); - if (!today.equals(day)){ - if (gameDate.getDay()==0){ - advanceCols(); - } - cols.get(day).backgroundColor = 0xEE5D15; - cols.get(today).backgroundColor = 0xFFFFFF; - today=day; - } - cursor.x = xOffset + colWidth*gameDate.getDay(); - cursor.y = yOffset + colHeight*modDay(gameDate); + // trace("hi"); + var day = Day.fromDate(gameDate); + // trace(today.month+" "+today.day); + // trace(day.month+" "+day.day); + if (!today.equals(day)){ + if (gameDate.getDay()==0){ + advanceCols(); + } + cols.get(day).backgroundColor = 0xEE5D15; + cols.get(today).backgroundColor = 0xFFFFFF; + today=day; + } + cursor.x = xOffset + colWidth*gameDate.getDay(); + cursor.y = yOffset + colHeight*modDay(gameDate); } } From 8c58b59a3e6313a2bbefbb0356006fb1a4914ef5 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 28 Jul 2018 08:43:31 -0400 Subject: [PATCH 02/12] Changed tabs to be consisitent with conventions --- Source/Bar.hx | 102 +++++++++---------- Source/Calendar.hx | 151 ++++++++++++++-------------- Source/Day.hx | 14 +-- Source/Main.hx | 206 +++++++++++++++++++------------------- Source/Schedule.hx | 244 ++++++++++++++++++++++----------------------- Source/Util.hx | 22 ++-- 6 files changed, 368 insertions(+), 371 deletions(-) diff --git a/Source/Bar.hx b/Source/Bar.hx index cf4a341..c055878 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -23,71 +23,71 @@ class Bar extends Sprite // interestRate is the proportion of the total that increases per day public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Array, gameDate:Date, color:Int=0x000000) { - super(); - - movable = new Sprite(); - movable.x = movable.y = 0; - column = new Shape(); - column.graphics.lineStyle(0); - column.graphics.beginFill(color, 1); - column.graphics.drawRect(Math.round(barWidth/2),0,barWidth,1000); - column.graphics.endFill(); - movable.addChild(column); - - nameField = new TextField(); - nameField.text = nameStr; - nameField.x = Math.round(barWidth/2); - nameField.y = -nameHeight; - movable.addChild(nameField); - - addChild(movable); - movable.x = 0; - movable.y = -startHeight; - movable.addEventListener(MouseEvent.MOUSE_DOWN, - function (e:MouseEvent) - {working=true;}); - movable.addEventListener(MouseEvent.MOUSE_UP, - function (e:MouseEvent) - {working=false;}); - movable.addEventListener(MouseEvent.MOUSE_OUT, - function (e:MouseEvent) - {working=false;}); - - this.interestRate = interestRate; - this.workRate = workRate; - this.lectures = lectures; - lectureNum = 0; - initGameDate = gameDate; - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + super(); + + movable = new Sprite(); + movable.x = movable.y = 0; + column = new Shape(); + column.graphics.lineStyle(0); + column.graphics.beginFill(color, 1); + column.graphics.drawRect(Math.round(barWidth/2),0,barWidth,1000); + column.graphics.endFill(); + movable.addChild(column); + + nameField = new TextField(); + nameField.text = nameStr; + nameField.x = Math.round(barWidth/2); + nameField.y = -nameHeight; + movable.addChild(nameField); + + addChild(movable); + movable.x = 0; + movable.y = -startHeight; + movable.addEventListener(MouseEvent.MOUSE_DOWN, + function (e:MouseEvent) + {working=true;}); + movable.addEventListener(MouseEvent.MOUSE_UP, + function (e:MouseEvent) + {working=false;}); + movable.addEventListener(MouseEvent.MOUSE_OUT, + function (e:MouseEvent) + {working=false;}); + + this.interestRate = interestRate; + this.workRate = workRate; + this.lectures = lectures; + lectureNum = 0; + initGameDate = gameDate; + lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); } public function update(gameDate:Date, delta:Float) { - accrueInterest(delta); - if (working){ - work(delta); - } - getHomework(gameDate); + accrueInterest(delta); + if (working){ + work(delta); + } + getHomework(gameDate); } private function accrueInterest(delta:Float) { - //trace(interestRate+" "+delta/(3600*24)+" "+movable.y); - movable.y += interestRate*(delta/(3600*24))*movable.y; // make movable.y more negative + //trace(interestRate+" "+delta/(3600*24)+" "+movable.y); + movable.y += interestRate*(delta/(3600*24))*movable.y; // make movable.y more negative } private function work(delta:Float) { - //trace(workRate * delta/(3600*24)); + //trace(workRate * delta/(3600*24)); movable.y += workRate * delta/(3600*24); } private function getHomework(gameDate:Date){ - if (lectureNum < lectures.length){ - if (gameDate.getTime() > lectureEndDate.getTime()){ - movable.y -= lectures[lectureNum].size; - lectureNum++; if (lectureNum < lectures.length){ - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + if (gameDate.getTime() > lectureEndDate.getTime()){ + movable.y -= lectures[lectureNum].size; + lectureNum++; + if (lectureNum < lectures.length){ + lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + } + } } - } - } } } diff --git a/Source/Calendar.hx b/Source/Calendar.hx index f4b11f0..53d1728 100644 --- a/Source/Calendar.hx +++ b/Source/Calendar.hx @@ -19,95 +19,94 @@ class Calendar extends Sprite { private var endDate:Date; //first date not in calendar public function new(width, height, date:Date){ - super(); - today = Day.fromDate(date); - //round down to nearest Sunday to get endDate because nothing in calendar yet - endDate = DateTools.delta(date, -DateTools.days(date.getDay())); - - xOffset = 0; - yOffset = weekdayHeight; - cellWidth = Math.round(width/7); - cellHeight = Math.round((height-weekdayHeight)/2); - rows = 2; - - makeGrid(); - makeWeekdays(); - cells.get(today).backgroundColor = 0xEE5D15; + super(); + today = Day.fromDate(date); + //round down to nearest Sunday to get endDate because nothing in calendar yet + endDate = DateTools.delta(date, -DateTools.days(date.getDay())); + + xOffset = 0; + yOffset = weekdayHeight; + cellWidth = Math.round(width/7); + cellHeight = Math.round((height-weekdayHeight)/2); + rows = 2; + + makeGrid(); + makeWeekdays(); + cells.get(today).backgroundColor = 0xEE5D15; } private function makeRow (rowNum){ - for (j in 0...7){ - - var cell:TextField = new TextField(); - addChild(cell); - - cell.x = xOffset + j*cellWidth; - cell.y = yOffset + rowNum*cellHeight; - cell.text = Std.string(endDate.getDate()); - trace(endDate); - if (endDate.getDate()==1){ - var ms:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - var m = ms[endDate.getMonth()]; - trace(ms); - trace(m); - cell.text += " "+m; - } - - cell.background = true; - cell.backgroundColor = 0xFFFFFF; - cell.border = true; - cell.borderColor = 0x000000; - cell.width = cellWidth; - cell.height = cellHeight; - - cells.set(Day.fromDate(endDate),cell); - - endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); - } + for (j in 0...7){ + + var cell:TextField = new TextField(); + addChild(cell); + + cell.x = xOffset + j*cellWidth; + cell.y = yOffset + rowNum*cellHeight; + cell.text = Std.string(endDate.getDate()); + trace(endDate); + if (endDate.getDate()==1){ + var ms:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + var m = ms[endDate.getMonth()]; + trace(ms); + trace(m); + cell.text += " "+m; + } + + cell.background = true; + cell.backgroundColor = 0xFFFFFF; + cell.border = true; + cell.borderColor = 0x000000; + cell.width = cellWidth; + cell.height = cellHeight; + + cells.set(Day.fromDate(endDate),cell); + + endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); + } } - private function makeGrid() - { - for (i in 0...rows){ - makeRow(i); - } + private function makeGrid(){ + for (i in 0...rows){ + makeRow(i); + } } private function advanceGrid(){ - for (cell in cells){ - if (cell.y <= yOffset){ - removeChild(cell); - } else { - cell.y -= cellHeight; - } - } - makeRow(rows-1); + for (cell in cells){ + if (cell.y <= yOffset){ + removeChild(cell); + } else { + cell.y -= cellHeight; + } + } + makeRow(rows-1); } private function makeWeekdays() { - var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - for (i in 0...7) { - var weekday:TextField = new TextField(); - addChild(weekday); - - weekday.text = names[i]; - weekday.x = xOffset + i*cellWidth; - weekday.y = yOffset - 15; - } + var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + for (i in 0...7) { + var weekday:TextField = new TextField(); + addChild(weekday); + + weekday.text = names[i]; + weekday.x = xOffset + i*cellWidth; + weekday.y = yOffset - 15; + } } public function update(gameDate:Date) { - //trace("hi"); - var day = Day.fromDate(gameDate); - //trace(today.month+" "+today.day); - //trace(day.month+" "+day.day); - if (!today.equals(day)){ - if (gameDate.getDay()==0){ - advanceGrid(); - } - cells.get(day).backgroundColor = 0xEE5D15; - cells.get(today).backgroundColor = 0xFFFFFF; - today=day; - } + //trace("hi"); + var day = Day.fromDate(gameDate); + //trace(today.month+" "+today.day); + //trace(day.month+" "+day.day); + if (!today.equals(day)){ + if (gameDate.getDay()==0){ + advanceGrid(); + } + cells.get(day).backgroundColor = 0xEE5D15; + cells.get(today).backgroundColor = 0xFFFFFF; + today=day; + } } } diff --git a/Source/Day.hx b/Source/Day.hx index 24edaba..fef2e39 100644 --- a/Source/Day.hx +++ b/Source/Day.hx @@ -5,20 +5,20 @@ class Day { public var day:Int; public function new (month:Int, day:Int){ - this.month = month; - this.day = day; + this.month = month; + this.day = day; } public static function fromDate(date:Date){ - return new Day(date.getMonth(), date.getDate()); + return new Day(date.getMonth(), date.getDate()); } public function equals(other:Day){ - return this.hashCode() == other.hashCode(); + return this.hashCode() == other.hashCode(); } - public function hashCode():Int - { - return month*8+day; + + public function hashCode():Int{ + return month*8+day; } } diff --git a/Source/Main.hx b/Source/Main.hx index 86b0f8a..92a45c4 100644 --- a/Source/Main.hx +++ b/Source/Main.hx @@ -37,113 +37,111 @@ class Main extends Sprite { public var colors:Array; public function new () { - - super (); - - var scheduleJson = Assets.getText("assets/schedule.json"); - scheduleObject = Json.parse(scheduleJson); - - colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; - - /* - var bitmapData = Assets.getBitmapData ("assets/openfl.png"); - var bitmap = new Bitmap (bitmapData); - addChild (bitmap); - - bitmap.x = (stage.stageWidth - bitmap.width) / 2; - bitmap.y = (stage.stageHeight - bitmap.height) / 2; - */ - gameDate = new Date(2018, 9, 28, 0, 0, 0); - var gameDay = new Date(2018, 9, 28, 12, 0, 0); - //This is for the purpose of daylight savings. Some days are 23 or 25 hours, so putting the time as noon will be stable WRT these changes. - - //trace(gameDate.getDay()); //Should be 0 - initialTimestamp = Timer.stamp(); - initialGameTimestamp = gameDate.getTime()/1000; - //trace(gameDate.getTime()); - trace(initialTimestamp); - trace(Date.now().getTime()/1000); - trace(Timer.stamp()); - mscheduleSpr = new Calendar(x2,y1, gameDay); - mscheduleSpr.x=2*xM+x1; - mscheduleSpr.y=yM; - var avatarSpr = new Sprite(); - avatarSpr.x=xM; - avatarSpr.y=2*yM+y1; - var classesSpr = new Sprite(); - classesSpr.x=2*xM+x1; - classesSpr.y=2*yM+y1; - wscheduleSpr = new Schedule(x3,y2, gameDay, scheduleObject, colors); - wscheduleSpr.x=3*xM+x1+x2; - wscheduleSpr.y=2*yM+y1; - - // var rectangle1 = new Shape(); - var rectangle2 = new Shape(); - var rectangle3 = new Shape(); - //var rectangle4 = new Shape(); - //rectangle1.graphics.lineStyle(2); - rectangle2.graphics.lineStyle(2); - rectangle3.graphics.lineStyle(2); - //rectangle4.graphics.lineStyle(2); - - //rectangle1.graphics.drawRect(0,0, x2, y1); - rectangle2.graphics.drawRect(0,0, x1, y2); - rectangle3.graphics.drawRect(0,0, x2, y2); - // rectangle4.graphics.drawRect(0,0, x3, y2); - - //mscheduleSpr.addChild(rectangle1); - avatarSpr.addChild(rectangle2); - classesSpr.addChild(rectangle3); - //wscheduleSpr.addChild(rectangle4); - - this.addChild(mscheduleSpr); - this.addChild(avatarSpr); - this.addChild(classesSpr); - this.addChild(wscheduleSpr); - - bar1 = new Bar(0.01, 100, 50, "Drawing", scheduleObject[0], gameDate, colors[0]); - bar1.x = Math.round(x2/7); - bar1.y = y2; - bar2 = new Bar(0.04, 100, 50, "Evolution and Ecology", scheduleObject[1], gameDate, colors[1]); - bar2.x = Math.round(2*x2/7); - bar2.y = y2; - bar3 = new Bar(0.04, 100, 50, "EE Lab", scheduleObject[2], gameDate, colors[2]); - bar3.x = Math.round(3*x2/7); - bar3.y = y2; - bar4 = new Bar(0.04, 100, 50, "Chem", scheduleObject[3], gameDate, colors[3]); - bar4.x = Math.round(4*x2/7); - bar4.y = y2; - bar5 = new Bar(0.04, 100, 50, "Chem Lab", scheduleObject[4], gameDate, colors[4]); - bar5.x = Math.round(5*x2/7); - bar5.y = y2; - bar6 = new Bar(0.01, 100, 50, "How Things Work", scheduleObject[5], gameDate, colors[5]); - bar6.x = Math.round(6*x2/7); - bar6.y = y2; - classesSpr.addChild(bar1); - classesSpr.addChild(bar2); - classesSpr.addChild(bar3); - classesSpr.addChild(bar4); - classesSpr.addChild(bar5); - classesSpr.addChild(bar6); - - stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); - + super (); + + var scheduleJson = Assets.getText("assets/schedule.json"); + scheduleObject = Json.parse(scheduleJson); + + colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; + + /* + var bitmapData = Assets.getBitmapData ("assets/openfl.png"); + var bitmap = new Bitmap (bitmapData); + addChild (bitmap); + + bitmap.x = (stage.stageWidth - bitmap.width) / 2; + bitmap.y = (stage.stageHeight - bitmap.height) / 2; + */ + gameDate = new Date(2018, 9, 28, 0, 0, 0); + var gameDay = new Date(2018, 9, 28, 12, 0, 0); + //This is for the purpose of daylight savings. Some days are 23 or 25 hours, so putting the time as noon will be stable WRT these changes. + + //trace(gameDate.getDay()); //Should be 0 + initialTimestamp = Timer.stamp(); + initialGameTimestamp = gameDate.getTime()/1000; + //trace(gameDate.getTime()); + trace(initialTimestamp); + trace(Date.now().getTime()/1000); + trace(Timer.stamp()); + mscheduleSpr = new Calendar(x2,y1, gameDay); + mscheduleSpr.x=2*xM+x1; + mscheduleSpr.y=yM; + var avatarSpr = new Sprite(); + avatarSpr.x=xM; + avatarSpr.y=2*yM+y1; + var classesSpr = new Sprite(); + classesSpr.x=2*xM+x1; + classesSpr.y=2*yM+y1; + wscheduleSpr = new Schedule(x3,y2, gameDay, scheduleObject, colors); + wscheduleSpr.x=3*xM+x1+x2; + wscheduleSpr.y=2*yM+y1; + + // var rectangle1 = new Shape(); + var rectangle2 = new Shape(); + var rectangle3 = new Shape(); + //var rectangle4 = new Shape(); + //rectangle1.graphics.lineStyle(2); + rectangle2.graphics.lineStyle(2); + rectangle3.graphics.lineStyle(2); + //rectangle4.graphics.lineStyle(2); + + //rectangle1.graphics.drawRect(0,0, x2, y1); + rectangle2.graphics.drawRect(0,0, x1, y2); + rectangle3.graphics.drawRect(0,0, x2, y2); + // rectangle4.graphics.drawRect(0,0, x3, y2); + + //mscheduleSpr.addChild(rectangle1); + avatarSpr.addChild(rectangle2); + classesSpr.addChild(rectangle3); + //wscheduleSpr.addChild(rectangle4); + + this.addChild(mscheduleSpr); + this.addChild(avatarSpr); + this.addChild(classesSpr); + this.addChild(wscheduleSpr); + + bar1 = new Bar(0.01, 100, 50, "Drawing", scheduleObject[0], gameDate, colors[0]); + bar1.x = Math.round(x2/7); + bar1.y = y2; + bar2 = new Bar(0.04, 100, 50, "Evolution and Ecology", scheduleObject[1], gameDate, colors[1]); + bar2.x = Math.round(2*x2/7); + bar2.y = y2; + bar3 = new Bar(0.04, 100, 50, "EE Lab", scheduleObject[2], gameDate, colors[2]); + bar3.x = Math.round(3*x2/7); + bar3.y = y2; + bar4 = new Bar(0.04, 100, 50, "Chem", scheduleObject[3], gameDate, colors[3]); + bar4.x = Math.round(4*x2/7); + bar4.y = y2; + bar5 = new Bar(0.04, 100, 50, "Chem Lab", scheduleObject[4], gameDate, colors[4]); + bar5.x = Math.round(5*x2/7); + bar5.y = y2; + bar6 = new Bar(0.01, 100, 50, "How Things Work", scheduleObject[5], gameDate, colors[5]); + bar6.x = Math.round(6*x2/7); + bar6.y = y2; + classesSpr.addChild(bar1); + classesSpr.addChild(bar2); + classesSpr.addChild(bar3); + classesSpr.addChild(bar4); + classesSpr.addChild(bar5); + classesSpr.addChild(bar6); + + stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame (e:Event){ - //initialTimeStamp is in seconds, but Date.fromTime takes milliseconds - var newGameDate = Date.fromTime(1000*(initialGameTimestamp+timeScale*(Timer.stamp()-initialTimestamp))); - // trace(timeScale*(wut-initialTimeStamp)); - var delta = (newGameDate.getTime() - gameDate.getTime())/1000; - gameDate = newGameDate; - mscheduleSpr.update(gameDate); - wscheduleSpr.update(gameDate); - bar1.update(gameDate, delta); - bar2.update(gameDate, delta); - bar3.update(gameDate, delta); - bar4.update(gameDate, delta); - bar5.update(gameDate, delta); - bar6.update(gameDate, delta); + //initialTimeStamp is in seconds, but Date.fromTime takes milliseconds + var newGameDate = Date.fromTime(1000*(initialGameTimestamp+timeScale*(Timer.stamp()-initialTimestamp))); + // trace(timeScale*(wut-initialTimeStamp)); + var delta = (newGameDate.getTime() - gameDate.getTime())/1000; + gameDate = newGameDate; + mscheduleSpr.update(gameDate); + wscheduleSpr.update(gameDate); + bar1.update(gameDate, delta); + bar2.update(gameDate, delta); + bar3.update(gameDate, delta); + bar4.update(gameDate, delta); + bar5.update(gameDate, delta); + bar6.update(gameDate, delta); } } diff --git a/Source/Schedule.hx b/Source/Schedule.hx index 258458c..b34e942 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -25,144 +25,144 @@ class Schedule extends Sprite { private var colors:Array; public function new (width, height, date:Date, scheduleObject:Array>, colors:Array=null){ - super(); - - this.scheduleObject = scheduleObject; - this.colors = colors; - - if (colors == null || colors.lengthweek){ - break; + week++; + + for (j in 0...7){ + var col:TextField = new TextField(); + addChild(col); + + col.x = xOffset + j*colWidth; + col.y = yOffset; + col.text = Std.string(endDate.getDate()); + + col.background = true; + col.backgroundColor = 0xFFFFFF; + col.border = true; + col.borderColor = 0x000000; + col.width = colWidth; + col.height = colHeight; + + cols.set(Day.fromDate(endDate),col); + endDate = DateTools.delta(endDate, DateTools.days(1)); } - //trace("there"); - var startFrac = (startNums[2]+startNums[3]/60)/24; - var yPos = yOffset + colHeight*startFrac; - var xPos = xOffset + startNums[1]*colWidth; - var endNums = Util.splitAndParseInt(times[1], "/"); - var endFrac = (endNums[2]+endNums[3]/60)/24; - // We don't look at endNums[0] or endNums[1] - var h = colHeight*(endFrac-startFrac); - var lectureCol = new TextField(); - addChild(lectureCol); - - lectureCol.x = xPos; - lectureCol.y = yPos; - lectureCol.text = lecture.title; - - lectureCol.background = true; - lectureCol.backgroundColor = colors[colorNum]; - lectureCol.border = true; - lectureCol.borderColor = 0x000000; - lectureCol.width = colWidth; - lectureCol.height = h; - lectureCols.push(lectureCol); - } - colorNum++; - } - this.addChild(cursor); + var colorNum = 0; + for (lectures in scheduleObject){ + for (lecture in lectures){ + var times = lecture.times.split(" "); + var startNums = Util.splitAndParseInt(times[0], "/"); + //trace("hey"); + if (startNums[0]week){ + break; + } + //trace("there"); + var startFrac = (startNums[2]+startNums[3]/60)/24; + var yPos = yOffset + colHeight*startFrac; + var xPos = xOffset + startNums[1]*colWidth; + var endNums = Util.splitAndParseInt(times[1], "/"); + var endFrac = (endNums[2]+endNums[3]/60)/24; + // We don't look at endNums[0] or endNums[1] + var h = colHeight*(endFrac-startFrac); + var lectureCol = new TextField(); + addChild(lectureCol); + + lectureCol.x = xPos; + lectureCol.y = yPos; + lectureCol.text = lecture.title; + + lectureCol.background = true; + lectureCol.backgroundColor = colors[colorNum]; + lectureCol.border = true; + lectureCol.borderColor = 0x000000; + lectureCol.width = colWidth; + lectureCol.height = h; + + lectureCols.push(lectureCol); + } + colorNum++; + } + this.addChild(cursor); } private function makeWeekdays() { - var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - for (i in 0...7) { - var weekday:TextField = new TextField(); - addChild(weekday); - - weekday.text = names[i]; - weekday.x = xOffset + i*colWidth; - weekday.y = yOffset - 15; - } + var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + for (i in 0...7) { + var weekday:TextField = new TextField(); + addChild(weekday); + + weekday.text = names[i]; + weekday.x = xOffset + i*colWidth; + weekday.y = yOffset - 15; + } } private function advanceCols(){ - for (col in cols){ - removeChild(col); - } - for (lectureCol in lectureCols){ - removeChild(lectureCol); - } - makeCols(); + for (col in cols){ + removeChild(col); + } + for (lectureCol in lectureCols){ + removeChild(lectureCol); + } + makeCols(); } public function update(gameDate:Date) { -// trace("hi"); - var day = Day.fromDate(gameDate); -// trace(today.month+" "+today.day); -// trace(day.month+" "+day.day); - if (!today.equals(day)){ - if (gameDate.getDay()==0){ - advanceCols(); - } - cols.get(day).backgroundColor = 0xEE5D15; - cols.get(today).backgroundColor = 0xFFFFFF; - today=day; - } - cursor.x = xOffset + colWidth*gameDate.getDay(); - cursor.y = yOffset + colHeight*modDay(gameDate); + // trace("hi"); + var day = Day.fromDate(gameDate); + // trace(today.month+" "+today.day); + // trace(day.month+" "+day.day); + if (!today.equals(day)){ + if (gameDate.getDay()==0){ + advanceCols(); + } + cols.get(day).backgroundColor = 0xEE5D15; + cols.get(today).backgroundColor = 0xFFFFFF; + today=day; + } + cursor.x = xOffset + colWidth*gameDate.getDay(); + cursor.y = yOffset + colHeight*modDay(gameDate); } } diff --git a/Source/Util.hx b/Source/Util.hx index 37866bc..68431f7 100644 --- a/Source/Util.hx +++ b/Source/Util.hx @@ -2,18 +2,18 @@ package; class Util { public static function splitAndParseInt(str:String, delim:String){ - var result:Array = new Array(); - for (x in str.split(delim)){ - result.push(Std.parseInt(x)); - } - return result; + var result:Array = new Array(); + for (x in str.split(delim)){ + result.push(Std.parseInt(x)); + } + return result; } public static function jsonTimeToDate (gameDate:Date, jsonTime:String) { - var nums = splitAndParseInt(jsonTime, "/"); - var weeks = nums[0];//Std.parseInt(nums[0]); - var days = nums[1];//Std.parseInt(nums[1]); - var hours = nums[2];//Std.parseInt(nums[2]); - var minutes = nums[3];//Std.parseInt(nums[3]); - return DateTools.delta(gameDate, 1000*60*(minutes+60*(hours+24*(days+7*weeks)))); + var nums = splitAndParseInt(jsonTime, "/"); + var weeks = nums[0];//Std.parseInt(nums[0]); + var days = nums[1];//Std.parseInt(nums[1]); + var hours = nums[2];//Std.parseInt(nums[2]); + var minutes = nums[3];//Std.parseInt(nums[3]); + return DateTools.delta(gameDate, 1000*60*(minutes+60*(hours+24*(days+7*weeks)))); } } From 94d4694adf9a8fa24ff0700d2f2135b10a7417ed Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 29 Jul 2018 15:40:50 -0400 Subject: [PATCH 03/12] Suggested change and code for new json format --- Assets/test.json | 18 ++++++++++++++++++ Source/Bar.hx | 30 ++++++++++++++++++++---------- Source/Calendar.hx | 4 ++-- Source/Day.hx | 6 ++++-- Source/Lecture.hx | 38 +++++++++++++++++++++++++++++++++++++- Source/Main.hx | 35 ++++++++++++++++++++++++----------- Source/Schedule.hx | 46 +++++++++++++++++++++++++--------------------- Source/Util.hx | 7 +++++++ 8 files changed, 137 insertions(+), 47 deletions(-) create mode 100644 Assets/test.json diff --git a/Assets/test.json b/Assets/test.json new file mode 100644 index 0000000..5b5eefa --- /dev/null +++ b/Assets/test.json @@ -0,0 +1,18 @@ +[ + { + "days" : 6, + "interval" : "11:30-13:20", + "start" : { + "day": 30, + "month":9, + "year": 2018 + }, + "end" : { + "day": 1, + "month":2, + "year": 2019 + }, + "size" : 10, + "title" : "Drawing" + } +] diff --git a/Source/Bar.hx b/Source/Bar.hx index 5d6a97c..a28a3cf 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -16,13 +16,13 @@ class Bar extends Sprite private var interestRate:Float; private var workRate:Float; private var working:Bool; - private var lectures:Array; + private var lectures:Lecture.LectureObject; private var lectureNum:Int; private var lectureEndDate:Date; private var initGameDate:Date; // interestRate is the proportion of the total that increases per day - public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Array, gameDate:Date, color:Int=0x000000) { + public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Lecture.LectureObject, gameDate:Date, color:Int=0x000000) { super(); movable = new Sprite(); @@ -59,7 +59,7 @@ class Bar extends Sprite this.lectures = lectures; lectureNum = 0; initGameDate = gameDate; - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); + lectureEndDate = lectures.startDate; } public function update(gameDate:Date, delta:Float) { @@ -81,14 +81,24 @@ class Bar extends Sprite } private function getHomework(gameDate:Date){ - if (lectureNum < lectures.length){ - if (gameDate.getTime() > lectureEndDate.getTime()){ - movable.y -= lectures[lectureNum].size; + if (gameDate.getTime() < lectures.endDate.getTime() && gameDate.getTime() > lectureEndDate.getTime()){ + movable.y -= lectures.size; lectureNum++; - if (lectureNum < lectures.length){ - lectureEndDate = Util.jsonTimeToDate(initGameDate, lectures[lectureNum].times.split(" ")[1]); - } + lectureEndDate = nextHomework(gameDate); + } + } + + //Returns the next date that a homwork will be due/lecture will occur + private function nextHomework(gameDate:Date) : Date { + var nextDate = DateTools.delta(gameDate, DateTools.days(1)); + while (Util.DayinRange(lectures.startDate, lectures.endDate, nextDate)){ + trace(nextDate); + if (((lectures.days >> (6 - nextDate.getDay())) & 1) == 1){ + trace("found"); + return nextDate; } + nextDate = DateTools.delta(nextDate, DateTools.days(1)); } - } + return null; + } } diff --git a/Source/Calendar.hx b/Source/Calendar.hx index 53d1728..3d431e2 100644 --- a/Source/Calendar.hx +++ b/Source/Calendar.hx @@ -75,9 +75,9 @@ class Calendar extends Sprite { private function advanceGrid(){ for (cell in cells){ if (cell.y <= yOffset){ - removeChild(cell); + removeChild(cell); } else { - cell.y -= cellHeight; + cell.y -= cellHeight; } } makeRow(rows-1); diff --git a/Source/Day.hx b/Source/Day.hx index fef2e39..228d5a1 100644 --- a/Source/Day.hx +++ b/Source/Day.hx @@ -3,14 +3,16 @@ package; class Day { public var month:Int; public var day:Int; + public var year:Int; - public function new (month:Int, day:Int){ + public function new (month:Int, day:Int, year:Int){ this.month = month; this.day = day; + this.year = year; } public static function fromDate(date:Date){ - return new Day(date.getMonth(), date.getDate()); + return new Day(date.getMonth(), date.getDate(), date.getFullYear()); } public function equals(other:Day){ diff --git a/Source/Lecture.hx b/Source/Lecture.hx index d9f9975..47f5f7f 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -1,7 +1,43 @@ package; typedef Lecture = { - var times:String; + var days:Int; + var interval:String; + var start:SSDate; + var end:SSDate; var size:Int; var title:String; +} + +typedef SSDate = { + var day:Int; + var month:Int; + var year:Int; +} + +class LectureObject { + public var startDate:Date; + public var endDate:Date; + public var days:Int; + public var interval:String; + public var size:Int; + public var title:String; + + public function new (lecture:Lecture){ + var start = Util.splitAndParseInt(lecture.interval.split("-")[0], ":"); + + this.startDate = new Date(lecture.start.year, lecture.start.month, lecture.start.day, start[0], start[1], 0); + var delta = 0; + + while ((lecture.days >> (6 - delta - startDate.getDay())) & 1 != 1) + delta++; + + startDate = DateTools.delta(this.startDate, DateTools.days(delta)); + + this.endDate = new Date(lecture.end.year, lecture.end.month, lecture.end.day, 0, 0, 0); + this.days = lecture.days; + this.size = lecture.size; + this.title = lecture.title; + this.interval = lecture.interval; + } } \ No newline at end of file diff --git a/Source/Main.hx b/Source/Main.hx index 92a45c4..66beb6b 100644 --- a/Source/Main.hx +++ b/Source/Main.hx @@ -1,11 +1,12 @@ package; - import openfl.display.Sprite; import openfl.display.Shape; import openfl.display.Bitmap; import openfl.Assets; import openfl.events.Event; +import openfl.events.KeyboardEvent; +import openfl.ui.Keyboard; import haxe.Json; import haxe.Timer; @@ -33,14 +34,18 @@ class Main extends Sprite { public var bar6:Bar; public var initialTimestamp:Float; public var initialGameTimestamp:Float; - public var scheduleObject:Array>; + public var scheduleObject:Array; public var colors:Array; public function new () { super (); - var scheduleJson = Assets.getText("assets/schedule.json"); - scheduleObject = Json.parse(scheduleJson); + var scheduleJson = Assets.getText("assets/test.json"); + var lectureArray:Array = Json.parse(scheduleJson); + var scheduleObject:Array = new Array(); + for (lecture in lectureArray){ + scheduleObject.push(new Lecture.LectureObject(lecture)); + } colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF]; @@ -100,10 +105,10 @@ class Main extends Sprite { this.addChild(classesSpr); this.addChild(wscheduleSpr); - bar1 = new Bar(0.01, 100, 50, "Drawing", scheduleObject[0], gameDate, colors[0]); + bar1 = new Bar(0.04, 100, 50, "Drawing", scheduleObject[0], gameDate, colors[0]); bar1.x = Math.round(x2/7); bar1.y = y2; - bar2 = new Bar(0.04, 100, 50, "Evolution and Ecology", scheduleObject[1], gameDate, colors[1]); + /*bar2 = new Bar(0.04, 100, 50, "Evolution and Ecology", scheduleObject[1], gameDate, colors[1]); bar2.x = Math.round(2*x2/7); bar2.y = y2; bar3 = new Bar(0.04, 100, 50, "EE Lab", scheduleObject[2], gameDate, colors[2]); @@ -117,17 +122,25 @@ class Main extends Sprite { bar5.y = y2; bar6 = new Bar(0.01, 100, 50, "How Things Work", scheduleObject[5], gameDate, colors[5]); bar6.x = Math.round(6*x2/7); - bar6.y = y2; + bar6.y = y2;*/ classesSpr.addChild(bar1); - classesSpr.addChild(bar2); + /*classesSpr.addChild(bar2); classesSpr.addChild(bar3); classesSpr.addChild(bar4); classesSpr.addChild(bar5); - classesSpr.addChild(bar6); + classesSpr.addChild(bar6);*/ stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); + stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); } + private function onKeyDown(e:KeyboardEvent){ + if (e.keyCode == Keyboard.ESCAPE){ + var i:Int = 0; + while (i < 1000000) i++; + } + } + private function onEnterFrame (e:Event){ //initialTimeStamp is in seconds, but Date.fromTime takes milliseconds var newGameDate = Date.fromTime(1000*(initialGameTimestamp+timeScale*(Timer.stamp()-initialTimestamp))); @@ -137,11 +150,11 @@ class Main extends Sprite { mscheduleSpr.update(gameDate); wscheduleSpr.update(gameDate); bar1.update(gameDate, delta); - bar2.update(gameDate, delta); + /*bar2.update(gameDate, delta); bar3.update(gameDate, delta); bar4.update(gameDate, delta); bar5.update(gameDate, delta); - bar6.update(gameDate, delta); + bar6.update(gameDate, delta);*/ } } diff --git a/Source/Schedule.hx b/Source/Schedule.hx index d43fafa..d505ba2 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -21,13 +21,13 @@ class Schedule extends Sprite { private var cursor:Shape; private var week:Int; - private var scheduleObject:Array>; + private var scheduleObject:Array; private var colors:Array; private var textHeight:Int; private var format:TextFormat; - public function new (width, height, date:Date, scheduleObject:Array>, colors:Array=null){ + public function new (width, height, date:Date, scheduleObject:Array, colors:Array=null){ super(); this.scheduleObject = scheduleObject; @@ -36,7 +36,7 @@ class Schedule extends Sprite { if (colors == null || colors.length> (6 - j)) & 1 == 1)) + continue; + // If lecture is not held within the range of this week + if (!Util.DayinRange(lecture.startDate, lecture.endDate, cursorDate)) continue; - } else if(startNums[0]>week){ - break; - } - //trace("there"); - var startFrac = (startNums[2]+startNums[3]/60)/24; + // Lecture will be added since it is on this day in range + var time = lecture.interval.split("-"); + var start = Util.splitAndParseInt(time[0], ":"); + var end = Util.splitAndParseInt(time[1], ":"); + + var startFrac = (start[0] + start[1] / 60) / 24; var yPos = yOffset + colHeight*startFrac; - var xPos = xOffset + startNums[1]*colWidth; - var endNums = Util.splitAndParseInt(times[1], "/"); - var endFrac = (endNums[2]+endNums[3]/60)/24; - // We don't look at endNums[0] or endNums[1] + var xPos = xOffset + j * colWidth; + + var endFrac = (end[0] + end[1] / 60) / 24; var h = colHeight*(endFrac-startFrac); var lectureCol = new TextField(); addChild(lectureCol); @@ -127,8 +131,8 @@ class Schedule extends Sprite { lectureCol.height = h; lectureCols.push(lectureCol); + colorNum++; } - colorNum++; } this.addChild(cursor); } @@ -177,7 +181,7 @@ class Schedule extends Sprite { // trace(day.month+" "+day.day); if (!today.equals(day)){ if (gameDate.getDay()==0){ - advanceCols(); + advanceCols(); } cols.get(day).backgroundColor = 0xEE5D15; cols.get(today).backgroundColor = 0xFFFFFF; diff --git a/Source/Util.hx b/Source/Util.hx index 68431f7..677c155 100644 --- a/Source/Util.hx +++ b/Source/Util.hx @@ -16,4 +16,11 @@ class Util { var minutes = nums[3];//Std.parseInt(nums[3]); return DateTools.delta(gameDate, 1000*60*(minutes+60*(hours+24*(days+7*weeks)))); } + + public static function DayinRange(startDate:Date, endDate:Date, date:Date): Bool{ + var start:Float = startDate.getTime(); + var end:Float = endDate.getTime(); + var day:Float = date.getTime(); + return day >= start && day <= end; + } } From 909bc96c733d36c0b08e461d13b8ccdf33147ef7 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 3 Aug 2018 21:10:08 -0400 Subject: [PATCH 04/12] Made lecture days independent from each other --- Assets/test.json | 12 ++++++++++-- Source/Bar.hx | 23 ++++++++++++++--------- Source/Lecture.hx | 27 ++++++++++++++++----------- Source/Schedule.hx | 5 +++-- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/Assets/test.json b/Assets/test.json index 5b5eefa..1420d3a 100644 --- a/Assets/test.json +++ b/Assets/test.json @@ -1,7 +1,15 @@ [ { - "days" : 6, - "interval" : "11:30-13:20", + "days" : [ + { + "weekday" : 4, + "time" : "13:30-15:20" + }, + { + "weekday" : 5, + "time" : "10:30-12:30" + } + ], "start" : { "day": 30, "month":9, diff --git a/Source/Bar.hx b/Source/Bar.hx index a28a3cf..fa8eaae 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -22,7 +22,8 @@ class Bar extends Sprite private var initGameDate:Date; // interestRate is the proportion of the total that increases per day - public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Lecture.LectureObject, gameDate:Date, color:Int=0x000000) { + public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, + lectures:Lecture.LectureObject, gameDate:Date, color:Int=0x000000) { super(); movable = new Sprite(); @@ -90,15 +91,19 @@ class Bar extends Sprite //Returns the next date that a homwork will be due/lecture will occur private function nextHomework(gameDate:Date) : Date { - var nextDate = DateTools.delta(gameDate, DateTools.days(1)); - while (Util.DayinRange(lectures.startDate, lectures.endDate, nextDate)){ - trace(nextDate); - if (((lectures.days >> (6 - nextDate.getDay())) & 1) == 1){ - trace("found"); - return nextDate; - } - nextDate = DateTools.delta(nextDate, DateTools.days(1)); + var nextIndex = (lectures.weekdays.indexOf(gameDate.getDay()) + 1) % lectures.weekdays.length; + var next = lectures.weekdays[nextIndex]; + var nextStart = Util.splitAndParseInt(lectures.times[nextIndex].split("-")[0], ":"); + + var delta:Float = next - gameDate.getDay(); + if (delta <= 0) { + delta = 7 + delta; } + delta = DateTools.days(delta) + DateTools.hours(nextStart[0] - gameDate.getHours()) + DateTools.minutes(nextStart[1] - gameDate.getMinutes()); + + var nextDate = DateTools.delta(gameDate, delta); + if (Util.DayinRange(lectures.startDate, lectures.endDate, nextDate)) + return nextDate; return null; } } diff --git a/Source/Lecture.hx b/Source/Lecture.hx index 47f5f7f..4c014af 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -1,14 +1,18 @@ package; typedef Lecture = { - var days:Int; - var interval:String; + var days:Array; var start:SSDate; var end:SSDate; var size:Int; var title:String; } +typedef LectureDay = { + var weekday:Int; + var time:String; +} + typedef SSDate = { var day:Int; var month:Int; @@ -18,26 +22,27 @@ typedef SSDate = { class LectureObject { public var startDate:Date; public var endDate:Date; - public var days:Int; - public var interval:String; + public var weekdays:Array; + public var times:Array; public var size:Int; public var title:String; public function new (lecture:Lecture){ - var start = Util.splitAndParseInt(lecture.interval.split("-")[0], ":"); + var start = Util.splitAndParseInt(lecture.days[0].time.split("-")[0], ":"); this.startDate = new Date(lecture.start.year, lecture.start.month, lecture.start.day, start[0], start[1], 0); - var delta = 0; - - while ((lecture.days >> (6 - delta - startDate.getDay())) & 1 != 1) - delta++; + var delta = lecture.days[0].weekday - startDate.getDay(); startDate = DateTools.delta(this.startDate, DateTools.days(delta)); + this.times = new Array(); + this.weekdays = new Array(); + for (i in lecture.days) { + times.push(i.time); + weekdays.push(i.weekday); + } this.endDate = new Date(lecture.end.year, lecture.end.month, lecture.end.day, 0, 0, 0); - this.days = lecture.days; this.size = lecture.size; this.title = lecture.title; - this.interval = lecture.interval; } } \ No newline at end of file diff --git a/Source/Schedule.hx b/Source/Schedule.hx index d505ba2..bc6bf2a 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -100,13 +100,14 @@ class Schedule extends Sprite { cursorDate = DateTools.delta(cursorDate, DateTools.days(1)); for (lecture in scheduleObject){ // If lecture is not held on that day continue to next lecture - if (!((lecture.days >> (6 - j)) & 1 == 1)) + if (lecture.weekdays.indexOf(j) == -1) continue; + var index = lecture.weekdays.indexOf(j); // If lecture is not held within the range of this week if (!Util.DayinRange(lecture.startDate, lecture.endDate, cursorDate)) continue; // Lecture will be added since it is on this day in range - var time = lecture.interval.split("-"); + var time = lecture.times[index].split("-"); var start = Util.splitAndParseInt(time[0], ":"); var end = Util.splitAndParseInt(time[1], ":"); From b607a149d0981ae87c077de887bca2641fd46ee7 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 3 Aug 2018 21:48:46 -0400 Subject: [PATCH 05/12] Fixed bug with time --- Source/Schedule.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Schedule.hx b/Source/Schedule.hx index bc6bf2a..3143474 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -44,9 +44,9 @@ class Schedule extends Sprite { //round down to nearest Sunday to get endDate because nothing in schedule yet endDate = DateTools.delta(date, -DateTools.days(date.getDay())); - xOffset = 0; + xOffset = 40; yOffset = weekdayHeight; - colWidth = Math.round(width/7); + colWidth = Math.round((width-xOffset)/7); colHeight = height-weekdayHeight; textHeight = 10; format = new TextFormat(textHeight); From 764c6c0d958bd9936a52b18eb5988334f1e50c01 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 4 Aug 2018 11:08:34 -0400 Subject: [PATCH 06/12] Added different kinds of homeworks for lectures to Json --- Assets/test.json | 30 ++++++++++++++++---- Source/Bar.hx | 23 ++++++++++------ Source/Lecture.hx | 70 +++++++++++++++++++++++------------------------ 3 files changed, 74 insertions(+), 49 deletions(-) diff --git a/Assets/test.json b/Assets/test.json index fdb1e58..effaa4d 100644 --- a/Assets/test.json +++ b/Assets/test.json @@ -20,7 +20,11 @@ "month": 2, "year": 2019 }, - "size": 10, + "homework": [ + [20, 6], + [10, 4], + [30, 3] + ], "title": "Drawing" }, { @@ -48,7 +52,11 @@ "month": 2, "year": 2019 }, - "size": 25, + "homework": [ + [25, 6], + [5, 4], + [30, 3] + ], "title": "Evolution and Ecology" }, { @@ -68,7 +76,9 @@ "month": 2, "year": 2019 }, - "size": 60, + "homework": [ + [60, 10] + ], "title": "EE Lab" }, { @@ -96,7 +106,11 @@ "month": 2, "year": 2019 }, - "size": 25, + "homework": [ + [25, 6], + [5, 4], + [30, 3] + ], "title": "Chem" }, { @@ -116,7 +130,9 @@ "month": 2, "year": 2019 }, - "size": 60, + "homework": [ + [60, 10] + ], "title": "Chem Lab" }, { @@ -140,7 +156,9 @@ "month": 2, "year": 2019 }, - "size": 10, + "homework": [ + [10, 20] + ], "title": "How Things Work" } ] diff --git a/Source/Bar.hx b/Source/Bar.hx index 73546e5..9ad9b4c 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -19,6 +19,7 @@ class Bar extends Sprite { private var lectureEndDate:Date; private var initGameDate:Date; private var color:Int; + private var currentHomework:Int; // interestRate is the proportion of the total that increases per day @@ -38,6 +39,7 @@ class Bar extends Sprite { lectureNum = 0; initGameDate = gameDate; lectureEndDate = lectures.startDate; + currentHomework = 0; } public function update(gameDate:Date, delta:Float) { @@ -59,14 +61,19 @@ class Bar extends Sprite { } private function getHomework(gameDate:Date) { - if (gameDate.getTime() < lectures.endDate.getTime() && gameDate.getTime() > lectureEndDate.getTime()) { - var size = lectures.size; - var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); - assignments.push(assignment); - this.addChild(assignment); - lectureNum++; - lectureEndDate = nextHomework(gameDate); - numAssignments++; + if (currentHomework < lectures.homework.length) { + if (gameDate.getTime() < lectures.endDate.getTime() && gameDate.getTime() > lectureEndDate.getTime()) { + var size = lectures.homework[currentHomework][0]; + var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); + assignments.push(assignment); + this.addChild(assignment); + lectureNum++; + lectureEndDate = nextHomework(gameDate); + numAssignments++; + lectures.homework[currentHomework][1]--; + if (lectures.homework[currentHomework][1] == 0) + currentHomework++; + } } } diff --git a/Source/Lecture.hx b/Source/Lecture.hx index 4c014af..5232443 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -1,48 +1,48 @@ package; typedef Lecture = { - var days:Array; - var start:SSDate; - var end:SSDate; - var size:Int; + var days:Array; + var start:SSDate; + var end:SSDate; + var homework:Array>; var title:String; } typedef LectureDay = { - var weekday:Int; - var time:String; + var weekday:Int; + var time:String; } typedef SSDate = { - var day:Int; - var month:Int; - var year:Int; + var day:Int; + var month:Int; + var year:Int; } class LectureObject { - public var startDate:Date; - public var endDate:Date; - public var weekdays:Array; - public var times:Array; - public var size:Int; - public var title:String; - - public function new (lecture:Lecture){ - var start = Util.splitAndParseInt(lecture.days[0].time.split("-")[0], ":"); - - this.startDate = new Date(lecture.start.year, lecture.start.month, lecture.start.day, start[0], start[1], 0); - var delta = lecture.days[0].weekday - startDate.getDay(); - - startDate = DateTools.delta(this.startDate, DateTools.days(delta)); - - this.times = new Array(); - this.weekdays = new Array(); - for (i in lecture.days) { - times.push(i.time); - weekdays.push(i.weekday); - } - this.endDate = new Date(lecture.end.year, lecture.end.month, lecture.end.day, 0, 0, 0); - this.size = lecture.size; - this.title = lecture.title; - } -} \ No newline at end of file + public var startDate:Date; + public var endDate:Date; + public var weekdays:Array; + public var times:Array; + public var homework:Array>; + public var title:String; + + public function new(lecture:Lecture) { + var start = Util.splitAndParseInt(lecture.days[0].time.split("-")[0], ":"); + + this.startDate = new Date(lecture.start.year, lecture.start.month, lecture.start.day, start[0], start[1], 0); + var delta = lecture.days[0].weekday - startDate.getDay(); + + startDate = DateTools.delta(this.startDate, DateTools.days(delta)); + + this.times = new Array(); + this.weekdays = new Array(); + for (i in lecture.days) { + times.push(i.time); + weekdays.push(i.weekday); + } + this.endDate = new Date(lecture.end.year, lecture.end.month, lecture.end.day, 0, 0, 0); + this.homework = lecture.homework; + this.title = lecture.title; + } +} From d88964a657b132fee93b87105c9cf1ebd9048056 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 4 Aug 2018 12:28:32 -0400 Subject: [PATCH 07/12] Fixed bug where schedule had wrong colors and added projects to Json --- Assets/test.json | 14 ++++++++++---- Source/Lecture.hx | 1 + Source/Schedule.hx | 4 +--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Assets/test.json b/Assets/test.json index effaa4d..6204a11 100644 --- a/Assets/test.json +++ b/Assets/test.json @@ -2,12 +2,12 @@ { "days": [ { - "weekday": 4, - "time": "13:30-15:20" + "weekday": 2, + "time": "11:30-13:20" }, { - "weekday": 5, - "time": "10:30-12:30" + "weekday": 4, + "time": "13:30-15:20" } ], "start": { @@ -57,6 +57,7 @@ [5, 4], [30, 3] ], + "project": 1000, "title": "Evolution and Ecology" }, { @@ -79,6 +80,7 @@ "homework": [ [60, 10] ], + "project": 0, "title": "EE Lab" }, { @@ -111,6 +113,7 @@ [5, 4], [30, 3] ], + "project": 0, "title": "Chem" }, { @@ -133,6 +136,7 @@ "homework": [ [60, 10] ], + "project": 0, "title": "Chem Lab" }, { @@ -157,8 +161,10 @@ "year": 2019 }, "homework": [ + [0, 2], [10, 20] ], + "project": 0, "title": "How Things Work" } ] diff --git a/Source/Lecture.hx b/Source/Lecture.hx index 5232443..16e3744 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -5,6 +5,7 @@ typedef Lecture = { var start:SSDate; var end:SSDate; var homework:Array>; + var project:Int; var title:String; } diff --git a/Source/Schedule.hx b/Source/Schedule.hx index 3143474..118cd53 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -96,7 +96,6 @@ class Schedule extends Sprite { var cursorDate = new Date(today.year, today.month, today.day, 0, 0, 0); cursorDate = DateTools.delta(cursorDate, DateTools.days(1)); for (j in 0...7){ - var colorNum = 0; cursorDate = DateTools.delta(cursorDate, DateTools.days(1)); for (lecture in scheduleObject){ // If lecture is not held on that day continue to next lecture @@ -125,14 +124,13 @@ class Schedule extends Sprite { lectureCol.text = lecture.title; lectureCol.background = true; - lectureCol.backgroundColor = colors[colorNum]; + lectureCol.backgroundColor = colors[scheduleObject.indexOf(lecture)]; lectureCol.border = true; lectureCol.borderColor = 0x000000; lectureCol.width = colWidth; lectureCol.height = h; lectureCols.push(lectureCol); - colorNum++; } } this.addChild(cursor); From 9a85c8dbb11049a1c6b4d874c96a1f79ffb05d05 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 4 Aug 2018 13:28:38 -0400 Subject: [PATCH 08/12] Added Handling of Exceptions to when lectures are held (HW is not assigned at these points) --- Assets/test.json | 7 +++++++ Source/Bar.hx | 11 +++++++---- Source/Lecture.hx | 5 +++++ Source/Schedule.hx | 5 +++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Assets/test.json b/Assets/test.json index 6204a11..7d77c13 100644 --- a/Assets/test.json +++ b/Assets/test.json @@ -25,6 +25,8 @@ [10, 4], [30, 3] ], + "project": 100, + "exception": [3, 4, 8, 2], "title": "Drawing" }, { @@ -58,6 +60,7 @@ [30, 3] ], "project": 1000, + "exception": [5], "title": "Evolution and Ecology" }, { @@ -81,6 +84,7 @@ [60, 10] ], "project": 0, + "exception": [8, 2], "title": "EE Lab" }, { @@ -114,6 +118,7 @@ [30, 3] ], "project": 0, + "exception": [3, 4], "title": "Chem" }, { @@ -137,6 +142,7 @@ [60, 10] ], "project": 0, + "exception": [], "title": "Chem Lab" }, { @@ -165,6 +171,7 @@ [10, 20] ], "project": 0, + "exception": [], "title": "How Things Work" } ] diff --git a/Source/Bar.hx b/Source/Bar.hx index 9ad9b4c..ad7265e 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -20,6 +20,7 @@ class Bar extends Sprite { private var initGameDate:Date; private var color:Int; private var currentHomework:Int; + private var totalHW:Int; // interestRate is the proportion of the total that increases per day @@ -36,10 +37,10 @@ class Bar extends Sprite { this.interestRate = interestRate; this.workRate = workRate; this.lectures = lectures; - lectureNum = 0; initGameDate = gameDate; lectureEndDate = lectures.startDate; currentHomework = 0; + totalHW = 0; } public function update(gameDate:Date, delta:Float) { @@ -63,14 +64,16 @@ class Bar extends Sprite { private function getHomework(gameDate:Date) { if (currentHomework < lectures.homework.length) { if (gameDate.getTime() < lectures.endDate.getTime() && gameDate.getTime() > lectureEndDate.getTime()) { + lectures.homework[currentHomework][1]--; + lectureEndDate = nextHomework(gameDate); + + if (lectures.exceptions.indexOf(totalHW++) != -1) return; + var size = lectures.homework[currentHomework][0]; var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); assignments.push(assignment); this.addChild(assignment); - lectureNum++; - lectureEndDate = nextHomework(gameDate); numAssignments++; - lectures.homework[currentHomework][1]--; if (lectures.homework[currentHomework][1] == 0) currentHomework++; } diff --git a/Source/Lecture.hx b/Source/Lecture.hx index 16e3744..72d2642 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -6,6 +6,7 @@ typedef Lecture = { var end:SSDate; var homework:Array>; var project:Int; + var exception:Array; var title:String; } @@ -27,6 +28,8 @@ class LectureObject { public var times:Array; public var homework:Array>; public var title:String; + public var exceptions:Array; + public var curLectureNum:Int; public function new(lecture:Lecture) { var start = Util.splitAndParseInt(lecture.days[0].time.split("-")[0], ":"); @@ -45,5 +48,7 @@ class LectureObject { this.endDate = new Date(lecture.end.year, lecture.end.month, lecture.end.day, 0, 0, 0); this.homework = lecture.homework; this.title = lecture.title; + this.exceptions = lecture.exception; + this.curLectureNum = 0; } } diff --git a/Source/Schedule.hx b/Source/Schedule.hx index 20def53..d81c453 100644 --- a/Source/Schedule.hx +++ b/Source/Schedule.hx @@ -101,6 +101,10 @@ class Schedule extends Sprite { // If lecture is not held on that day continue to next lecture if (lecture.weekdays.indexOf(j) == -1) continue; + if (lecture.exceptions.indexOf(lecture.curLectureNum) != -1){ + lecture.curLectureNum++; + continue; + } var index = lecture.weekdays.indexOf(j); // If lecture is not held within the range of this week if (!Util.DayinRange(lecture.startDate, lecture.endDate, cursorDate)) @@ -129,6 +133,7 @@ class Schedule extends Sprite { lectureCol.borderColor = 0x000000; lectureCol.width = colWidth; lectureCol.height = h; + lecture.curLectureNum++; lectureCols.push(lectureCol); } From d1d7e4f5927b8e0717f4756ddc04c1f3a047de0e Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 6 Aug 2018 16:43:50 -0400 Subject: [PATCH 09/12] Lectures can alternate weeks and be held multiple time in one day --- Assets/test.json | 34 +++++++--- Source/Bar.hx | 159 ++++++++++++++++++++++--------------------- Source/Calendar.hx | 46 ++++++------- Source/Lecture.hx | 98 +++++++++++++++----------- Source/Main.hx | 63 ++++++++--------- Source/Schedule.hx | 166 ++++++++++++++++++++++----------------------- Source/Util.hx | 8 +-- 7 files changed, 302 insertions(+), 272 deletions(-) diff --git a/Assets/test.json b/Assets/test.json index 7d77c13..9d13a0b 100644 --- a/Assets/test.json +++ b/Assets/test.json @@ -5,13 +5,17 @@ "weekday": 2, "time": "11:30-13:20" }, + { + "weekday": 2, + "time": "14:00-15:00" + }, { "weekday": 4, "time": "13:30-15:20" } ], "start": { - "day": 30, + "day": 28, "month": 9, "year": 2018 }, @@ -26,7 +30,7 @@ [30, 3] ], "project": 100, - "exception": [3, 4, 8, 2], + "exception": [3], "title": "Drawing" }, { @@ -42,10 +46,18 @@ { "weekday": 5, "time": "10:30-11:20" + }, + { + "weekday": 2, + "time": "15:00-15:30" + }, + { + "weekday": 4, + "time": "15:00-15:30" } ], "start": { - "day": 30, + "day": 28, "month": 9, "year": 2018 }, @@ -71,7 +83,7 @@ } ], "start": { - "day": 30, + "day": 28, "month": 9, "year": 2018 }, @@ -84,7 +96,7 @@ [60, 10] ], "project": 0, - "exception": [8, 2], + "exception": [3, 8, 2], "title": "EE Lab" }, { @@ -103,7 +115,7 @@ } ], "start": { - "day": 30, + "day": 28, "month": 9, "year": 2018 }, @@ -118,7 +130,7 @@ [30, 3] ], "project": 0, - "exception": [3, 4], + "exception": [], "title": "Chem" }, { @@ -129,7 +141,7 @@ } ], "start": { - "day": 30, + "day": 28, "month": 9, "year": 2018 }, @@ -142,7 +154,7 @@ [60, 10] ], "project": 0, - "exception": [], + "exception": [7, 4], "title": "Chem Lab" }, { @@ -157,7 +169,7 @@ } ], "start": { - "day": 30, + "day": 28, "month": 9, "year": 2018 }, @@ -171,7 +183,7 @@ [10, 20] ], "project": 0, - "exception": [], + "exception": [4, 5], "title": "How Things Work" } ] diff --git a/Source/Bar.hx b/Source/Bar.hx index ad7265e..aedd0a3 100644 --- a/Source/Bar.hx +++ b/Source/Bar.hx @@ -1,100 +1,101 @@ package; +import DateTools; import openfl.display.Sprite; import openfl.display.Shape; import openfl.text.TextField; import openfl.events.MouseEvent; class Bar extends Sprite { - private var nameHeight = 15; - private var barWidth = 20; - private var assignments:Array; - private var heights:Array; - private var numAssignments:Int; - // private var nameField:TextField; - private var interestRate:Float; - private var workRate:Float; - private var lectures:Lecture.LectureObject; - private var lectureNum:Int; - private var lectureEndDate:Date; - private var initGameDate:Date; - private var color:Int; - private var currentHomework:Int; - private var totalHW:Int; + private var nameHeight = 15; + private var barWidth = 20; + private var assignments:Array; + private var heights:Array; + private var numAssignments:Int; + // private var nameField:TextField; + private var interestRate:Float; + private var workRate:Float; + private var lectures:Lecture.LectureObject; + private var lectureEndDate:Date; + private var initGameDate:Date; + private var color:Int; + private var currentHomework:Int; - // interestRate is the proportion of the total that increases per day + // interestRate is the proportion of the total that increases per day - public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Lecture.LectureObject, gameDate:Date, color:Int = 0x000000) { - super(); + public function new(interestRate:Float, workRate:Float, startHeight:Int, nameStr:String, lectures:Lecture.LectureObject, gameDate:Date, color:Int = 0x000000) { + super(); - this.color = color; + this.color = color; - assignments = new Array(); - heights = new Array(); - heights.push(0); - numAssignments = 0; + assignments = new Array(); + heights = new Array(); + heights.push(0); + numAssignments = 0; - this.interestRate = interestRate; - this.workRate = workRate; - this.lectures = lectures; - initGameDate = gameDate; - lectureEndDate = lectures.startDate; - currentHomework = 0; - totalHW = 0; - } + this.interestRate = interestRate; + this.workRate = workRate; + this.lectures = lectures; + initGameDate = gameDate; - public function update(gameDate:Date, delta:Float) { - var i:Int = 0; - var size:Float; - // We need a while loop instead of a for loop because numAssignments can change during, and a for loop converts it to a number at the outset - while (i < numAssignments) { - size = assignments[i].update(gameDate, delta, heights[i]); - if (size == 0) { - removeChild(assignments[i]); - assignments = assignments.slice(0, i).concat(assignments.slice(i + 1)); - numAssignments--; - } else { - heights[i + 1] = heights[i] + size; - } - i++; - } - getHomework(gameDate); - } + lectureEndDate = new Date(lectures.startDate.getFullYear(), lectures.startDate.getMonth(), lectures.startDate.getDate(), + lectures.times[0].end[0], lectures.times[0].end[1], 0); + currentHomework = 0; + } - private function getHomework(gameDate:Date) { - if (currentHomework < lectures.homework.length) { - if (gameDate.getTime() < lectures.endDate.getTime() && gameDate.getTime() > lectureEndDate.getTime()) { - lectures.homework[currentHomework][1]--; - lectureEndDate = nextHomework(gameDate); + public function update(gameDate:Date, delta:Float) { + var i:Int = 0; + var size:Float; + // We need a while loop instead of a for loop because numAssignments can change during, and a for loop converts it to a number at the outset + while (i < numAssignments) { + size = assignments[i].update(gameDate, delta, heights[i]); + if (size == 0) { + removeChild(assignments[i]); + assignments = assignments.slice(0, i).concat(assignments.slice(i + 1)); + numAssignments--; + } else { + heights[i + 1] = heights[i] + size; + } + i++; + } + getHomework(gameDate); + } - if (lectures.exceptions.indexOf(totalHW++) != -1) return; + private function getHomework(gameDate:Date) { + if (currentHomework < lectures.homework.length) { + if (gameDate.getTime() < lectures.endDate.getTime() && gameDate.getTime() > lectureEndDate.getTime()) { + lectures.homework[currentHomework][1]--; + lectureEndDate = nextHomework(gameDate); - var size = lectures.homework[currentHomework][0]; - var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); - assignments.push(assignment); - this.addChild(assignment); - numAssignments++; - if (lectures.homework[currentHomework][1] == 0) - currentHomework++; - } - } - } + if (lectures.exceptions.indexOf(lectures.curLectureNum++) != -1) return; - //Returns the next date that a homwork will be due/lecture will occur - private function nextHomework(gameDate:Date):Date { - var nextIndex = (lectures.weekdays.indexOf(gameDate.getDay()) + 1) % lectures.weekdays.length; - var next = lectures.weekdays[nextIndex]; - var nextStart = Util.splitAndParseInt(lectures.times[nextIndex].split("-")[0], ":"); + var size = lectures.homework[currentHomework][0]; + var assignment = new Assignment(size, heights[numAssignments], color, barWidth, interestRate, workRate); + assignments.push(assignment); + this.addChild(assignment); + numAssignments++; + if (lectures.homework[currentHomework][1] == 0) + currentHomework++; + } + } + } - var delta:Float = next - gameDate.getDay(); - if (delta <= 0) { - delta = 7 + delta; - } - delta = DateTools.days(delta) + DateTools.hours(nextStart[0] - gameDate.getHours()) + DateTools.minutes(nextStart[1] - gameDate.getMinutes()); + //Returns the next date that a homwork will be due/lecture will occur + private function nextHomework(gameDate:Date):Date { + var nextIndex = (lectures.curLectureNum + 1) % lectures.weekdays.length; + var next = lectures.weekdays[nextIndex]; + var nextStart = lectures.times[nextIndex].end; - var nextDate = DateTools.delta(gameDate, delta); - if (Util.DayinRange(lectures.startDate, lectures.endDate, nextDate)) - return nextDate; - return null; - } + var delta:Float = next - gameDate.getDay(); + + if (delta < 0 || lectures.weekdays.length == 1) { + delta = 7 + delta; + } + delta = DateTools.days(delta) + DateTools.hours(nextStart[0] - gameDate.getHours()) + DateTools.minutes(nextStart[1] - gameDate.getMinutes()); + + var nextDate = DateTools.delta(gameDate, delta); + if (Util.DayinRange(lectures.startDate, lectures.endDate, nextDate)) + return nextDate; + return null; + } } diff --git a/Source/Calendar.hx b/Source/Calendar.hx index 3d431e2..2579672 100644 --- a/Source/Calendar.hx +++ b/Source/Calendar.hx @@ -7,18 +7,18 @@ import haxe.ds.HashMap; class Calendar extends Sprite { - private var cells:HashMap = new HashMap(); - private var weekdayHeight = 15; - private var today:Day; - - private var xOffset:Int; - private var yOffset:Int; - private var cellWidth:Int; - private var cellHeight:Int; - private var rows:Int; - private var endDate:Date; //first date not in calendar - - public function new(width, height, date:Date){ + private var cells:HashMap = new HashMap(); + private var weekdayHeight = 15; + private var today:Day; + + private var xOffset:Int; + private var yOffset:Int; + private var cellWidth:Int; + private var cellHeight:Int; + private var rows:Int; + private var endDate:Date; //first date not in calendar + + public function new(width, height, date:Date){ super(); today = Day.fromDate(date); //round down to nearest Sunday to get endDate because nothing in calendar yet @@ -33,9 +33,9 @@ class Calendar extends Sprite { makeGrid(); makeWeekdays(); cells.get(today).backgroundColor = 0xEE5D15; - } + } - private function makeRow (rowNum){ + private function makeRow (rowNum){ for (j in 0...7){ var cell:TextField = new TextField(); @@ -64,15 +64,15 @@ class Calendar extends Sprite { endDate = DateTools.delta(endDate, 24*3600*1000);//DateTools.days(1)); } - } + } - private function makeGrid(){ + private function makeGrid(){ for (i in 0...rows){ makeRow(i); } - } + } - private function advanceGrid(){ + private function advanceGrid(){ for (cell in cells){ if (cell.y <= yOffset){ removeChild(cell); @@ -81,9 +81,9 @@ class Calendar extends Sprite { } } makeRow(rows-1); - } + } - private function makeWeekdays() { + private function makeWeekdays() { var names:Array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; for (i in 0...7) { var weekday:TextField = new TextField(); @@ -93,9 +93,9 @@ class Calendar extends Sprite { weekday.x = xOffset + i*cellWidth; weekday.y = yOffset - 15; } - } + } - public function update(gameDate:Date) { + public function update(gameDate:Date) { //trace("hi"); var day = Day.fromDate(gameDate); //trace(today.month+" "+today.day); @@ -108,5 +108,5 @@ class Calendar extends Sprite { cells.get(today).backgroundColor = 0xFFFFFF; today=day; } - } + } } diff --git a/Source/Lecture.hx b/Source/Lecture.hx index 72d2642..4067904 100644 --- a/Source/Lecture.hx +++ b/Source/Lecture.hx @@ -1,54 +1,70 @@ package; typedef Lecture = { - var days:Array; - var start:SSDate; - var end:SSDate; - var homework:Array>; - var project:Int; - var exception:Array; - var title:String; + var days:Array; + var start:SSDate; + var end:SSDate; + var homework:Array>; + var project:Int; + var exception:Array; + var title:String; } typedef LectureDay = { - var weekday:Int; - var time:String; + var weekday:Int; + var time:String; } typedef SSDate = { - var day:Int; - var month:Int; - var year:Int; + var day:Int; + var month:Int; + var year:Int; } class LectureObject { - public var startDate:Date; - public var endDate:Date; - public var weekdays:Array; - public var times:Array; - public var homework:Array>; - public var title:String; - public var exceptions:Array; - public var curLectureNum:Int; - - public function new(lecture:Lecture) { - var start = Util.splitAndParseInt(lecture.days[0].time.split("-")[0], ":"); - - this.startDate = new Date(lecture.start.year, lecture.start.month, lecture.start.day, start[0], start[1], 0); - var delta = lecture.days[0].weekday - startDate.getDay(); - - startDate = DateTools.delta(this.startDate, DateTools.days(delta)); - - this.times = new Array(); - this.weekdays = new Array(); - for (i in lecture.days) { - times.push(i.time); - weekdays.push(i.weekday); - } - this.endDate = new Date(lecture.end.year, lecture.end.month, lecture.end.day, 0, 0, 0); - this.homework = lecture.homework; - this.title = lecture.title; - this.exceptions = lecture.exception; - this.curLectureNum = 0; - } + public var startDate:Date; + public var endDate:Date; + public var weekdays:Array; + public var times:Array