diff --git a/.gitattributes b/.gitattributes index dde9b4eb8..18aa82081 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ *.psd filter=lfs diff=lfs merge=lfs -text *.ogg filter=lfs diff=lfs merge=lfs -text *.tga filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text diff --git a/assets/books/userguide_ENG.aux b/assets/books/userguide_ENG.aux deleted file mode 100644 index 3e2b649a8..000000000 --- a/assets/books/userguide_ENG.aux +++ /dev/null @@ -1,36 +0,0 @@ -\relax -\providecommand\hyper@newdestlabel[2]{} -\providecommand*{\memsetcounter}[2]{} -\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} -\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined -\global\let\oldcontentsline\contentsline -\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} -\global\let\oldnewlabel\newlabel -\gdef\newlabel#1#2{\newlabelxx{#1}#2} -\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} -\AtEndDocument{\ifx\hyper@anchor\@undefined -\let\contentsline\oldcontentsline -\let\newlabel\oldnewlabel -\fi} -\fi} -\global\let\hyper@last\relax -\gdef\HyperFirstAtBeginDocument#1{#1} -\providecommand\HyField@AuxAddToFields[1]{} -\providecommand\HyField@AuxAddToCoFields[2]{} -\@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{4}{section.0.1}} -\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}Luggage preparation}{4}{subsection.0.1.1}} -\@writefile{toc}{\contentsline {section}{\numberline {2}Moving around}{5}{section.0.2}} -\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Your first toddling}{5}{subsection.0.2.1}} -\@writefile{toc}{\contentsline {subsubsection}{ISO/\penalty \exhyphenpenalty ANSI/\penalty \exhyphenpenalty JIS pedalboards}{5}{section*.1}} -\@writefile{toc}{\contentsline {subsubsection}{Joypads}{6}{section*.2}} -\@writefile{toc}{\contentsline {section}{\numberline {3}World}{6}{section.0.3}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Geograghy}{7}{subsection.0.3.1}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}Day and night}{7}{subsection.0.3.2}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.3}Biome}{8}{subsection.0.3.3}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.4}Vegetation}{8}{subsection.0.3.4}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.5}Races and their civilisations}{8}{subsection.0.3.5}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.6}Common animals}{8}{subsection.0.3.6}} -\@writefile{toc}{\contentsline {section}{\numberline {4}World creation}{8}{section.0.4}} -\@writefile{toc}{\contentsline {subsection}{\numberline {4.1}World Size}{9}{subsection.0.4.1}} -\memsetcounter{lastsheet}{9} -\memsetcounter{lastpage}{9} diff --git a/assets/books/userguide_ENG.out b/assets/books/userguide_ENG.out deleted file mode 100644 index 085a8d88a..000000000 --- a/assets/books/userguide_ENG.out +++ /dev/null @@ -1,13 +0,0 @@ -\BOOKMARK [1][-]{section.0.1}{\376\377\000I\000n\000t\000r\000o\000d\000u\000c\000t\000i\000o\000n}{}% 1 -\BOOKMARK [2][-]{subsection.0.1.1}{\376\377\000L\000u\000g\000g\000a\000g\000e\000\040\000p\000r\000e\000p\000a\000r\000a\000t\000i\000o\000n}{section.0.1}% 2 -\BOOKMARK [1][-]{section.0.2}{\376\377\000M\000o\000v\000i\000n\000g\000\040\000a\000r\000o\000u\000n\000d}{}% 3 -\BOOKMARK [2][-]{subsection.0.2.1}{\376\377\000Y\000o\000u\000r\000\040\000f\000i\000r\000s\000t\000\040\000t\000o\000d\000d\000l\000i\000n\000g}{section.0.2}% 4 -\BOOKMARK [1][-]{section.0.3}{\376\377\000W\000o\000r\000l\000d}{}% 5 -\BOOKMARK [2][-]{subsection.0.3.1}{\376\377\000G\000e\000o\000g\000r\000a\000g\000h\000y}{section.0.3}% 6 -\BOOKMARK [2][-]{subsection.0.3.2}{\376\377\000D\000a\000y\000\040\000a\000n\000d\000\040\000n\000i\000g\000h\000t}{section.0.3}% 7 -\BOOKMARK [2][-]{subsection.0.3.3}{\376\377\000B\000i\000o\000m\000e}{section.0.3}% 8 -\BOOKMARK [2][-]{subsection.0.3.4}{\376\377\000V\000e\000g\000e\000t\000a\000t\000i\000o\000n}{section.0.3}% 9 -\BOOKMARK [2][-]{subsection.0.3.5}{\376\377\000R\000a\000c\000e\000s\000\040\000a\000n\000d\000\040\000t\000h\000e\000i\000r\000\040\000c\000i\000v\000i\000l\000i\000s\000a\000t\000i\000o\000n\000s}{section.0.3}% 10 -\BOOKMARK [2][-]{subsection.0.3.6}{\376\377\000C\000o\000m\000m\000o\000n\000\040\000a\000n\000i\000m\000a\000l\000s}{section.0.3}% 11 -\BOOKMARK [1][-]{section.0.4}{\376\377\000W\000o\000r\000l\000d\000\040\000c\000r\000e\000a\000t\000i\000o\000n}{}% 12 -\BOOKMARK [2][-]{subsection.0.4.1}{\376\377\000W\000o\000r\000l\000d\000\040\000S\000i\000z\000e}{section.0.4}% 13 diff --git a/assets/books/userguide_ENG.pdf b/assets/books/userguide_ENG.pdf deleted file mode 100644 index 89b3464f6..000000000 Binary files a/assets/books/userguide_ENG.pdf and /dev/null differ diff --git a/assets/books/userguide_ENG.synctex.gz b/assets/books/userguide_ENG.synctex.gz deleted file mode 100644 index 4de82c6ea..000000000 Binary files a/assets/books/userguide_ENG.synctex.gz and /dev/null differ diff --git a/assets/books/userguide_ENG.toc b/assets/books/userguide_ENG.toc deleted file mode 100644 index ac89bafcb..000000000 --- a/assets/books/userguide_ENG.toc +++ /dev/null @@ -1,15 +0,0 @@ -\contentsline {section}{\numberline {1}Introduction}{4}{section.0.1} -\contentsline {subsection}{\numberline {1.1}Luggage preparation}{4}{subsection.0.1.1} -\contentsline {section}{\numberline {2}Moving around}{5}{section.0.2} -\contentsline {subsection}{\numberline {2.1}Your first toddling}{5}{subsection.0.2.1} -\contentsline {subsubsection}{ISO/\penalty \exhyphenpenalty ANSI/\penalty \exhyphenpenalty JIS pedalboards}{5}{section*.1} -\contentsline {subsubsection}{Joypads}{6}{section*.2} -\contentsline {section}{\numberline {3}World}{6}{section.0.3} -\contentsline {subsection}{\numberline {3.1}Geograghy}{7}{subsection.0.3.1} -\contentsline {subsection}{\numberline {3.2}Day and night}{7}{subsection.0.3.2} -\contentsline {subsection}{\numberline {3.3}Biome}{8}{subsection.0.3.3} -\contentsline {subsection}{\numberline {3.4}Vegetation}{8}{subsection.0.3.4} -\contentsline {subsection}{\numberline {3.5}Races and their civilisations}{8}{subsection.0.3.5} -\contentsline {subsection}{\numberline {3.6}Common animals}{8}{subsection.0.3.6} -\contentsline {section}{\numberline {4}World creation}{8}{section.0.4} -\contentsline {subsection}{\numberline {4.1}World Size}{9}{subsection.0.4.1} diff --git a/assets/books/userguide_NON.aux b/assets/books/userguide_NON.aux deleted file mode 100644 index 4d3fae00e..000000000 --- a/assets/books/userguide_NON.aux +++ /dev/null @@ -1,33 +0,0 @@ -\relax -\providecommand\hyper@newdestlabel[2]{} -\providecommand*{\memsetcounter}[2]{} -\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} -\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined -\global\let\oldcontentsline\contentsline -\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} -\global\let\oldnewlabel\newlabel -\gdef\newlabel#1#2{\newlabelxx{#1}#2} -\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} -\AtEndDocument{\ifx\hyper@anchor\@undefined -\let\contentsline\oldcontentsline -\let\newlabel\oldnewlabel -\fi} -\fi} -\global\let\hyper@last\relax -\gdef\HyperFirstAtBeginDocument#1{#1} -\providecommand\HyField@AuxAddToFields[1]{} -\providecommand\HyField@AuxAddToCoFields[2]{} -\@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{4}{section.0.1}} -\@writefile{toc}{\contentsline {subsection}{\numberline {1.1}Luggage preparation}{4}{subsection.0.1.1}} -\@writefile{toc}{\contentsline {section}{\numberline {2}Moving around}{5}{section.0.2}} -\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Your first toddling}{5}{subsection.0.2.1}} -\@writefile{toc}{\contentsline {section}{\numberline {3}World}{5}{section.0.3}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Geograghy}{6}{subsection.0.3.1}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}Day and night}{7}{subsection.0.3.2}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.3}Biome}{7}{subsection.0.3.3}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.4}Vegetation}{8}{subsection.0.3.4}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.5}Races and their civilisations}{8}{subsection.0.3.5}} -\@writefile{toc}{\contentsline {subsection}{\numberline {3.6}Common animals}{8}{subsection.0.3.6}} -\@writefile{toc}{\contentsline {section}{\numberline {4}World creation}{8}{section.0.4}} -\memsetcounter{lastsheet}{9} -\memsetcounter{lastpage}{9} diff --git a/assets/books/userguide_NON.out b/assets/books/userguide_NON.out deleted file mode 100644 index 0d5c71d38..000000000 --- a/assets/books/userguide_NON.out +++ /dev/null @@ -1,12 +0,0 @@ -\BOOKMARK [1][-]{section.0.1}{\376\377\000I\000n\000t\000r\000o\000d\000u\000c\000t\000i\000o\000n}{}% 1 -\BOOKMARK [2][-]{subsection.0.1.1}{\376\377\000L\000u\000g\000g\000a\000g\000e\000\040\000p\000r\000e\000p\000a\000r\000a\000t\000i\000o\000n}{section.0.1}% 2 -\BOOKMARK [1][-]{section.0.2}{\376\377\000M\000o\000v\000i\000n\000g\000\040\000a\000r\000o\000u\000n\000d}{}% 3 -\BOOKMARK [2][-]{subsection.0.2.1}{\376\377\000Y\000o\000u\000r\000\040\000f\000i\000r\000s\000t\000\040\000t\000o\000d\000d\000l\000i\000n\000g}{section.0.2}% 4 -\BOOKMARK [1][-]{section.0.3}{\376\377\000W\000o\000r\000l\000d}{}% 5 -\BOOKMARK [2][-]{subsection.0.3.1}{\376\377\000G\000e\000o\000g\000r\000a\000g\000h\000y}{section.0.3}% 6 -\BOOKMARK [2][-]{subsection.0.3.2}{\376\377\000D\000a\000y\000\040\000a\000n\000d\000\040\000n\000i\000g\000h\000t}{section.0.3}% 7 -\BOOKMARK [2][-]{subsection.0.3.3}{\376\377\000B\000i\000o\000m\000e}{section.0.3}% 8 -\BOOKMARK [2][-]{subsection.0.3.4}{\376\377\000V\000e\000g\000e\000t\000a\000t\000i\000o\000n}{section.0.3}% 9 -\BOOKMARK [2][-]{subsection.0.3.5}{\376\377\000R\000a\000c\000e\000s\000\040\000a\000n\000d\000\040\000t\000h\000e\000i\000r\000\040\000c\000i\000v\000i\000l\000i\000s\000a\000t\000i\000o\000n\000s}{section.0.3}% 10 -\BOOKMARK [2][-]{subsection.0.3.6}{\376\377\000C\000o\000m\000m\000o\000n\000\040\000a\000n\000i\000m\000a\000l\000s}{section.0.3}% 11 -\BOOKMARK [1][-]{section.0.4}{\376\377\000W\000o\000r\000l\000d\000\040\000c\000r\000e\000a\000t\000i\000o\000n}{}% 12 diff --git a/assets/books/userguide_NON.pdf b/assets/books/userguide_NON.pdf deleted file mode 100644 index 2f822ab51..000000000 Binary files a/assets/books/userguide_NON.pdf and /dev/null differ diff --git a/assets/books/userguide_NON.synctex.gz b/assets/books/userguide_NON.synctex.gz deleted file mode 100644 index 3ca99691b..000000000 Binary files a/assets/books/userguide_NON.synctex.gz and /dev/null differ diff --git a/assets/books/userguide_NON.tex b/assets/books/userguide_NON.tex deleted file mode 100644 index d78484522..000000000 --- a/assets/books/userguide_NON.tex +++ /dev/null @@ -1,110 +0,0 @@ -\documentclass[stock,9pt,nohan]{oblivoir} - -\usepackage{fapapersize} -\usefapapersize{3in,4.5in,.333in,*,.333in,.333in} -\usepackage{gensymb} -\usepackage{allrunes} -\usepackage[T1]{fontenc} - -\linespread{1.25} -\frenchspacing - -\usepackage[verbose=true]{microtype} - -\renewcommand{\contentsname}{\arnfamily efnisifirlit} - -\newcommand{\gamever}{\arnfamily alfa:f} - -\newcommand{\Terrarumemph}{\arnfamily +iArþin+} - -\newcommand{\boktitle}{\arnfamily ferþahantbukin:furiR \\ \Terrarumemph himR \vskip1ex \small nurAna:utkafa \normalsize} - -\newcommand{\bokauthor}{\arnfamily \small fra\Terrarumemph hAfuntum} - -\newcommand{\bokdate}{\arnfamily\small basa:uiþ:\gamever} - -\title{\boktitle} -\author{\bokauthor} -\date{\bokdate} - -\epigraphposition{center} -\setlength{\epigraphrule}{0pt} -\setlength{\epigraphwidth}{2in} -\setlength{\beforeepigraphskip}{72pt} - -\begin{document} - -\maketitle - -\newpage - -\epigraph{ -Uilkumin! You are most likely an explorer, or a brave and courageous traveller who seeks uncharted planet in the universe, or an aspiring ruler-to-be who want rule your own world. We hope this little book to be an useful guide for whatever ambitious work you are up to. -}{Writers} - -\tableofcontents* - -\newpage - -\newpage - -\section{Introduction} -\emph{Terrarum} is a rogue-like world which things are happening on real-time basis as in real-time role-playing games. - - \subsection{Luggage preparation} - Trip to \emph{Terrarum} can be achieved with any proper wagon, which should be equipped with: - \begin{itemize} - \item 64-bit wagon engine - \item \emph{Java Roving Environs 8} or higher - \item A wagon engine with cylinder size of 2 GB, 4 GB or more is recommended - \item Free luggage space of 4 GB or more - \end{itemize} - -\section{Moving around} -The control is omnidirectional. In other words, \emph{not} cell-based. - - \subsection{Your first toddling} - Your default moving around uses ESDF (qwerty)\slash FRST (colemak)\slash .OEW (dvorak) pedals for default `WASD', in order for you to provide more modifier pedals that are pressed with your little finger and more comfort to pedalboards with \emph{Topre} actuators.\footnote{Writers of this book recommend you to use pedalboard with \emph{Cherry MX Red} actuators.} - -\section{World} -The world is composed with \emph{three-dimensional} blocks, which is the feature you should keep in mind during your trip. Each block is a metre-size and a metre-high, so an average-height man should occupy two tiles vertically, thus he is two-tile-high in the world. - -Cliffs are treated as a stair, and you---as well as any living things in the world---can climb the tile as you would use a stair. Climbable cliff height is calculated as $$ floor( \frac{height_{you}}{height_{cliff}} ) $$ - -i.e. The man mentioned above can climb one-tile-high cliff as a stair. - - \subsection{Geograghy} - The world---the continent you play on---features mountains, valleys, rivers, lakes, ocean, caves, etc. - - There are several continents on the planet, which are created by you. While there are multiple continents, however, your wagon cannot travel interplanetary. - - Each time you create a continent, unless you specified a \emph{seed}\footnote{Refer to Section 4.}, will never be the same. - - \subsection{Day and night} - A day in \emph{Terrarum} world---the planet---is 72 000 seconds. A second in Earth would be equivalent to 60 (depends on the operational speed of your wagon) planetary seconds, which consists a planetary minute. - - \subsection{Biome} - Average temperature in meadows\slash forests\slash mountains are kept to pleasant 298 K\slash 25 \degree{}C\slash 77 \degree{}F. However, you might want to re-think before setting your feet on the snowy area, unless you are prepared well. While the Snow Queen % ---one of the devteam -will not hinder any access to her territory, in the same time she will not be welcoming. - - \subsection{Vegetation} - - - \subsection{Races and their civilisations} - - - \subsection{Common animals} - - -\section{World creation} - You can specify some parameters when you create a continent. Controllable parameters are: - \begin{itemize} - \item World size (affects distance between tribes) - \item Ore amount (affects civilisation) - \item Vegetation (more trees means more building materials) - \item Seed (each randomly-created continent has its own \emph{seed} for landform. Leave it blank to randomise) - \end{itemize} - - You can name your continent while in creation, so try to come up with a good name! - -\end{document} \ No newline at end of file diff --git a/assets/books/userguide_NON.toc b/assets/books/userguide_NON.toc deleted file mode 100644 index eafafaca8..000000000 --- a/assets/books/userguide_NON.toc +++ /dev/null @@ -1,12 +0,0 @@ -\contentsline {section}{\numberline {1}Introduction}{4}{section.0.1} -\contentsline {subsection}{\numberline {1.1}Luggage preparation}{4}{subsection.0.1.1} -\contentsline {section}{\numberline {2}Moving around}{5}{section.0.2} -\contentsline {subsection}{\numberline {2.1}Your first toddling}{5}{subsection.0.2.1} -\contentsline {section}{\numberline {3}World}{5}{section.0.3} -\contentsline {subsection}{\numberline {3.1}Geograghy}{6}{subsection.0.3.1} -\contentsline {subsection}{\numberline {3.2}Day and night}{7}{subsection.0.3.2} -\contentsline {subsection}{\numberline {3.3}Biome}{7}{subsection.0.3.3} -\contentsline {subsection}{\numberline {3.4}Vegetation}{8}{subsection.0.3.4} -\contentsline {subsection}{\numberline {3.5}Races and their civilisations}{8}{subsection.0.3.5} -\contentsline {subsection}{\numberline {3.6}Common animals}{8}{subsection.0.3.6} -\contentsline {section}{\numberline {4}World creation}{8}{section.0.4} diff --git a/assets/modules/basegame/tiles/terrain.tga.gz b/assets/modules/basegame/tiles/terrain.tga.gz new file mode 100644 index 000000000..4d4754267 --- /dev/null +++ b/assets/modules/basegame/tiles/terrain.tga.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f82613049541ade37c2996b55d3034b0df07f0b6e938b5f9b804e2b7d07059c8 +size 3016276 diff --git a/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt b/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt index e129cefa3..cb6762226 100644 --- a/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt +++ b/src/net/torvald/terrarum/mapdrawer/TilesDrawer.kt @@ -8,6 +8,7 @@ import com.jme3.math.FastMath import net.torvald.terrarum.* import net.torvald.terrarum.concurrent.ThreadParallel import net.torvald.terrarum.gameactors.roundInt +import net.torvald.terrarum.gameworld.toUint import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE import net.torvald.terrarum.mapdrawer.LightmapRenderer.normaliseToColour import net.torvald.terrarum.mapdrawer.MapCamera.x @@ -17,7 +18,12 @@ import net.torvald.terrarum.mapdrawer.MapCamera.width import net.torvald.terrarum.realestate.LandUtil import org.lwjgl.opengl.GL11 import org.newdawn.slick.* +import org.newdawn.slick.opengl.* +import java.io.FileInputStream +import java.nio.ByteBuffer import java.util.* +import java.util.zip.GZIPInputStream +import java.util.zip.InflaterInputStream /** * Created by minjaesong on 16-01-19. @@ -27,10 +33,41 @@ object TilesDrawer { private val TILE_SIZE = FeaturesDrawer.TILE_SIZE private val TILE_SIZEF = FeaturesDrawer.TILE_SIZE.toFloat() - val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE) + //val tilesTerrain = SpriteSheet(ModMgr.getPath("basegame", "tiles/terrain.tga"), TILE_SIZE, TILE_SIZE) // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here. val tilesWire = SpriteSheet(ModMgr.getPath("basegame", "tiles/wire.tga"), TILE_SIZE, TILE_SIZE) + val tilesTerrain: SpriteSheet + + init { + // read DEFLATEd terrain.tar + val tgaLoader = TGAImageData() + val terrainImageData = tgaLoader.loadImage( + GZIPInputStream( + FileInputStream(ModMgr.getFile("basegame", "tiles/terrain.tga.gz")), + 8192 + ), false, null) + terrainImageData.rewind() + /*val terrainTex = InternalTextureLoader.get().getTexture(object : ImageData { + override fun getHeight(): Int = tgaLoader.height + override fun getTexWidth(): Int = tgaLoader.texWidth + override fun getDepth(): Int = tgaLoader.depth + override fun getImageBufferData(): ByteBuffer = terrainImageData + override fun getWidth(): Int = tgaLoader.width + override fun getTexHeight(): Int = tgaLoader.texHeight + }, Image.FILTER_NEAREST)*/ + + //// method 1 + //val terrainImage = Image(terrainTex) + //tilesTerrain = SpriteSheet(terrainImage, TILE_SIZE, TILE_SIZE) + + //// method 2 + val terrainImgBuffer = ImageBuffer(tgaLoader.width, tgaLoader.height) + terrainImageData.get(terrainImgBuffer.rgba) + tilesTerrain = SpriteSheet(terrainImgBuffer.image, TILE_SIZE, TILE_SIZE) + } + + val breakAnimSteps = 10 val WALL = GameWorld.WALL diff --git a/src/net/torvald/terrarum/virtualcomputer/tvd/VDUtil.kt b/src/net/torvald/terrarum/virtualcomputer/tvd/VDUtil.kt index 1f242d19b..94c8f777b 100644 --- a/src/net/torvald/terrarum/virtualcomputer/tvd/VDUtil.kt +++ b/src/net/torvald/terrarum/virtualcomputer/tvd/VDUtil.kt @@ -468,15 +468,19 @@ object VDUtil { } /** * Add subdirectory to the specified directory. + * + * @return EntryID of newly created directory */ - fun addDir(disk: VirtualDisk, parentPath: VDPath, name: ByteArray) { + fun addDir(disk: VirtualDisk, parentPath: VDPath, name: ByteArray): EntryID { val parentID = getFile(disk, parentPath)!!.entryID return addDir(disk, parentID, name) } /** * Add file to the specified directory. + * + * @return EntryID of newly created directory */ - fun addDir(disk: VirtualDisk, directoryID: EntryID, name: ByteArray) { + fun addDir(disk: VirtualDisk, parentDir: EntryID, name: ByteArray): EntryID { disk.checkReadOnly() disk.checkCapacity(EntryDirectory.NEW_ENTRY_SIZE) @@ -484,16 +488,18 @@ object VDUtil { try { // add record to the directory - getAsDirectory(disk, directoryID).add(newID) + getAsDirectory(disk, parentDir).add(newID) // add entry on the disk disk.entries[newID] = DiskEntry( newID, - directoryID, + parentDir, name, currentUnixtime, currentUnixtime, EntryDirectory() ) + + return newID } catch (e: KotlinNullPointerException) { throw FileNotFoundException("No such directory") @@ -519,6 +525,8 @@ object VDUtil { } } + + val entry = disk.entries[directoryID] if (entry != null && entry.contents is EntryDirectory) { entry.contents.forEach { @@ -543,20 +551,49 @@ object VDUtil { /** * Imports external file and returns corresponding DiskEntry. */ - fun importFile(file: File, id: EntryID): DiskEntry { + fun importFile(file: File, newID: EntryID, charset: Charset): DiskEntry { if (file.isDirectory) { throw IOException("The file is a directory") } return DiskEntry( - entryID = id, + entryID = newID, parentEntryID = 0, // placeholder - filename = file.name.toByteArray(), + filename = file.name.toEntryName(DiskEntry.NAME_LENGTH, charset), creationDate = currentUnixtime, modificationDate = currentUnixtime, contents = EntryFile(file.readBytes64()) ) } + + fun importDirRecurse(disk: VirtualDisk, dir: File, path: VDPath, charset: Charset) = + importDirRecurse(disk, dir, getFile(disk, path)!!.entryID, charset) + + fun importDirRecurse(disk: VirtualDisk, dir: File, superNode: EntryID, charset: Charset, newName: String? = null) { + fun recurse1(file: File, node: EntryID) { + // return conditions + if (!file.isDirectory) { + // if not a directory, add to node + val importedFile = importFile(file, disk.generateUniqueID(), charset) + addFile(disk, node, importedFile) + return + } + // recurse + else { + // mkdir + val newDir = addDir(disk, node, file.name.toEntryName(DiskEntry.NAME_LENGTH, charset)) + // for entries in this fileDirectory... + file.listFiles().forEach { recurse1(it, newDir) } + } + } + + + // mkdir to superNode + val newDir = addDir(disk, superNode, (newName ?: dir.name).toEntryName(DiskEntry.NAME_LENGTH, charset)) + // for entries in this fileDirectory... + dir.listFiles().forEach { recurse1(it, newDir) } + } + /** * Export file on the virtual disk into real disk. */ @@ -565,6 +602,33 @@ object VDUtil { outfile.writeBytes64(entryFile.bytes) } + fun exportDirRecurse(disk: VirtualDisk, parentDir: EntryID, outfile: File, charset: Charset) { + fun recurse1(file: DiskEntry, dir: File) { + // return conditions + if (file.contents is EntryFile) { + // if not a directory, write as file + val newFile = File(dir, file.getFilenameString(charset)) + newFile.writeBytes64(file.contents.bytes) + return + } + // recurse + else if (file.contents is EntryDirectory) { + // mkdir + val newDir = File(dir, file.getFilenameString(charset)) + newDir.mkdir() + // for entries in this fileDirectory... + file.contents.forEach { recurse1(disk.entries[it]!!, newDir) } + } + } + + + // mkdir to superNode + val newDir = File(outfile, disk.entries[parentDir]!!.getFilenameString(charset)) + newDir.mkdir() + // for entries in this fileDirectory... + getDirectoryEntries(disk, parentDir).forEach { recurse1(it, newDir) } + } + /** * Check for name collision in specified directory. */ @@ -765,7 +829,8 @@ object VDUtil { } } catch (e: Exception) { - throw InternalError("Aw, snap! Here's what it says:\n$e") + e.printStackTrace() + throw InternalError("Aw, snap!") } } @@ -779,7 +844,8 @@ object VDUtil { } } catch (e: Exception) { - throw InternalError("Aw, snap! Here's what it says:\n$e") + e.printStackTrace() + throw InternalError("Aw, snap!") } } } diff --git a/src/net/torvald/terrarum/virtualcomputer/tvd/VirtualDisk.kt b/src/net/torvald/terrarum/virtualcomputer/tvd/VirtualDisk.kt index 0fa599e70..e1c20d7d2 100644 --- a/src/net/torvald/terrarum/virtualcomputer/tvd/VirtualDisk.kt +++ b/src/net/torvald/terrarum/virtualcomputer/tvd/VirtualDisk.kt @@ -198,7 +198,7 @@ class EntryDirectory(private val entries: ArrayList = ArrayList