Created
February 8, 2018 21:09
-
-
Save TheBizzle/314fc8ddc87ff8db93cc474e593fce4f to your computer and use it in GitHub Desktop.
Fixups to my `export-world` PR, between its first and second versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/compiler/shared/src/main/scala/Compiler.scala b/compiler/shared/src/main/scala/Compiler.scala | |
| index 0ee680e..945087f 100644 | |
| --- a/compiler/shared/src/main/scala/Compiler.scala | |
| +++ b/compiler/shared/src/main/scala/Compiler.scala | |
| @@ -70,8 +70,7 @@ object Compiler extends CompilerLike { | |
| val interfaceInit = JsStatement("interfaceInit", interfaceGlobalJs, Seq("world", "procedures", "modelConfig")) | |
| TortoiseLoader.integrateSymbols(init ++ plotConfig ++ procedures | |
| :+ outputConfig :+ dialogConfig | |
| - :+ fileReaderConfig :+ worldConfig | |
| - :+ importExportConfig | |
| + :+ worldConfig :+ importExportConfig | |
| :+ interfaceInit) | |
| } | |
| @@ -184,21 +183,6 @@ object Compiler extends CompilerLike { | |
| "notify" -> jsFunction(Seq("str")), | |
| "yesOrNo" -> jsFunction(Seq("str"), "return true;"))) | |
| - private def fileReaderConfig: JsStatement = | |
| - genConfig("fileReader", | |
| - Map("read" -> jsFunction( | |
| - Seq("filepath"), | |
| - """var Paths = Java.type('java.nio.file.Paths'); | |
| - |var Files = Java.type('java.nio.file.Files'); | |
| - |var UTF8 = Java.type('java.nio.charset.StandardCharsets').UTF_8; | |
| - |var lines = Files.readAllLines(Paths.get(filepath), UTF8); | |
| - |var out = []; | |
| - |lines.forEach(function(line) { out.push(line); }); | |
| - |return out.join("\n");""".stripMargin | |
| - ) | |
| - ) | |
| - ) | |
| - | |
| private def worldConfig: JsStatement = | |
| genConfig("world", Map("resizeWorld" -> jsFunction(Seq("agent")))) | |
| @@ -207,14 +191,24 @@ object Compiler extends CompilerLike { | |
| , Map( "exportOutput" -> jsFunction(Seq("filename")) | |
| , "exportView" -> jsFunction(Seq("filename")) | |
| , "exportFile" -> jsFunction(Seq("str"), | |
| - """return function(filepath) { | |
| - |var Paths = Java.type('java.nio.file.Paths'); | |
| - |var Files = Java.type('java.nio.file.Files'); | |
| - |var UTF8 = Java.type('java.nio.charset.StandardCharsets').UTF_8; | |
| - |Files.createDirectories(Paths.get(filepath).getParent()); | |
| - |var path = Files.write(Paths.get(filepath), str.getBytes()); | |
| - |}""".stripMargin) | |
| - , "importWorld" -> jsFunction(Seq("file")) | |
| + """ return function(filepath) { | |
| + | var Paths = Java.type('java.nio.file.Paths'); | |
| + | var Files = Java.type('java.nio.file.Files'); | |
| + | var UTF8 = Java.type('java.nio.charset.StandardCharsets').UTF_8; | |
| + | Files.createDirectories(Paths.get(filepath).getParent()); | |
| + | var path = Files.write(Paths.get(filepath), str.getBytes()); | |
| + | }""".stripMargin) | |
| + , "importWorld" -> jsFunction(Seq("trueImportWorld"), | |
| + """ return function(filename) { | |
| + | var Paths = Java.type('java.nio.file.Paths'); | |
| + | var Files = Java.type('java.nio.file.Files'); | |
| + | var UTF8 = Java.type('java.nio.charset.StandardCharsets').UTF_8; | |
| + | var lines = Files.readAllLines(Paths.get(filename), UTF8); | |
| + | var out = []; | |
| + | lines.forEach(function(line) { out.push(line); }); | |
| + | var fileText = out.join("\n"); | |
| + | trueImportWorld(fileText); | |
| + | }""".stripMargin) | |
| ) | |
| ) | |
| diff --git a/engine/src/main/coffee/engine/core/world/export.coffee b/engine/src/main/coffee/engine/core/world/export.coffee | |
| index 6b6d3db..4316003 100644 | |
| --- a/engine/src/main/coffee/engine/core/world/export.coffee | |
| +++ b/engine/src/main/coffee/engine/core/world/export.coffee | |
| @@ -121,7 +121,7 @@ exportWildcardVar = (agent) -> (varName) -> | |
| # () => Object[Any] | |
| exportMetadata = -> | |
| - # TODO: IMPLEMENT FILENAME | |
| + # TODO: Get filename from metadata from compiler, once NetLogo/NetLogo#1547 has been merged --JAB (2/8/18) | |
| new Metadata(version, '[IMPLEMENT .NLOGO]', new Date()) | |
| # [T, U <: ExportedAgent[T]] @ (Class[U], Array[(String, (Any) => Any)]) => (T) => U | |
| diff --git a/engine/src/main/coffee/engine/plot/plot.coffee b/engine/src/main/coffee/engine/plot/plot.coffee | |
| index b54f41a..01d4994 100644 | |
| --- a/engine/src/main/coffee/engine/plot/plot.coffee | |
| +++ b/engine/src/main/coffee/engine/plot/plot.coffee | |
| @@ -91,13 +91,11 @@ module.exports = class Plot | |
| pipeline(@_getPenMaybeByName.bind(this), isSomething)(name) | |
| # (ExportedPlot) => Unit | |
| - importState: ({ currentPenNameOrNull, isAutoplotting, isLegendOpen, pens, xMax, xMin, yMax, yMin }) -> | |
| + importState: ({ currentPenNameOrNull, @isAutoplotting, isLegendOpen: @isLegendEnabled, pens | |
| + , @xMax, @xMin, @yMax, @yMin }) -> | |
| pens.forEach((pen) => @_createAndReturnTemporaryPen(pen.name).importState(pen)) | |
| - @isAutoplotting = isAutoplotting | |
| - @isLegendEnabled = isLegendOpen | |
| @_currentPenMaybe = @_getPenMaybeByName(currentPenNameOrNull) | |
| - @setXRange(xMin, xMax) | |
| - @setYRange(yMin, yMax) | |
| + @_resize() | |
| return | |
| # () => Unit | |
| diff --git a/engine/src/main/coffee/engine/prim/importexportprims.coffee b/engine/src/main/coffee/engine/prim/importexportprims.coffee | |
| index e56d82b..815edc8 100644 | |
| --- a/engine/src/main/coffee/engine/prim/importexportprims.coffee | |
| +++ b/engine/src/main/coffee/engine/prim/importexportprims.coffee | |
| @@ -8,14 +8,15 @@ module.exports.Config = | |
| , @exportPlot = (-> ->) # (String) => (String) => Unit | |
| , @exportView = (->) # (String) => Unit | |
| , @exportWorld = (-> ->) # (String) => (() => String) => Unit | |
| - , @importWorld = (->) # (String) => Unit | |
| + , @importWorld = (-> ->) # (String) => ((String) => Unit) => Unit | |
| ) -> | |
| module.exports.Prims = | |
| class ImportExportPrims | |
| # (ImportExportConfig, () => String, () => String, (String) => String, (String) => Unit) => ImportExportPrims | |
| - constructor: ({ exportAllPlots, exportFile, @exportOutput, exportPlot, @exportView, exportWorld, @importWorld } | |
| + constructor: ({ exportAllPlots, exportFile, @exportOutput, exportPlot, @exportView, exportWorld, importWorld } | |
| , trueExportWorld, trueExportAllPlots, trueExportPlot, trueImportWorld) -> | |
| @exportWorld = (filename) -> exportFile(trueExportWorld() )(filename) | |
| @exportAllPlots = (filename) -> exportFile(trueExportAllPlots())(filename) | |
| @exportPlot = (plot, filename) -> exportFile(trueExportPlot(plot))(filename) | |
| + @importWorld = (filename) -> importWorld(trueImportWorld )(filename) | |
| diff --git a/engine/src/main/coffee/engine/workspace.coffee b/engine/src/main/coffee/engine/workspace.coffee | |
| index 495fb22..59e1910 100644 | |
| --- a/engine/src/main/coffee/engine/workspace.coffee | |
| +++ b/engine/src/main/coffee/engine/workspace.coffee | |
| @@ -4,10 +4,6 @@ class WorldConfig | |
| # (() => Unit) => WorldConfig | |
| constructor: (@resizeWorld = (->)) -> | |
| -class FileReaderConfig | |
| - # ((String, (String) => Unit) => String) => FileReaderConfig | |
| - constructor: (@read = (->)) -> | |
| - | |
| BreedManager = require('./core/breedmanager') | |
| Dump = require('./dump') | |
| EvalPrims = require('./prim/evalprims') | |
| @@ -48,7 +44,6 @@ module.exports = | |
| worldArgs = arguments # If you want `Workspace` to take more parameters--parameters not related to `World`--just keep returning new functions | |
| dialogConfig = modelConfig?.dialog ? new UserDialogConfig | |
| - fileReader = modelConfig?.fileReader ? new FileReaderConfig | |
| importExportConfig = modelConfig?.importExport ? new ImportExportConfig | |
| mouseConfig = modelConfig?.mouse ? new MouseConfig | |
| outputConfig = modelConfig?.output ? new OutputConfig | |
| @@ -97,14 +92,11 @@ module.exports = | |
| worldState = csvToWorldState(singularToPlural, pluralToSingular)(csvText) | |
| world.importState(worldState) | |
| - importWorld = (file) -> | |
| - importWorldFromCSV(fileReader.read(file)) | |
| - | |
| importExportPrims = new ImportExportPrims( importExportConfig | |
| , (-> world.exportCSV()) | |
| , (-> world.exportAllPlotsCSV()) | |
| , ((plot) -> world.exportPlotCSV(plot)) | |
| - , importWorld | |
| + , importWorldFromCSV | |
| ) | |
| { | |
| @@ -112,7 +104,6 @@ module.exports = | |
| breedManager | |
| dump | |
| importExportPrims | |
| - importWorldFromCSV | |
| layoutManager | |
| linkPrims | |
| listPrims | |
| diff --git a/netlogo-web/src/test/scala/TortoiseFinder.scala b/netlogo-web/src/test/scala/TortoiseFinder.scala | |
| index 4243ceb..794f74d 100644 | |
| --- a/netlogo-web/src/test/scala/TortoiseFinder.scala | |
| +++ b/netlogo-web/src/test/scala/TortoiseFinder.scala | |
| @@ -79,14 +79,13 @@ class TestCommands extends CommandTests with TortoiseFinder { | |
| override val freebies = Map[String, String]( | |
| // requires handling of non-local exit (see in JVM NetLogo: `NonLocalExit`, `_report`, `_foreach`, `_run`) | |
| "Every::EveryLosesScope" -> "NetLogo Web does not support distinct jobs" | |
| - ) ++ incErrorDetectCommands ++ evalNotSupportedCommands ++ importWorldCommands ++ lameCommands | |
| + ) ++ incErrorDetectCommands ++ evalNotSupportedCommands ++ lameCommands | |
| } | |
| private[tortoise] object Freebies { | |
| def incErrorDetectCommands = asFreebieMap(incErrorDetectCommandNames, incErrorDetectStr) | |
| def evalNotSupportedCommands = asFreebieMap(evalNotSupportedCommandNames, evalNotSupportedStr) | |
| - def importWorldCommands = asFreebieMap(importWorldCommandNames, importWorldStr) | |
| def lameCommands = asFreebieMap(lameCommandNames, lameCommandStr) | |
| def incErrorDetectReporters = asFreebieMap(incErrorDetectReporterNames, incErrorDetectStr) | |
| @@ -205,17 +204,6 @@ private[tortoise] object Freebies { | |
| "Run::run-evaluate-string-input-only-once" | |
| ) | |
| - private val importWorldStr = "Tortoise does not know how to import from a filepath (see: JavaScript)" | |
| - private val importWorldCommandNames = Seq( | |
| - // Uncomment these if `__mkdir` is ever implemented. --JAB (2/7/18) | |
| - // "ImportWorld::AllTurtlesExport", | |
| - // "ImportWorld::AllBreedsExport", | |
| - // "ImportWorld::AllLinkBreedsExport", | |
| - // "ImportWorld::ImportExportBreedOrder", | |
| - // "ImportWorld::ImportExportLinkBreedOrder", | |
| - "ImportWorld::RoundTripWithUTF8Chars" | |
| - ) | |
| - | |
| private val lameCommandStr = "This test is LAME!" | |
| private val lameCommandNames = Seq( | |
| "UserPrimitives::UserReporters_Headless" | |
| diff --git a/netlogo-web/src/test/scala/dock/DockingFixture.scala b/netlogo-web/src/test/scala/dock/DockingFixture.scala | |
| index 5e58528..834891f 100644 | |
| --- a/netlogo-web/src/test/scala/dock/DockingFixture.scala | |
| +++ b/netlogo-web/src/test/scala/dock/DockingFixture.scala | |
| @@ -62,7 +62,6 @@ class DockingFixture(name: String, nashorn: Nashorn) extends Fixture(name) { | |
| var opened = false | |
| val netLogoCode = new StringBuilder | |
| - | |
| val implementedOptimizations = { | |
| val commands = (OCommand, Seq("CroFast", "CrtFast", "Fd1", "FdLessThan1", "HatchFast", "SproutFast")) | |
| val reporters = (OReporter, | |
| diff --git a/netlogo-web/src/test/scala/dock/TestModels.scala b/netlogo-web/src/test/scala/dock/TestModels.scala | |
| index 0b7dead..9759cc4 100644 | |
| --- a/netlogo-web/src/test/scala/dock/TestModels.scala | |
| +++ b/netlogo-web/src/test/scala/dock/TestModels.scala | |
| @@ -49,10 +49,7 @@ class TestModels extends DockingSuite { | |
| def testReimport(inPlatform: Platform, fixture: DockingFixture): Unit = { | |
| val outBase = if (inPlatform == Web) FromWeb else FromDesktop | |
| - val nashorn = fixture.getNashorn | |
| - nashorn.engineScope.put("importWorldText", readFile(csv(inPlatform, Original))) | |
| - nashorn.eval("workspace.importWorldFromCSV(importWorldText);") | |
| fixture.testCommand(s"""import-world "${csv(inPlatform, Original)}" """) | |
| fixture.testCommand(s"""export-world (ifelse-value netlogo-web? [ "${csv(Web, outBase)}"] [ "${csv(Desktop, outBase)}" ])""") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment