diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..30c1beee --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Build results +[Dd]ebug/ +[Rr]elease/ + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + +# Mac crap +.DS_Store + +Makefile.Debug +Makefile.Release + +*.pdb +*.user diff --git a/.hgignore b/.hgignore deleted file mode 100644 index 8dcd9e48..00000000 --- a/.hgignore +++ /dev/null @@ -1,4 +0,0 @@ -syntax: glob -*.o -*.a -minutor diff --git a/.hgtags b/.hgtags deleted file mode 100644 index f7cec319..00000000 --- a/.hgtags +++ /dev/null @@ -1,8 +0,0 @@ -0000000000000000000000000000000000000000 0.2.3 -9a0e075066f1fdc72191a5e517c0457c98d9a582 0.3 -ce597867eb2da0c6b9ca76f01450742a349d2e88 1.1 -310f5c23f02e5e36eb910eac85275e4b6f007312 1.5 -310f5c23f02e5e36eb910eac85275e4b6f007312 1.5 -0000000000000000000000000000000000000000 1.5 -0000000000000000000000000000000000000000 1.5 -e184d35990a81b6fb2bf22f5ec83e12404f3292f 1.5 diff --git a/Makefile b/Makefile deleted file mode 100644 index 3988a3a9..00000000 --- a/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -GTK_INC=`pkg-config --cflags gtk+-2.0` -GTK_LIB=`pkg-config --libs gtk+-2.0` - -BIN=$(DESTDIR)/usr/bin -DESKTOP=$(DESTDIR)/usr/share/applications -PIXMAP=$(DESTDIR)/usr/share/pixmaps -OBJS=minutor.o mapviewer.o colorschemes.o -CC=gcc -MAKE=make -#CFLAGS=-Wall -std=c99 -O2 -CFLAGS=-Wall -std=c99 -g -INCLUDE=$(GTK_INC) -LIBS=$(GTK_LIB) - -EXEC=minutor - -all: $(EXEC) - -$(EXEC): $(OBJS) maplib - $(CC) -Wl,--as-needed -o $(EXEC) $(OBJS) $(LIBS) MinutorMap/MinutorMap.a - -install: $(EXEC) - install -d $(BIN) $(DESKTOP) $(PIXMAP) - install -s $(EXEC) $(BIN) - install minutor.desktop $(DESKTOP) - install minutor.png $(PIXMAP) - install minutor.xpm $(PIXMAP) - -maplib: - cd MinutorMap && $(MAKE) - -%.o: %.c - $(CC) -c $(CFLAGS) -o $@ $< $(INCLUDE) - -clean: cleanmaplib - rm -f $(EXEC) $(OBJS) -cleanmaplib: - cd MinutorMap && $(MAKE) clean \ No newline at end of file diff --git a/MinutorMap/Makefile b/MinutorMap/Makefile deleted file mode 100644 index 4d4086ed..00000000 --- a/MinutorMap/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -OBJS=MinutorMap.o cache.o nbt.o region.o -CC=gcc -AR=ar -#CFLAGS=-Wall -std=c99 -O2 -CFLAGS=-Wall -std=c99 -g - -LIB=MinutorMap.a - -$(LIB): $(OBJS) - $(AR) -cr $(LIB) $(OBJS) -%.o: %.c - $(CC) -c $(CFLAGS) -o $@ $< $(INCLUDE) -clean: - rm -f $(LIB) $(OBJS) diff --git a/MinutorMap/MinutorMap.c b/MinutorMap/MinutorMap.c deleted file mode 100644 index e8ead643..00000000 --- a/MinutorMap/MinutorMap.c +++ /dev/null @@ -1,606 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun - Parts Copyright (c) 2010, Ryan Hitchman -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -// MinutorMap.cpp : Defines the exported functions for the DLL application. -// - -#include "stdafx.h" -#include "blockInfo.h" -#include - -static unsigned char* draw(const char *world,int bx,int bz,int y,int opts, - ProgressCallback callback,float percent); -static void blit(unsigned char *block,unsigned char *bits,int px,int py, - double zoom,int w,int h); -static Block *LoadBlock(char *directory,int bx,int bz); -static void initColors(); - -static int colorsInited=0; -static unsigned int blockColors[256*16]; -static unsigned char blank_tile[16*16*4]; - -static unsigned short colormap=0; -static long long mapSeed; - -#define clamp(v,a,b) ((v)a?(v):a):b) - - - - - - - -static long long randomSeed; -static void javaRandomSetSeed(long long seed){ - randomSeed = (seed ^ 0x5DEECE66DL) & ((1LL << 48) - 1); -} - -static long long javaRandomNext(int bits) { - long long r = randomSeed; - r = (r * 0x5DEECE66DL + 0xBL) & ((1LL << 48) - 1); - return (long long)(r >> (48 - bits)); -} -static int javaRandomNextInt(int n) { - long long bits,val; - if ((n & -n) == n) // i.e., n is a power of 2 - return (int)((n * (long long)javaRandomNext(31)) >> 31); - do { - bits = javaRandomNext(31); - val = bits % n; - } while(bits - val + (n-1) < 0); - return (int)val; -} - -static long long getChunkSeed(int xPosition, int zPosition){ - return (mapSeed + (long long) (xPosition * xPosition * 0x4c1906) + (long long) (xPosition * 0x5ac0db) + - (long long) (zPosition * zPosition) * 0x4307a7L + (long long) (zPosition * 0x5f24f)) ^ 0x3ad8025f; -} - -static int isSlimeChunk(int x, int z){ - long long nextSeed = getChunkSeed(x, z); - javaRandomSetSeed(nextSeed); - return javaRandomNextInt(10)==0; -} - -//world = path to world saves -//cx = center x world -//cz = center z world -//y = start depth -//w = output width -//h = output height -//zoom = zoom amount (1.0 = 100%) -//bits = byte array for output -//opts = bitmask of render options (see MinutorMap.h) -void DrawMap(const char *world,double cx,double cz,int y,int w,int h,double zoom,unsigned char *bits,int opts,ProgressCallback callback) -{ - /* Simplified coordinate system. - -world z N -screen y - | - | - | - -world x |(cx,cz) +world x - W--------------+----------------E - -screen x | +screen x - | - | - | - +world z N +screen y - */ - - unsigned char *blockbits; - int z,x,px,py; - int blockScale=(int)(16*zoom); - - // number of blocks to fill the screen (plus 2 blocks for floating point inaccuracy) - int hBlocks=(w+blockScale*2)/blockScale; - int vBlocks=(h+blockScale*2)/blockScale; - - - // cx/cz is the center, so find the upper left corner from that - double startx=cx-(double)w/(2*zoom); - double startz=cz-(double)h/(2*zoom); - int startxblock=(int)(startx/16); - int startzblock=(int)(startz/16); - int shiftx=(int)((startx-startxblock*16)*zoom); - int shifty=(int)((startz-startzblock*16)*zoom); - - if (shiftx<0) - { - startxblock--; - shiftx+=blockScale; - } - if (shifty<0) - { - startzblock--; - shifty+=blockScale; - } - - if (!colorsInited) - initColors(); - - // z increases south, decreases north - for (z=0,py=-shifty;z<=vBlocks;z++,py+=blockScale) - { - // x increases west, decreases east - for (x=0,px=-shiftx;x<=hBlocks;x++,px+=blockScale) - { - blockbits = draw(world,startxblock+x,startzblock+z,y,opts,callback,(float)(z*hBlocks+x)/(float)(vBlocks*hBlocks)); - blit(blockbits,bits,px,py,zoom,w,h); - } - } -} - -const char *biomes[]={ - "Ocean", "Plains", "Desert", "Extreme Hills", "Forest", - "Taiga", "Swampland", "River", "Hell", "Sky", "Frozen Ocean", - "Frozen River", "Ice Plains", "Ice Mountains", "Mushroom Island", - "Mushroom Island Shore", "Beach", "Desert Hills", "Forest Hills", - "Taiga Hills", "Extreme Hills Edge", "Jungle", "Jungle Hills" -}; - -//bx = x coord of pixel -//by = y coord of pixel -//cx = center x world -//cz = center z world -//w = output width -//h = output height -//zoom = zoom amount (1.0 = 100%) -//ox = world x at mouse -//oz = world z at mouse -//biome = biome name at mouse -const char *IDBlock(int bx, int by, double cx, double cz, int w, int h, double zoom,int *ox,int *oz,const char **biome) -{ - //WARNING: keep this code in sync with draw() - Block *block; - int x,y,z,px,py,xoff,zoff; - int blockScale=(int)(16*zoom); - - // cx/cz is the center, so find the upper left corner from that - double startx=cx-(double)w/(2*zoom); - double startz=cz-(double)h/(2*zoom); - int startxblock=(int)(startx/16); - int startzblock=(int)(startz/16); - int shiftx=(int)((startx-startxblock*16)*zoom); - int shifty=(int)((startz-startzblock*16)*zoom); - - if (shiftx<0) - { - startxblock--; - shiftx+=blockScale; - } - if (shifty<0) - { - startzblock--; - shifty+=blockScale; - } - - if (by<0) return ""; - - x=(bx+shiftx)/blockScale; - px=x*blockScale-shiftx; - z=(by+shifty)/blockScale; - py=z*blockScale-shifty; - - xoff=(int)((bx-px)/zoom); - zoff=(int)((by-py)/zoom); - - *ox=(startxblock+x)*16+xoff; - *oz=(startzblock+z)*16+zoff; - - *biome="Unknown Biome"; - - block=(Block *)Cache_Find(startxblock+x, startzblock+z); - - if (block==NULL) - return "Unknown"; - - y=block->heightmap[xoff+zoff*16]; - - if (block->biomes[xoff+zoff*16]<23) - *biome=biomes[block->biomes[xoff+zoff*16]]; - - if (y == (unsigned char)-1) - return "Empty"; // nothing was rendered here - - return blocks[block->grid[xoff+zoff*16+y*256]].name; -} - -//copy block to bits at px,py at zoom. bits is wxh -static void blit(unsigned char *block,unsigned char *bits,int px,int py, - double zoom,int w,int h) -{ - int x,y,yofs,bitofs; - int skipx=0,skipy=0; - int bw=(int)(16*zoom); - int bh=(int)(16*zoom); - if (px<0) skipx=-px; - if (px+bw>=w) bw=w-px; - if (bw<=0) return; - if (py<0) skipy=-py; - if (py+bh>=h) bh=h-py; - if (bh<=0) return; - bits+=py*w*4; - bits+=px*4; - for (y=0;yrendery==y && block->renderopts==opts && block->colormap==colormap) // already rendered - { - if (block->rendermissing // wait, the last render was incomplete - && Cache_Find(bx, bz+block->rendermissing) != NULL) - { - ; // we can do a better render now that the missing block is loaded - } else { - // there's no need to re-render, use cache - return block->rendercache; - } - } - - block->rendery=y; - block->renderopts=opts; - block->rendermissing=0; - block->colormap=colormap; - - bits = block->rendercache; - - // find the block to the west, so we can use its heightmap for shading - prevblock=(Block *)Cache_Find(bx-1, bz); - - if (prevblock==NULL) - block->rendermissing=1; //note no loaded block to west - else if (prevblock->rendery!=y || prevblock->renderopts!=opts) - { - block->rendermissing=1; //note improperly rendered block to west - prevblock = NULL; //block was rendered at a different y level, ignore - } - // z increases south, decreases north - for (z=0;z<16;z++) - { - if (prevblock!=NULL) - prevy = prevblock->heightmap[15+z*16]; - else - prevy=-1; - // x increases west, decreases east - for (x=0;x<16;x++) - { - bofs=((y*16+z)*16+x); - color=0; - r=g=b=0; - seenempty=(y==255?1:0); - alpha=0.0; - for (i=y;i>=0;i--,bofs-=16*16) - { - pixel=block->grid[bofs]; - if (pixel==BLOCK_AIR) - { - seenempty=1; - continue; - } - if (pixel==BLOCK_STATIONARY_WATER) - seenempty=1; - if ((showobscured || seenempty) && pixellight[(bofs+256)/2]; - if (bofs&1) light>>=4; - light&=0xf; - } else - light = 0; - - if (mob && blocks[pixel].type==BLOCK_TYPE_OPAQUE && light<8 && i<250) - { - int upone=block->grid[bofs+16*16]; - int uptwo=block->grid[bofs+16*16*2]; - //spawn on solid blocks. The "spawn block" must be transparent, not liquid, not solid. The block above - //the spawn block must be transparent and non solid, but could be liquid. - if ((blocks[upone].type&(BLOCK_TYPE_SOLID|BLOCK_TYPE_TRANSPARENT|BLOCK_TYPE_LIQUID))==BLOCK_TYPE_TRANSPARENT && - (blocks[uptwo].type&(BLOCK_TYPE_SOLID|BLOCK_TYPE_TRANSPARENT))==BLOCK_TYPE_TRANSPARENT) - { - r=0xff; - g=0; - b=0xff; - break; - } - } - if (!lighting) light=12; - } - - if (prevy==-1) - prevy=i; - else if (prevyi) - light-=5; - light=clamp(light,1,15); - color=blockColors[pixel*16+light]; - if (alpha==0.0) - { - alpha=blocks[pixel].alpha; - r=color>>16; - g=(color>>8)&0xff; - b=color&0xff; - } - else - { - r+=(unsigned char)((1.0-alpha)*(color>>16)); - g+=(unsigned char)((1.0-alpha)*((color>>8)&0xff)); - b+=(unsigned char)((1.0-alpha)*(color&0xff)); - alpha+=blocks[pixel].alpha*(1.0-alpha); - } - if (blocks[pixel].alpha==1.0) - break; - } - } - prevy=i; - if (depthshading) // darken deeper blocks - { - int num=prevy+50-(256-y)/10; - int denom=y+50-(256-y)/10; - r=r*num/denom; - g=g*num/denom; - b=b*num/denom; - } - if (hasSlime > 0) - { - if (y<=16) - g=clamp(g+20,0,255); - else if (x%15==0 || z%15==0) - g=clamp(g+20,0,255); - } - if (cavemode) - { - seenempty=0; - pixel=block->grid[bofs]; - if (pixel==BLOCK_LEAVES || pixel==BLOCK_LOG) //special case surface trees - for (; i>=1; i--,bofs-=16*16,pixel=block->grid[bofs]) - if (!(pixel==BLOCK_LOG||pixel==BLOCK_LEAVES||pixel==BLOCK_AIR)) - break; // skip leaves, wood, air - for (;i>=1;i--,bofs-=16*16) - { - pixel=block->grid[bofs]; - if (pixel==BLOCK_AIR) - { - seenempty=1; - continue; - } - if (seenempty && pixelheightmap[x+z*16] = prevy; - } - } - return bits; -} -Block *LoadBlock(char *directory, int cx, int cz) -{ - Block *block=block_alloc(); - block->rendery = -1; // force redraw - - if (regionGetBlocks(directory, cx, cz, block->grid, block->light, block->biomes)) { - return block; - } - - block_free(block); - return NULL; -} - -void GetSpawn(const char *world,int *x,int *y,int *z) -{ - bfFile bf; - char filename[256]; - strncpy_s(filename,256,world,256); - strncat_s(filename,256,"/level.dat",256); - bf=newNBT(filename); - nbtGetSpawn(bf,x,y,z); - nbtClose(bf); -} -void GetRandomSeed(const char *world,long long *seed) -{ - bfFile bf; - char filename[256]; - strncpy_s(filename,256,world,256); - strncat_s(filename,256,"/level.dat",256); - bf=newNBT(filename); - nbtGetRandomSeed(bf,seed); - mapSeed = *seed; - nbtClose(bf); - -} -void GetPlayer(const char *world,int *px,int *py,int *pz) -{ - bfFile bf; - char filename[256]; - strncpy_s(filename,256,world,256); - strncat_s(filename,256,"/level.dat",256); - bf=newNBT(filename); - nbtGetPlayer(bf,px,py,pz); - nbtClose(bf); -} -void GetPlayerSpawn(const char *world,int *px,int *py,int *pz) -{ - bfFile bf; - char filename[256]; - strncpy_s(filename,256,world,256); - strncat_s(filename,256,"/level.dat",256); - bf=newNBT(filename); - nbtGetPlayerSpawn(bf,px,py,pz); - nbtClose(bf); -} - -//palette should be in RGBA format -void SetMapPalette(unsigned int *palette,int num) -{ - unsigned char r,g,b; - double a; - int i; - - colormap++; - for (i=0;i>24; - g=palette[i]>>16; - b=palette[i]>>8; - a=((double)(palette[i]&0xff))/255.0; - r=(unsigned char)(r*a); //premultiply alpha - g=(unsigned char)(g*a); - b=(unsigned char)(b*a); - blocks[i].color=(r<<16)|(g<<8)|b; - blocks[i].alpha=a; - } - initColors(); -} - -// for each block color, calculate light levels 0-15 -static void initColors() -{ - unsigned r,g,b,i,shade; - double y,u,v,delta; - unsigned int color; - int rx, ry; - - colorsInited=1; - for (i=0;i>16; - g=(color>>8)&0xff; - b=color&0xff; - //we'll use YUV to darken the blocks.. gives a nice even - //coloring - y=0.299*r+0.587*g+0.114*b; - u=(b-y)*0.565; - v=(r-y)*0.713; - delta=y/15; - - for (shade=0;shade<16;shade++) - { - y=shade*delta; - r=(unsigned int)clamp(y+1.403*v,0,255); - g=(unsigned int)clamp(y-0.344*u-0.714*v,0,255); - b=(unsigned int)clamp(y+1.770*u,0,255); - blockColors[i*16+shade]=(r<<16)|(g<<8)|b; - } - } - - // also initialize the "missing tile" graphic - - for (rx = 0; rx < 16; ++rx) - { - for (ry = 0; ry < 16; ++ry) - { - int off = (rx+ry*16)*4; - int tone = 150; - if ((rx/4)%2 ^ (ry/4)%2) - tone=140; - blank_tile[off] = tone; - blank_tile[off+1] = tone; - blank_tile[off+2] = tone; - blank_tile[off+3] = 128; - } - } -} diff --git a/MinutorMap/MinutorMap.h b/MinutorMap/MinutorMap.h deleted file mode 100644 index d42d5cb8..00000000 --- a/MinutorMap/MinutorMap.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef __MINUTOR_MAP_H__ -#define __MINUTOR_MAP_H__ - -#ifndef WIN32 -#define __declspec(a) -#define dllexport 0 -#define __cdecl -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define CAVEMODE 0x01 -#define HIDEOBSCURED 0x02 -#define DEPTHSHADING 0x04 -#define LIGHTING 0x08 -#define HELL 0x10 -#define ENDER 0x20 -#define SLIME 0x40 -#define MOB 0x80 - -typedef void (*ProgressCallback)(float progress); - - __declspec(dllexport) void __cdecl DrawMap(const char *world,double cx,double cz,int y,int w,int h,double zoom,unsigned char *bits, int opts,ProgressCallback callback); - __declspec(dllexport) const char * __cdecl IDBlock(int bx, int by, double cx, double cz, int w, int h, double zoom,int *ox,int *oz, const char **biome); - __declspec(dllexport) void __cdecl CloseAll(); - __declspec(dllexport) void __cdecl GetSpawn(const char *world,int *x,int *y,int *z); - __declspec(dllexport) void __cdecl GetPlayer(const char *world,int *px,int *py,int *pz); - __declspec(dllexport) void __cdecl GetRandomSeed(const char *world,long long* pseed); - __declspec(dllexport) void __cdecl GetPlayerSpawn(const char *world,int *px,int *py,int *pz); - - // palette should be in RGBA format, num colors in the palette - __declspec(dllexport) void __cdecl SetMapPalette(unsigned int *palette,int num); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/MinutorMap/MinutorMap.vcxproj b/MinutorMap/MinutorMap.vcxproj deleted file mode 100644 index 8a175d08..00000000 --- a/MinutorMap/MinutorMap.vcxproj +++ /dev/null @@ -1,151 +0,0 @@ - - - - - Debug - Win32 - - - Release 64bit - Win32 - - - Release - Win32 - - - - {9E6153B8-20A1-42DC-B889-DAD936A8A786} - Win32Proj - MinutorMap - - - - StaticLibrary - true - Unicode - - - StaticLibrary - false - true - Unicode - - - DynamicLibrary - false - true - Unicode - - - - - - - - - - - - - - - - true - - - false - - - false - - - - Use - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;MINUTORMAP_EXPORTS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - Windows - true - - - - - Level3 - Use - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;MINUTORMAP_EXPORTS;%(PreprocessorDefinitions) - MultiThreaded - - - Windows - true - true - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - LIBCMT.lib - - - - - Level3 - Use - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;MINUTORMAP_EXPORTS;%(PreprocessorDefinitions) - - - Windows - true - true - true - zlibstat64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - LIBCMT.lib - MachineX64 - - - - - - - - - - - - - - - - false - - - false - false - - - - - - - - - - Create - Create - Create - - - - - - - - - diff --git a/MinutorMap/blockInfo.h b/MinutorMap/blockInfo.h deleted file mode 100644 index e450d1c8..00000000 --- a/MinutorMap/blockInfo.h +++ /dev/null @@ -1,210 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef __BLOCKINFO_H__ -#define __BLOCKINFO_H__ - -#include - -/* -We use pre-multiplied alpha. -That means that if the color is #ffffff, and alpha is 0.5, then the entry should be: -0x7f7f7f,0.5 -*/ - -#define BLOCK_TYPE_OPAQUE 0 -#define BLOCK_TYPE_TRANSPARENT 1 -#define BLOCK_TYPE_SOLID 2 -#define BLOCK_TYPE_LIQUID 4 - -static struct { - const char *name; - unsigned int color; - double alpha; - unsigned char type; // bitmask -} blocks[256]={ -{"Air", 0x000000,0.0,1}, //00 -{"Stone", 0x787878,1.0,0}, //01 -{"Grass", 0x78b34d,1.0,0}, //02 -{"Dirt", 0x8c6344,1.0,0}, //03 -{"Cobblestone", 0x828282,1.0,0}, //04 -{"Wooden Plank", 0x9f8150,1.0,0}, //05 -{"Sapling", 0x000000,0.0,1}, //06 -{"Bedrock", 0x565656,1.0,0}, //07 -{"Water", 0x163288,0.535,5}, //08 -{"Stationary Water", 0x163288,0.535,5}, //09 -{"Lava", 0xf56d00,1.0,5}, //0a -{"Stationary Lava", 0xf56d00,1.0,5}, //0b -{"Sand", 0xe0d8a6,1.0,0}, //0c -{"Gravel", 0x857b7b,1.0,0}, //0d -{"Gold Ore", 0xfcee4b,1.0,0}, //0e -{"Iron Ore", 0xbc9980,1.0,0}, //0f -{"Coal Ore", 0x343434,1.0,0}, //10 -{"Wood", 0xb1905a,1.0,0}, //11 -{"Leaves", 0x39ab27,1.0,3}, //12 -{"Sponge", 0xc7c743,1.0,0}, //13 -{"Glass", 0x607b7f,0.5,3}, //14 -{"Lapis Lazuli Ore", 0x143880,1.0,0}, //15 -{"Lapis Lazuli Block", 0x1b4ebb,1.0,0}, //16 -{"Dispenser", 0x6f6f6f,1.0,0}, //17 -{"Sandstone", 0xe0d8a6,1.0,0}, //18 -{"Note Block", 0x342017,1.0,0}, //19 -{"Bed", 0xff3333,1.0,3}, //1a -{"Powered Rail", 0x693838,1.0,1}, //1b -{"Detector Rail", 0x694d3a,1.0,1}, //1c -{"Sticky Piston", 0x719e60,1.0,3}, //1d -{"Cobweb", 0xeeeeee,1.0,1}, //1e -{"Tall Grass", 0x68a33d,1.0,1}, //1f -{"Dead Bush", 0x946428,1.0,1}, //20 -{"Piston", 0x95774b,1.0,3}, //21 -{"Piston Extension", 0x95774b,1.0,3}, //22 -{"Wool", 0xdcdcdc,1.0,0}, //23 -{"", 0x000000,0.0,0}, //24 -{"Dandelion", 0x000000,0.0,1}, //25 -{"Rose", 0x000000,0.0,1}, //26 -{"Brown Mushroom", 0x000000,0.0,1}, //27 -{"Red Mushroom", 0x000000,0.0,1}, //28 -{"Gold Block", 0xfef74e,1.0,0}, //29 -{"Iron Block", 0xeeeeee,1.0,0}, //2a -{"Double Slab", 0xa6a6a6,1.0,0}, //2b -{"Slab", 0xa5a5a5,1.0,3}, //2c -{"Brick", 0xa0807b,1.0,0}, //2d -{"TNT", 0xdb441a,1.0,3}, //2e -{"Bookshelf", 0x795a39,1.0,0}, //2f -{"Moss Stone", 0x627162,1.0,0}, //30 -{"Obsidian", 0x1b1729,1.0,0}, //31 -{"Torch", 0xfcfc00,1.0,1}, //32 -{"Fire", 0xfca100,1.0,1}, //33 -{"Monster Spawner", 0x254254,1.0,3}, //34 -{"Oak Wood Stairs", 0x9e804f,1.0,3}, //35 -{"Chest", 0xa06f23,1.0,3}, //36 -{"Redstone Wire", 0xd60000,1.0,1}, //37 -{"Diamond Ore", 0x5decf5,1.0,0}, //38 -{"Diamond Block", 0x7fe3df,1.0,0}, //39 -{"Crafting Table", 0x825432,1.0,0}, //3a -{"Wheat", 0x766615,1.0,1}, //3b -{"Farmland", 0x40220b,1.0,3}, //3c -{"Furnace", 0x767677,1.0,0}, //3d -{"Burning Furnace", 0x777676,1.0,0}, //3e -{"Sign Post", 0x9f814f,1.0,1}, //3f -{"Wooden Door", 0x000000,0.0,3}, //40 -{"Ladder", 0x000000,0.0,3}, //41 -{"Rail", 0x686868,1.0,1}, //42 -{"Cobblestone Stairs", 0x818181,1.0,3}, //43 -{"Wall Sign", 0x000000,0.0,1}, //44 -{"Lever", 0x000000,0.0,1}, //45 -{"Stone Pressure Plate", 0xa4a4a4,1.0,1}, //46 -{"Iron Door", 0x000000,0.0,3}, //47 -{"Wooden Pressure Plate", 0x9d7f4e,1.0,1}, //48 -{"Redstone Ore", 0x8f0303,1.0,0}, //49 -{"Glowing Redstone Ore", 0x900303,1.0,0}, //4a -{"Redstone Torch (off)", 0x560000,1.0,1}, //4b -{"Redstone Torch (on)", 0xfd0000,1.0,1}, //4c -{"Stone Button", 0x000000,0.0,1}, //4d -{"Snow", 0xf0fafa,1.0,1}, //4e -{"Ice", 0x4d6a9c,0.613,3}, //4f -{"Snow Block", 0xf1fafa,1.0,0}, //50 -{"Cactus", 0x0f791d,1.0,1}, //51 -{"Clay", 0xa2a7b4,1.0,0}, //52 -{"Sugar Cane", 0x72944e,1.0,1}, //53 -{"Jukebox", 0x8a5a40,1.0,0}, //54 -{"Fence", 0x9f814e,1.0,3}, //55 -{"Pumpkin", 0xc07615,1.0,0}, //56 -{"Netherrack", 0x723a38,1.0,0}, //57 -{"Soul Sand", 0x554134,1.0,0}, //58 -{"Glowstone", 0xf9d49c,1.0,3}, //59 -{"Nether Portal", 0xd67fff,1.0,1}, //5a -{"Jack-O-Lantern", 0xe9b416,1.0,0}, //5b -{"Cake", 0xffffff,1.0,3}, //5c -{"Redstone Repeater (off)",0x560000,1.0,3}, //5d -{"Redstone Repeater (on)", 0xee5555,1.0,3}, //5e -{"Locked Chest", 0xa06f23,1.0,3}, //5f -{"Trapdoor", 0x886634,1.0,3}, //60 -{"Monster Egg", 0x787878,1.0,0}, //61 -{"Stone Brick", 0x797979,1.0,0}, //62 -{"Huge Brown Mushroom", 0x654b39,1.0,0}, //63 -{"Huge Red Mushroom", 0xa91b19,1.0,0}, //64 -{"Iron Bars", 0xa3a4a4,1.0,3}, //65 -{"Glass Pane", 0x607b7f,0.5,3}, //66 -{"Melon", 0xaead27,1.0,0}, //67 -{"Pumpkin Stem", 0x000000,0.0,1}, //68 -{"Melon Stem", 0x000000,0.0,1}, //69 -{"Vines", 0x1e4c0a,1.0,1}, //6a -{"Fence Gate", 0xa88754,1.0,3}, //6b -{"Brick Stairs", 0xa0807b,1.0,3}, //6c -{"Stone Brick Stairs", 0x797979,1.0,3}, //6d -{"Mycelium", 0x685d69,1.0,0}, //6e -{"Lily Pad", 0x0c5f14,1.0,0}, //6f -{"Nether Brick", 0x32171c,1.0,0}, //70 -{"Nether Brick Fence", 0x241316,1.0,3}, //71 -{"Nether Brick Stairs", 0x32171c,1.0,3}, //72 -{"Nether Wart", 0x81080a,1.0,1}, //73 -{"Enchantment Table", 0x45dec3,1.0,1}, //74 -{"Brewing Stand", 0x77692e,1.0,1}, //75 -{"Cauldron", 0x323232,1.0,0}, //76 -{"End Portal", 0x000000,1.0,1}, //77 -{"End Portal Frame", 0x366059,1.0,0}, //78 -{"End Stone", 0xdadca6,1.0,0}, //79 -{"Dragon Egg", 0x1b1729,1.0,0}, //7a -{"Redstone Lamp (off)", 0xf9d49c,1.0,0}, //7b -{"Redstone Lamp (on)", 0xf9d49c,1.0,0}, //7c -{"Wooden Double Slab", 0x9f8150,1.0,0}, //7d -{"Wooden Slab", 0x9f8150,1.0,3}, //7e -{"Cocoa Plant", 0x79350d,1.0,0}, //7f -{"Sandstone Stairs", 0xe0d8a6,1.0,3}, //80 -{"Emerald Ore", 0x17ce5c,1.0,0}, //81 -{"Ender Chest", 0x2f4246,1.0,3}, //82 -{"Tripwire Hook", 0x343434,1.0,1}, //83 -{"Tripwire", 0xffeeee,1.0,1}, //84 -{"Emerald Block", 0x5edb81,1.0,0}, //85 -{"Spruce Wood Stairs", 0x4d3822,1.0,3}, //86 -{"Birch Wood Stairs", 0x897b55,1.0,3}, //87 -{"Jungle Wood Stairs", 0x66482f,1.0,3}, //88 -{"Command Block", 0xba764a,1.0,0}, //89 -{"Beacon", 0x9fdedb,1.0,0}, //8a -{"Cobblestone Wall", 0x828282,1.0,3}, //8b -{"Flower Pot", 0x5d3328,1.0,1}, //8c -{"Carrots", 0x08c400,1.0,1}, //8d -{"Potatoes", 0x00e01a,1.0,1}, //8e -{"Wooden Button", 0x9f8150,0.0,1}, //8f -{"Head", 0x000000,0.0,1}, //90 -{"Anvil", 0x393939,1.0,1} //91 -}; - -#define numBlocks 0x92 //number just after last block - -enum block_types { - BLOCK_AIR = 0x00, - BLOCK_STATIONARY_WATER = 0x09, - BLOCK_LOG = 0x11, - BLOCK_LEAVES = 0x12, - BLOCK_SNOW = 0x4e -}; - - -#endif diff --git a/MinutorMap/cache.c b/MinutorMap/cache.c deleted file mode 100644 index e9c89b41..00000000 --- a/MinutorMap/cache.c +++ /dev/null @@ -1,189 +0,0 @@ -/* -Copyright (c) 2011, Ryan Hitchman -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "stdafx.h" - -#include -#include -#include - -/* a simple cache based on a hashtable with separate chaining */ - -// these must be powers of two -#define HASH_XDIM 64 -#define HASH_ZDIM 64 -#define HASH_SIZE (HASH_XDIM * HASH_ZDIM) - -// arbitrary, let users tune this? -// 6000 entries translates to minutor using ~300MB of RAM (on x64) -#define HASH_MAX_ENTRIES 12000 - -typedef struct block_entry { - int x, z; - struct block_entry *next; - Block *data; -} block_entry; - -typedef struct { - int x, z; -} Point; - -static block_entry **blockCache=NULL; - -static Point *cacheHistory=NULL; -static int cacheN=0; - -static int hash_coord(int x, int z) { - return (x&(HASH_XDIM-1))*(HASH_ZDIM) + (z & (HASH_ZDIM - 1)); -} - -static block_entry* hash_new(int x, int z, void* data, block_entry* next) { - block_entry* ret = malloc(sizeof(block_entry)); - ret->x = x; - ret->z = z; - ret->data = data; - ret->next = next; - return ret; -} - -void Cache_Add(int bx, int bz, void *data) -{ - int hash; - block_entry *to_del=NULL; - - if (blockCache == NULL) { - blockCache = (block_entry**)malloc(sizeof(block_entry*) * HASH_SIZE); - memset(blockCache, 0, sizeof(block_entry*) * HASH_SIZE); - cacheHistory = (Point*)malloc(sizeof(Point) * HASH_MAX_ENTRIES); - cacheN = 0; - } - - hash = hash_coord(bx, bz); - - if (cacheN >= HASH_MAX_ENTRIES) { - // we need to remove an old entry - Point coord = cacheHistory[cacheN % HASH_MAX_ENTRIES]; - int oldhash = hash_coord(coord.x, coord.z); - - block_entry **cur = &blockCache[oldhash]; - while (*cur != NULL) { - if ((**cur).x == coord.x && (**cur).z == coord.z) { - to_del = *cur; - *cur = to_del->next; - block_free(to_del->data); - //free(to_del); // we will re-use this entry - break; - } - cur = &((**cur).next); - } - } - - if (to_del != NULL) { - // re-use the old entry for the new one - to_del->next = blockCache[hash]; - to_del->x = bx; - to_del->z = bz; - to_del->data = data; - blockCache[hash] = to_del; - } else { - blockCache[hash] = hash_new(bx, bz, data, blockCache[hash]); - } - - cacheHistory[cacheN % HASH_MAX_ENTRIES].x = bx; - cacheHistory[cacheN % HASH_MAX_ENTRIES].z = bz; - cacheN++; -} - -void *Cache_Find(int bx,int bz) -{ - block_entry *entry; - - if (blockCache == NULL) - return NULL; - - for (entry = blockCache[hash_coord(bx, bz)]; entry != NULL; entry = entry->next) - if (entry->x == bx && entry->z == bz) - return entry->data; - - return NULL; -} - -void Cache_Empty() -{ - int hash; - block_entry *entry,*next; - - if (blockCache == NULL) - return; - - for (hash = 0; hash < HASH_SIZE; hash++) { - entry = blockCache[hash]; - while (entry != NULL) { - next = entry->next; - free(entry->data); - free(entry); - entry = next; - } - } - - free(blockCache); - free(cacheHistory); - blockCache = NULL; -} - -/* a simple malloc wrapper, based on the observation that a common - * behavior pattern for Minutor when the cache is at max capacity - * is something like: - * - * newBlock = malloc(sizeof(Block)); - * cacheAdd(newBlock) - * free(oldBlock) // same size - * - * Repeatedly. Recycling the old block can prevent the need for - * malloc and free. - */ - -static Block* last_block = NULL; - -Block* block_alloc() -{ - if (last_block != NULL) - { - Block* ret = last_block; - last_block = NULL; - return ret; - } - return malloc(sizeof(Block)); -} - -void block_free(Block* block) -{ - if (last_block != NULL) - free(last_block); - - last_block = block; -} diff --git a/MinutorMap/cache.h b/MinutorMap/cache.h deleted file mode 100644 index 182b35df..00000000 --- a/MinutorMap/cache.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun - Parts Copyright (c) 2010-2011, Ryan Hitchman -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef __CACHE_H__ -#define __CACHE_H__ - -typedef struct Block { - unsigned char grid[16*16*256]; // blockid array [y+(z+x*16)*256] - unsigned char light[16*16*128]; - - unsigned char rendercache[16*16*4]; // bitmap of last render - unsigned char heightmap[16*16]; // height of rendered block [x+z*16] - unsigned char biomes[16*16]; //biome ids for block - - int rendery; // slice height for last render - int renderopts; // options bitmask for last render - char rendermissing; // the z-offset of a block that was missing - // when it was last rendered (for blocks on the - // left edge of the map, this might be +1) - unsigned short colormap; //color map when this was rendered -} Block; - -void *Cache_Find(int bx,int bz); -void Cache_Add(int bx,int bz,void *data); -void Cache_Empty(); - -/* a simple malloc wrapper, based on the observation that a common - * behavior pattern for Minutor when the cache is at max capacity - * is something like: - * - * newBlock = malloc(sizeof(Block)); - * cacheAdd(newBlock) - * free(oldBlock) // same size - * - * Repeated over and over. Recycling the most recently freed block - * prevents expensive reallocations. - */ - -Block* block_alloc(); // allocate memory for a block -void block_free(Block* block); // release memory for a block - -#endif diff --git a/MinutorMap/dllmain.c b/MinutorMap/dllmain.c deleted file mode 100644 index 4dc85ded..00000000 --- a/MinutorMap/dllmain.c +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -// dllmain.cpp : Defines the entry point for the DLL application. -#include "stdafx.h" - -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - diff --git a/MinutorMap/nbt.c b/MinutorMap/nbt.c deleted file mode 100644 index 8b5c2b50..00000000 --- a/MinutorMap/nbt.c +++ /dev/null @@ -1,417 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#include "stdafx.h" -#include - -static void skipType(bfFile bf, int type); -static void skipList(bfFile bf); -static void skipCompound(bfFile bf); - -void bfread(bfFile bf, void *target, int len) -{ - if (bf.type == BF_BUFFER) { - memcpy(target, bf.buf + *bf.offset, len); - *bf.offset += len; - } else if (bf.type == BF_GZIP) { - gzread(bf.gz, target, len); - } -} - -void bfseek(bfFile bf, int offset, int whence) -{ - if (bf.type == BF_BUFFER) { - if (whence == SEEK_CUR) - *bf.offset += offset; - else if (whence == SEEK_SET) - *bf.offset = offset; - } else if (bf.type == BF_GZIP) { - gzseek(bf.gz, offset, whence); - } -} - -bfFile newNBT(const char *filename) -{ - bfFile ret; - ret.type = BF_GZIP; - ret.gz = gzopen(filename,"rb"); - ret._offset = 0; - ret.offset = &ret._offset; - return ret; -} - -static unsigned short readWord(bfFile bf) -{ - unsigned char buf[2]; - bfread(bf,buf,2); - return (buf[0]<<8)|buf[1]; -} -static unsigned int readDword(bfFile bf) -{ - unsigned char buf[4]; - bfread(bf,buf,4); - return (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3]; -} -static unsigned long long readLong(bfFile bf) -{ - int i; - union { - double f; - unsigned long long l; - } fl; - unsigned char buf[8]; - bfread(bf,buf,8); - fl.l=0; - for (i=0;i<8;i++) - { - fl.l<<=8; - fl.l|=buf[i]; - } - return fl.l; -} -static double readDouble(bfFile bf) -{ - int i; - union { - double f; - unsigned long long l; - } fl; - unsigned char buf[8]; - bfread(bf,buf,8); - fl.l=0; - for (i=0;i<8;i++) - { - fl.l<<=8; - fl.l|=buf[i]; - } - return fl.f; -} -static void skipType(bfFile bf,int type) -{ - int len; - switch (type) - { - case 1: //byte - bfseek(bf,1,SEEK_CUR); - break; - case 2: //short - bfseek(bf,2,SEEK_CUR); - break; - case 3: //int - bfseek(bf,4,SEEK_CUR); - break; - case 4: //long - bfseek(bf,8,SEEK_CUR); - break; - case 5: //float - bfseek(bf,4,SEEK_CUR); - break; - case 6: //double - bfseek(bf,8,SEEK_CUR); - break; - case 7: //byte array - len=readDword(bf); - bfseek(bf,len,SEEK_CUR); - break; - case 8: //string - len=readWord(bf); - bfseek(bf,len,SEEK_CUR); - break; - case 9: //list - skipList(bf); - break; - case 10: //compound - skipCompound(bf); - break; - case 11: //int array - len=readDword(bf); - bfseek(bf,len*4,SEEK_CUR); - break; - } -} -static void skipList(bfFile bf) -{ - int len,i; - unsigned char type; - bfread(bf,&type,1); - len=readDword(bf); - switch (type) - { - case 1: //byte - bfseek(bf,len,SEEK_CUR); - break; - case 2: //short - bfseek(bf,len*2,SEEK_CUR); - break; - case 3: //int - bfseek(bf,len*4,SEEK_CUR); - break; - case 4: //long - bfseek(bf,len*8,SEEK_CUR); - break; - case 5: //float - bfseek(bf,len*4,SEEK_CUR); - break; - case 6: //double - bfseek(bf,len*8,SEEK_CUR); - break; - case 7: //byte array - for (i=0;i - -enum {BF_BUFFER, BF_GZIP}; - -// wraps gzFile and memory buffers with a consistent interface -typedef struct { - int type; - unsigned char *buf; - int *offset; - int _offset; - gzFile gz; -} bfFile; - -bfFile newNBT(const char *filename); -int nbtGetBlocks(bfFile bf, unsigned char *buff,unsigned char *blockLight,unsigned char *biomes); -void nbtGetSpawn(bfFile bf,int *x,int *y,int *z); -void nbtGetPlayer(bfFile bf,int *px,int *py,int *pz); -void nbtGetPlayerSpawn(bfFile bf,int *px,int *py,int *pz); -void nbtGetRandomSeed(bfFile bf,long long *seed); -void nbtClose(bfFile bf); - -#endif diff --git a/MinutorMap/region.c b/MinutorMap/region.c deleted file mode 100644 index fa5a9415..00000000 --- a/MinutorMap/region.c +++ /dev/null @@ -1,164 +0,0 @@ -/* -Copyright (c) 2011, Ryan Hitchman -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/* - -Region File Format - -Concept: The minimum unit of storage on hard drives is 4KB. 90% of Minecraft - chunks are smaller than 4KB. 99% are smaller than 8KB. Write a simple - container to store chunks in single files in runs of 4KB sectors. - -Each region file represents a 32x32 group of chunks. The conversion from -chunk number to region number is floor(coord / 32); a chunk at (30, -3) -would be in region (0, -1), and one at (70, -30) would be at (3, -1). -Region files are named "r.x.z.mcr", where x and z are the region coordinates. - -A region file begins with an 8KB header that describes where chunks are stored -in the file and when they were last modified. A 4-byte big-endian integer -represents sector offsets and sector counts. The chunk offset for a chunk -located at (x, z) begins at byte 4*(x+z*32) in the file. The bottom byte of -the chunk offset indicates the number of sectors the chunk takes up,and -the top 3 bytes represent the sector number of the chunk. Given a chunk -offset o, the chunk data begins at byte 4096*(o/256) and takes up at -most 4096*(o%256) bytes. A chunk cannot exceed 1MB in size. A chunk offset -of 0 indicates a missing chunk. - -The 4-byte big-endian modification time for a chunk (x,z) begins at byte -4096+4*(x+z*32) in the file. The time is stored as the number of seconds -since Jan 1, 1970 that the chunk was last written (aka Unix Time). - -Chunk data begins with a 4-byte big-endian integer representing the chunk data -length in bytes, not counting the length field. The length must be smaller than -4096 times the number of sectors. The next byte is a version number, to allow -backwards-compatible updates to how chunks are encoded. - -A version number of 1 is never used, for obscure historical reasons. - -A version number of 2 represents a deflated (zlib compressed) NBT file. The -deflated data is the chunk length - 1. - -*/ - -#include "stdafx.h" - -#define CHUNK_DEFLATE_MAX (1024 * 1024) // 1MB limit for compressed chunks -#define CHUNK_INFLATE_MAX (1024 * 2048) // 2MB limit for inflated chunks - -#define RERROR(x) if(x) { PortaClose(regionFile); return 0; } - - -// directory: the base world directory, e.g. "/home/ryan/.minecraft/saves/World1/" -// cx, cz: the chunk's x and z offset -// block: a 32KB buffer to write block data into -// blockLight: a 16KB buffer to write block light into (not skylight) -// -// returns 1 on success, 0 on error -int regionGetBlocks(char *directory, int cx, int cz, unsigned char *block, unsigned char *blockLight, unsigned char *biomes) -{ - char filename[256]; - PORTAFILE regionFile; - static unsigned char *buf=NULL,*out=NULL; - int br; - int sectorNumber, offset, chunkLength; - - int status; - bfFile bf; - - static z_stream strm; - static int strm_initialized = 0; - - if (buf==NULL) - { - buf=malloc(CHUNK_DEFLATE_MAX); - out=malloc(CHUNK_INFLATE_MAX); - } - - // open the region file - sprintf_s(filename,256,"%s/region/r.%d.%d.mca",directory,cx>>5,cz>>5); - - regionFile=PortaOpen(filename); - if (regionFile == NULL) - return 0; - - // seek to the chunk offset - RERROR(PortaSeek(regionFile, 4*((cx&31)+(cz&31)*32))); - - // get the chunk offset - RERROR(PortaRead(regionFile,buf, 4)); - - sectorNumber = buf[3]; // how many 4096B sectors the chunk takes up - offset = (buf[0]<<16)|(buf[1]<<8)|buf[2]; // 4KB sector the chunk is in - - RERROR(offset == 0); // an empty chunk - - RERROR(PortaSeek(regionFile, 4096*offset)); - - RERROR(sectorNumber * 4096 > CHUNK_DEFLATE_MAX); - - // read chunk in one shot - // this is faster than reading the header and data separately - RERROR(PortaRead(regionFile,buf, 4096 * sectorNumber)); - - chunkLength = (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3]; - - // sanity check chunk size - RERROR(chunkLength > sectorNumber * 4096 || chunkLength > CHUNK_DEFLATE_MAX); - - // only handle zlib-compressed chunks (v2) - RERROR(buf[4] != 2); - - PortaClose(regionFile); - - // decompress chunk - - - if (!strm_initialized) { - // we re-use dynamically allocated memory - strm.zalloc = (alloc_func)NULL; - strm.zfree = (free_func)NULL; - strm.opaque = NULL; - inflateInit(&strm); - strm_initialized = 1; - } - - strm.next_out = out; - strm.avail_out = CHUNK_INFLATE_MAX; - strm.avail_in = chunkLength - 1; - strm.next_in = buf + 5; - - inflateReset(&strm); - status = inflate(&strm, Z_FINISH); // decompress in one step - - if (status != Z_STREAM_END) // error inflating (not enough space?) - return 0; - - // the uncompressed chunk data is now in "out", with length strm.avail_out - - bf.type = BF_BUFFER; - bf.buf = out; - bf._offset = 0; - bf.offset = &bf._offset; - - return nbtGetBlocks(bf, block, blockLight, biomes); -} diff --git a/MinutorMap/region.h b/MinutorMap/region.h deleted file mode 100644 index 431aaa9e..00000000 --- a/MinutorMap/region.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright (c) 2010, Ryan Hitchman -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#ifndef __REGION_H__ -#define __REGION_H__ - -int regionGetBlocks(char *filename, int bx, int bz, unsigned char *block, unsigned char *blockLight, unsigned char *biomes); - -#endif diff --git a/MinutorMap/stdafx.c b/MinutorMap/stdafx.c deleted file mode 100644 index 6e0595cc..00000000 --- a/MinutorMap/stdafx.c +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -// stdafx.cpp : source file that includes just the standard includes -// MinutorMap.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/MinutorMap/stdafx.h b/MinutorMap/stdafx.h deleted file mode 100644 index 2ddb6ce5..00000000 --- a/MinutorMap/stdafx.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#ifdef WIN32 -#include "targetver.h" - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -// Windows Header Files: -#include - -#endif - -#include "MinutorMap.h" -#include "nbt.h" -#include "region.h" -#include "cache.h" -#include -#include - -#ifdef WIN32 -#define PORTAFILE HANDLE -#define PortaOpen(fn) CreateFileA(fn,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL) -#define PortaSeek(h,ofs) SetFilePointer(h,ofs,NULL,FILE_BEGIN)==INVALID_SET_FILE_POINTER -#define PortaRead(h,buf,len) !ReadFile(h,buf,len,&br,NULL) -#define PortaClose(h) CloseHandle(h) -#endif - -#ifndef WIN32 -#define strncpy_s(f,n,w,m) strncpy(f,w,m) -#define strncat_s(f,n,w,m) strncat(f,w,m) -#define sprintf_s snprintf -#define PORTAFILE FILE* -#define PortaOpen(fn) fopen(fn,"rb") -#define PortaSeek(h,ofs) fseek(h,ofs,SEEK_SET) -#define PortaRead(h,buf,len) fread(buf,len,1,h)!=1 -#define PortaClose(h) fclose(h) -#endif - -#if __STDC_VERSION__ >= 199901L -#define C99 -#endif diff --git a/MinutorMap/targetver.h b/MinutorMap/targetver.h deleted file mode 100644 index f3273087..00000000 --- a/MinutorMap/targetver.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#include diff --git a/MinutorMap/zlibstat.lib b/MinutorMap/zlibstat.lib deleted file mode 100644 index 88e39580..00000000 Binary files a/MinutorMap/zlibstat.lib and /dev/null differ diff --git a/Minutorwin.sln b/Minutorwin.sln deleted file mode 100644 index 1e7ab5c4..00000000 --- a/Minutorwin.sln +++ /dev/null @@ -1,34 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual C++ Express 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Minutor", "Win\Minutor.vcxproj", "{DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}" - ProjectSection(ProjectDependencies) = postProject - {9E6153B8-20A1-42DC-B889-DAD936A8A786} = {9E6153B8-20A1-42DC-B889-DAD936A8A786} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MinutorMap", "MinutorMap\MinutorMap.vcxproj", "{9E6153B8-20A1-42DC-B889-DAD936A8A786}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release 64bit|Win32 = Release 64bit|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}.Debug|Win32.ActiveCfg = Debug|Win32 - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}.Debug|Win32.Build.0 = Debug|Win32 - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}.Release 64bit|Win32.ActiveCfg = Release|Win32 - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}.Release 64bit|Win32.Build.0 = Release|Win32 - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}.Release|Win32.ActiveCfg = Release|Win32 - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655}.Release|Win32.Build.0 = Release|Win32 - {9E6153B8-20A1-42DC-B889-DAD936A8A786}.Debug|Win32.ActiveCfg = Debug|Win32 - {9E6153B8-20A1-42DC-B889-DAD936A8A786}.Debug|Win32.Build.0 = Debug|Win32 - {9E6153B8-20A1-42DC-B889-DAD936A8A786}.Release 64bit|Win32.ActiveCfg = Release 64bit|Win32 - {9E6153B8-20A1-42DC-B889-DAD936A8A786}.Release 64bit|Win32.Build.0 = Release 64bit|Win32 - {9E6153B8-20A1-42DC-B889-DAD936A8A786}.Release|Win32.ActiveCfg = Release|Win32 - {9E6153B8-20A1-42DC-B889-DAD936A8A786}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/OSX/ColorScheme.m b/OSX/ColorScheme.m deleted file mode 100644 index 3ee43469..00000000 --- a/OSX/ColorScheme.m +++ /dev/null @@ -1,259 +0,0 @@ -/* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. - */ -#import "ColorScheme.h" -#include "../MinutorMap/blockInfo.h" - -@interface ColorScheme : NSObject { - NSString *name; - unsigned int colors[256]; -} -@property (retain) NSString *name; -@end -@implementation ColorScheme -@synthesize name; -// creating a new color scheme always copies the currently selected one --(id)initWithName:(NSString *)theName -{ - if (self=[super init]) - { - name=[theName retain]; - for (int i=0;i>16; - g=color>>8; - b=color; - double alpha=blocks[i].alpha; - r/=alpha; - g/=alpha; - b/=alpha; - a=alpha*255; - color=(r<<24)|(g<<16)|(b<<8)|a; - colors[i]=color; - } - } - return self; -} --(void)encodeWithCoder:(NSCoder *)encoder -{ - [encoder encodeObject:name forKey:@"name"]; - [encoder encodeArrayOfObjCType:"I" count:255 at:colors]; -} --(id)initWithCoder:(NSCoder *)decoder -{ - if (self=[super init]) - { - name=[[decoder decodeObjectForKey:@"name"] retain]; - [decoder decodeArrayOfObjCType:"I" count:255 at:colors]; - } - return self; - -} --(NSString *)getColorString:(int)idx -{ - return [NSString stringWithFormat:@"#%06x",(colors[idx]>>8)]; -} --(NSString *)getAlphaString:(int)idx -{ - return [NSString stringWithFormat:@"%d",colors[idx]&0xff]; -} --(void)setColor:(unsigned int)color forIndex:(int)idx -{ - colors[idx]&=0xff; - colors[idx]|=color<<8; -} --(void)setAlpha:(unsigned int)alpha forIndex:(int)idx -{ - colors[idx]&=~0xff; - colors[idx]|=alpha&0xff; -} --(unsigned int *)getColors -{ - return colors; -} --(void)dealloc -{ - [name release]; - [super dealloc]; -} -@end - - -@implementation ColorSchemes - --(void)readDefaults -{ - schemes=[[NSMutableArray array] retain]; - - NSArray *s=[[NSUserDefaults standardUserDefaults] arrayForKey:@"colorSchemes"]; - if (s) - { - for (NSData *data in s) - { - ColorScheme *cs=(ColorScheme *)[NSKeyedUnarchiver unarchiveObjectWithData:data]; - [schemes addObject:cs]; - NSMenuItem *item=[[NSMenuItem alloc] initWithTitle:cs.name action:@selector(selectScheme:) keyEquivalent:@""]; - [menu insertItem:item atIndex:[schemes count]]; - [item release]; - } - } - - //setup standard colorscheme - standard=[[ColorScheme alloc] initWithName:@"Standard"]; - selected=0; -} - --(void)select:sender -{ - selected=[menu indexOfItem:sender]; - for (int i=0;i<[menu numberOfItems];i++) - { - [[menu itemAtIndex:i] setState:NSOffState]; - } - [[menu itemAtIndex:selected] setState:NSOnState]; -} --(unsigned int *)current -{ - if (selected==0) - return [standard getColors]; - ColorScheme *cs=[schemes objectAtIndex:selected-1]; - return [cs getColors]; -} - --(void)saveDefaults -{ - NSUserDefaults *def=[NSUserDefaults standardUserDefaults]; - NSMutableArray *encoded=[[NSMutableArray alloc] init]; - for (ColorScheme *cs in schemes) - { - [encoded addObject:[NSKeyedArchiver archivedDataWithRootObject:cs]]; - } - [def setObject:encoded forKey:@"colorSchemes"]; -} - --(IBAction)editColorSchemes:sender -{ - [schemesWin makeKeyAndOrderFront:sender]; -} - --(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tc row:(NSInteger)row -{ - if (tv==schemeList) - { - ColorScheme *cs=[schemes objectAtIndex:row]; - return cs.name; - } - if ([[tc identifier] isEqual:@"id"]) - return [NSString stringWithFormat:@"%d.",row+1]; - if ([[tc identifier] isEqual:@"name"]) - return [NSString stringWithCString:blocks[row].name encoding:NSASCIIStringEncoding]; - ColorScheme *cs=[schemes objectAtIndex:[schemeList selectedRow]]; - if ([[tc identifier] isEqual:@"color"]) - return [cs getColorString:row]; - if ([[tc identifier] isEqual:@"alpha"]) - return [cs getAlphaString:row]; - return nil; -} --(void)tableView:(NSTableView *)tv setObjectValue:obj forTableColumn:(NSTableColumn *)tc row:(NSInteger)row -{ - if (tv==schemeList) - { - ColorScheme *cs=[schemes objectAtIndex:row]; - cs.name=obj; - NSMenuItem *item=[menu itemAtIndex:1+row]; - [item setTitle:obj]; - } - else - { - ColorScheme *cs=[schemes objectAtIndex:[schemeList selectedRow]]; - NSString *str=obj; - NSUInteger range=[str rangeOfString:@"#"].location; - if (range!=NSNotFound) - str=[str substringFromIndex:range+1]; - - str=[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; - if ([[tc identifier] isEqual:@"color"]) - { - - unsigned int color; - NSScanner *scan=[NSScanner scannerWithString:str]; - if ([scan scanHexInt:&color]) - [cs setColor:color forIndex:row]; - } - if ([[tc identifier] isEqual:@"alpha"]) - { - id f=[[NSNumberFormatter alloc] init]; - NSNumber *num=[f numberFromString:str]; - [cs setAlpha:[num unsignedIntValue] forIndex:row]; - [f release]; - } - } - [self saveDefaults]; -} --(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView -{ - if (tableView==schemeList) - return [schemes count]; - else - { - return numBlocks; - } -} - --(IBAction) addOrRemove:sender -{ - NSSegmentedControl *seg=sender; - if ([seg selectedSegment]==0) //add - { - ColorScheme *cs=[[ColorScheme alloc] initWithName:@"New Color Scheme"]; - [schemes addObject:cs]; - NSMenuItem *item=[[NSMenuItem alloc] initWithTitle:@"New Color Scheme" action:@selector(selectScheme:) keyEquivalent:@""]; - [menu insertItem:item atIndex:[schemes count]]; - [item release]; - [schemeList reloadData]; - [self saveDefaults]; - } - else - { - NSInteger num=[schemeList selectedRow]; - if (num==-1) - return; - [schemes removeObjectAtIndex:num]; - [menu removeItemAtIndex:num+1]; - [schemeList reloadData]; - [self saveDefaults]; - } -} - --(IBAction) edit:sender -{ - if ([schemeList selectedRow]==-1) return; - [schemeWin makeKeyAndOrderFront:sender]; -} - -@end diff --git a/OSX/English.lproj/InfoPlist.strings b/OSX/English.lproj/InfoPlist.strings deleted file mode 100644 index 477b28ff..00000000 --- a/OSX/English.lproj/InfoPlist.strings +++ /dev/null @@ -1,2 +0,0 @@ -/* Localized versions of Info.plist keys */ - diff --git a/OSX/English.lproj/MainMenu.xib b/OSX/English.lproj/MainMenu.xib deleted file mode 100644 index bb2796a2..00000000 --- a/OSX/English.lproj/MainMenu.xib +++ /dev/null @@ -1,2663 +0,0 @@ - - - - 1050 - 11E53 - 2549 - 1138.47 - 569.00 - - com.apple.InterfaceBuilder.CocoaPlugin - 2549 - - - YES - NSButton - NSButtonCell - NSCustomObject - NSCustomView - NSMenu - NSMenuItem - NSProgressIndicator - NSScrollView - NSScroller - NSSegmentedCell - NSSegmentedControl - NSSlider - NSSliderCell - NSTableColumn - NSTableHeaderView - NSTableView - NSTextField - NSTextFieldCell - NSView - NSWindowTemplate - - - YES - com.apple.InterfaceBuilder.CocoaPlugin - - - PluginDependencyRecalculationVersion - - - - YES - - NSApplication - - - FirstResponder - - - NSApplication - - - AMainMenu - - YES - - - minutor - - 1048576 - 2147483647 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState - - submenuAction: - - minutor - - YES - - - About minutor - - 2147483647 - - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Services - - 1048576 - 2147483647 - - - submenuAction: - - Services - - YES - - _NSServicesMenu - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Hide minutor - h - 1048576 - 2147483647 - - - - - - Hide Others - h - 1572864 - 2147483647 - - - - - - Show All - - 1048576 - 2147483647 - - - - - - YES - YES - - - 1048576 - 2147483647 - - - - - - Quit minutor - q - 1048576 - 2147483647 - - - - - _NSAppleMenu - - - - - File - - 2147483647 - - - submenuAction: - - File - - YES - - - Open World - - 2147483647 - - - submenuAction: - - Open World - - YES - - - - - - Open… - o - 1048576 - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Close - w - 1048576 - 2147483647 - - - - - - - - - View - - 2147483647 - - - submenuAction: - - View - - YES - - - Jump to Spawn - - 2147483647 - - - 101 - - - - Jump to Player - - 2147483647 - - - 102 - - - - YES - YES - - - 2147483647 - - - - - - Nether - - 2147483647 - - - - - - End - - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Lighting - 1 - 262144 - 2147483647 - - - - - - Cave Mode - 2 - 262144 - 2147483647 - - - - - - Hide Obscured - 3 - 262144 - 2147483647 - - - - - - Depth Shading - 4 - 262144 - 2147483647 - - - - - - Show Mob Spawn - 5 - 262144 - 2147483647 - - - - - - - - - Colors - - 2147483647 - - - submenuAction: - - Colors - - YES - - - Standard - - 2147483647 - 1 - - - - - - YES - YES - - - 2147483647 - - - - - - Color Schemes... - - 2147483647 - - - - - - - - - Window - - 2147483647 - - - submenuAction: - - Window - - YES - - - Minimize - m - 1048576 - 2147483647 - - - - - - Zoom - - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Bring All to Front - - 2147483647 - - - - - _NSWindowsMenu - - - - - Help - - 2147483647 - - - submenuAction: - - Help - - YES - - - minutor Help - ? - 1048576 - 2147483647 - - - - - _NSHelpMenu - - - - _NSMainMenu - - - minutorAppDelegate - - - NSFontManager - - - 15 - 2 - {{612, 306}, {496, 453}} - 1685585920 - Window - NSWindow - - - {496, 431} - - - 274 - - YES - - - 266 - {{18, 424}, {419, 21}} - - YES - - -2079981824 - 0 - - - 255 - 0.0 - 0.0 - 0.0 - 0 - 1 - NO - NO - - - - - 274 - {{0, 20}, {496, 400}} - - Map - - - - 265 - {{443, 424}, {33, 22}} - - YES - - -2072904127 - 272630784 - 255 - - LucidaGrande - 13 - 1044 - - - YES - - 6 - System - textBackgroundColor - - 3 - MQA - - - - 6 - System - textColor - - 3 - MAA - - - - - - - 258 - {{5, 2}, {494, 17}} - - YES - - 67239488 - 272631808 - Label - - - - 6 - System - controlColor - - 3 - MC42NjY2NjY2NjY3AA - - - - 6 - System - controlTextColor - - - - - - - 1313 - - {{381, 3}, {96, 12}} - - 24840 - 100 - - - {496, 453} - - {{0, 0}, {1680, 1028}} - {496, 453} - {10000000000000, 10000000000000} - YES - - - MapViewer - - - 15 - 2 - {{196, 287}, {363, 223}} - 1685585920 - Color Schemes - NSWindow - - - - - 256 - - YES - - - 268 - - YES - - - 2304 - - YES - - - 256 - {321, 152} - - YES - - - -2147483392 - {{224, 0}, {16, 17}} - - - YES - - 318 - 40 - 1000 - - 75628096 - 2048 - - - LucidaGrande - 11 - 3100 - - - 3 - MC4zMzMzMzI5ODU2AA - - - 6 - System - headerTextColor - - - - - 337772096 - 2048 - Text Cell - - - - 6 - System - controlBackgroundColor - - - - - 3 - YES - YES - - - - 3 - 2 - - - 6 - System - gridColor - - 3 - MC41AA - - - 17 - -700448768 - - - 4 - 15 - 0 - YES - 0 - 1 - - - {{1, 1}, {321, 152}} - - - - - 4 - - - - -2147483392 - {{224, 17}, {15, 102}} - - - _doScroller: - 0.99425292015075684 - - - - -2147483392 - {{1, 32}, {46, 15}} - - 1 - - _doScroller: - 0.99725282192230225 - - - {{20, 49}, {323, 154}} - - - 133682 - - - - QSAAAEEgAABBmAAAQZgAAA - - - - 268 - {{20, 19}, {67, 23}} - - YES - - 67239424 - 0 - - LucidaGrande - 13 - 16 - - - - YES - - 32 - - NSImage - NSAddTemplate - - - 0 - - - 32 - - NSImage - NSRemoveTemplate - - - 1 - 0 - - - 1 - 2 - 6 - - - - - 268 - {{253, 12}, {96, 32}} - - YES - - 67239424 - 134217728 - Edit - - - -2038284033 - 129 - - - 200 - 25 - - - - {363, 223} - - {{0, 0}, {1680, 1028}} - {10000000000000, 10000000000000} - YES - - - 15 - 2 - {{196, 241}, {512, 269}} - 1685585920 - Color Scheme - NSWindow - - - - - 256 - - YES - - - 268 - - YES - - - 2304 - - YES - - - 256 - {512, 254} - - YES - - - 256 - {512, 17} - - - - - - -2147483392 - {{-26, 0}, {16, 17}} - - - - YES - - id - 40 - 40 - 1000 - - 75628096 - 2048 - ID - - - 3 - MC4zMzMzMzI5ODU2AA - - - - - 67239488 - 2048 - Text Cell - - - - - - 3 - YES - YES - - - - name - 300 - 40 - 1000 - - 75628096 - 2048 - Block Name - - - - - - 67239488 - 2048 - Text Cell - - - - - - 3 - YES - YES - - - - color - 83 - 10 - 3.4028230607370965e+38 - - 75628096 - 2048 - Color - - - 6 - System - headerColor - - - - - - 337772096 - 272630784 - Text - - - - - - 3 - YES - YES - - - - alpha - 77 - 10 - 3.4028230607370965e+38 - - 75628096 - 2048 - Alpha - - - - - - 337772096 - 2048 - Text Cell - - - - - - 3 - YES - YES - - - - 3 - 2 - - - 17 - -163577856 - - - 2 - 4 - 15 - 0 - YES - 0 - 1 - - - {{1, 17}, {512, 254}} - - - - - 4 - - - - -2147483392 - {{498, 17}, {15, 238}} - - - _doScroller: - 0.94094491004943848 - - - - -2147483392 - {{1, 256}, {497, 15}} - - 1 - - _doScroller: - 0.99805068969726562 - - - - 2304 - - YES - - - {{1, 0}, {512, 17}} - - - - - 4 - - - - {{-1, -2}, {514, 272}} - - - 133682 - - - - - QSAAAEEgAABBmAAAQZgAAA - - - {512, 269} - - {{0, 0}, {1680, 1028}} - {10000000000000, 10000000000000} - YES - - - ColorSchemes - - - - - YES - - - terminate: - - - - 449 - - - - orderFrontStandardAboutPanel: - - - - 142 - - - - delegate - - - - 495 - - - - hide: - - - - 367 - - - - hideOtherApplications: - - - - 368 - - - - unhideAllApplications: - - - - 370 - - - - showHelp: - - - - 493 - - - - performClose: - - - - 609 - - - - performMiniaturize: - - - - 655 - - - - performZoom: - - - - 656 - - - - arrangeInFront: - - - - 659 - - - - mapViewer - - - - 567 - - - - openWorld: - - - - 628 - - - - jumpToSpawn: - - - - 657 - - - - jumpToPlayer: - - - - 658 - - - - toggleLighting: - - - - 665 - - - - toggleCaveMode: - - - - 666 - - - - toggleObscured: - - - - 667 - - - - toggleDepth: - - - - 668 - - - - selectScheme: - - - - 737 - - - - colorSchemes - - - - 744 - - - - toggleHell: - - - - 754 - - - - worldMenu - - - - 758 - - - - hellItem - - - - 761 - - - - enderItem - - - - 762 - - - - toggleEnder: - - - - 763 - - - - toggleMob: - - - - 768 - - - - window - - - - 566 - - - - map - - - - 573 - - - - slider - - - - 574 - - - - sliderChanged: - - - - 583 - - - - depthText - - - - 587 - - - - status - - - - 635 - - - - progressBar - - - - 756 - - - - dataSource - - - - 745 - - - - dataSource - - - - 748 - - - - menu - - - - 739 - - - - schemeList - - - - 740 - - - - schemesWin - - - - 741 - - - - addOrRemove: - - - - 742 - - - - editColorSchemes: - - - - 743 - - - - edit: - - - - 746 - - - - schemeWin - - - - 747 - - - - - YES - - 0 - - YES - - - - - - -2 - - - File's Owner - - - -1 - - - First Responder - - - -3 - - - Application - - - 29 - - - YES - - - - - - - - - - - 56 - - - YES - - - - - - 420 - - - - - 490 - - - YES - - - - - - 491 - - - YES - - - - - - 492 - - - - - 494 - - - - - 559 - - - YES - - - - - - 560 - - - YES - - - - - - - - - - 564 - - - - - 568 - - - YES - - - - - - 569 - - - - - 572 - - - YES - - - - - 576 - - - YES - - - - - - 577 - - - YES - - - - - 57 - - - YES - - - - - - - - - - - - - - 145 - - - - - 149 - - - - - 131 - - - YES - - - - - - 130 - - - - - 236 - - - - - 144 - - - - - 136 - - - - - 150 - - - - - 134 - - - - - 58 - - - - - 592 - - - YES - - - - - - 593 - - - YES - - - - - - - - - 595 - - - - - 597 - - - - - 598 - - - - - 616 - - - YES - - - - - - 617 - - - YES - - - - - 633 - - - YES - - - - - - 634 - - - - - 644 - - - YES - - - - - - 645 - - - YES - - - - - - - - - - - - - - - - 646 - - - - - 647 - - - - - 648 - - - YES - - - - - - 649 - - - YES - - - - - - - - - 650 - - - - - 651 - - - - - 652 - - - - - 653 - - - - - 660 - - - - - 661 - - - - - 662 - - - - - 663 - - - - - 664 - - - - - 669 - - - YES - - - - - - 670 - - - YES - - - - - - - - 671 - - - YES - - - - - - - - 672 - - - - - 673 - - - - - 674 - - - YES - - - - - - 676 - - - YES - - - - - - 679 - - - - - 690 - - - YES - - - - - - 691 - - - - - 692 - - - YES - - - - - - 693 - - - YES - - - - - - 694 - - - YES - - - - - - - - - 695 - - - - - 696 - - - - - 697 - - - YES - - - - - - - - - 698 - - - - - 699 - - - YES - - - - - - 700 - - - YES - - - - - - 701 - - - - - 702 - - - - - 703 - - - YES - - - - - - 709 - - - YES - - - - - - 710 - - - YES - - - - - - - - 711 - - - - - 712 - - - - - 713 - - - - - 714 - - - YES - - - - - - 715 - - - - - 738 - - - - - 749 - - - YES - - - - - - 750 - - - - - 751 - - - - - 752 - - - - - 753 - - - - - 755 - - - - - 760 - - - - - 767 - - - - - - - YES - - YES - -1.IBPluginDependency - -2.IBPluginDependency - -3.IBPluginDependency - 130.IBPluginDependency - 131.IBPluginDependency - 134.IBPluginDependency - 136.IBPluginDependency - 144.IBPluginDependency - 145.IBPluginDependency - 149.IBPluginDependency - 150.IBPluginDependency - 236.IBPluginDependency - 29.IBPluginDependency - 420.IBPluginDependency - 490.IBPluginDependency - 491.IBPluginDependency - 492.IBPluginDependency - 494.IBPluginDependency - 559.IBPluginDependency - 559.IBWindowTemplateEditedContentRect - 559.NSWindowTemplate.visibleAtLaunch - 56.IBPluginDependency - 560.IBPluginDependency - 564.IBPluginDependency - 568.IBPluginDependency - 569.IBPluginDependency - 57.IBPluginDependency - 572.IBPluginDependency - 576.IBPluginDependency - 577.IBPluginDependency - 58.IBPluginDependency - 592.IBPluginDependency - 593.IBPluginDependency - 595.IBPluginDependency - 597.IBPluginDependency - 598.IBPluginDependency - 616.IBPluginDependency - 617.IBPluginDependency - 633.IBPluginDependency - 634.IBPluginDependency - 644.IBPluginDependency - 645.IBPluginDependency - 646.IBPluginDependency - 647.IBPluginDependency - 648.IBPluginDependency - 649.IBPluginDependency - 650.IBPluginDependency - 651.IBPluginDependency - 652.IBPluginDependency - 653.IBPluginDependency - 660.IBPluginDependency - 661.IBPluginDependency - 662.IBPluginDependency - 663.IBPluginDependency - 664.IBPluginDependency - 669.IBPluginDependency - 669.IBWindowTemplateEditedContentRect - 669.NSWindowTemplate.visibleAtLaunch - 670.IBPluginDependency - 671.IBPluginDependency - 672.IBPluginDependency - 673.IBPluginDependency - 674.IBPluginDependency - 676.IBPluginDependency - 679.IBPluginDependency - 690.IBPluginDependency - 691.IBPluginDependency - 691.IBSegmentedControlInspectorSelectedSegmentMetadataKey - 692.IBPluginDependency - 692.IBWindowTemplateEditedContentRect - 692.NSWindowTemplate.visibleAtLaunch - 693.IBPluginDependency - 694.IBPluginDependency - 695.IBPluginDependency - 696.IBPluginDependency - 697.IBPluginDependency - 698.IBPluginDependency - 699.IBPluginDependency - 700.IBPluginDependency - 701.IBPluginDependency - 702.IBPluginDependency - 703.IBPluginDependency - 709.IBPluginDependency - 710.IBPluginDependency - 711.IBPluginDependency - 712.IBPluginDependency - 713.IBPluginDependency - 714.IBPluginDependency - 715.IBPluginDependency - 738.IBPluginDependency - 749.IBPluginDependency - 750.IBPluginDependency - 751.IBPluginDependency - 752.IBPluginDependency - 753.IBPluginDependency - 755.IBPluginDependency - 760.IBPluginDependency - 767.IBPluginDependency - - - YES - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{371, 92}, {496, 453}} - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{783, 319}, {363, 223}} - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - {{306, 484}, {512, 269}} - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - - - YES - - - - - - YES - - - - - 768 - - - - YES - - ColorSchemes - NSObject - - YES - - YES - addOrRemove: - edit: - editColorSchemes: - - - YES - id - id - id - - - - YES - - YES - addOrRemove: - edit: - editColorSchemes: - - - YES - - addOrRemove: - id - - - edit: - id - - - editColorSchemes: - id - - - - - YES - - YES - menu - schemeList - schemeWin - schemesWin - - - YES - id - id - id - id - - - - YES - - YES - menu - schemeList - schemeWin - schemesWin - - - YES - - menu - id - - - schemeList - id - - - schemeWin - id - - - schemesWin - id - - - - - IBProjectSource - ./Classes/ColorSchemes.h - - - - Map - NSView - - IBProjectSource - ./Classes/Map.h - - - - MapViewer - NSObject - - sliderChanged: - NSSlider - - - sliderChanged: - - sliderChanged: - NSSlider - - - - YES - - YES - depthText - map - progressBar - slider - status - window - - - YES - id - Map - id - id - id - id - - - - YES - - YES - depthText - map - progressBar - slider - status - window - - - YES - - depthText - id - - - map - Map - - - progressBar - id - - - slider - id - - - status - id - - - window - id - - - - - IBProjectSource - ./Classes/MapViewer.h - - - - minutorAppDelegate - NSObject - - YES - - YES - jumpToPlayer: - jumpToSpawn: - openWorld: - selectScheme: - toggleCaveMode: - toggleDepth: - toggleEnder: - toggleHell: - toggleLighting: - toggleMob: - toggleObscured: - - - YES - id - id - id - id - id - id - id - id - id - id - id - - - - YES - - YES - jumpToPlayer: - jumpToSpawn: - openWorld: - selectScheme: - toggleCaveMode: - toggleDepth: - toggleEnder: - toggleHell: - toggleLighting: - toggleMob: - toggleObscured: - - - YES - - jumpToPlayer: - id - - - jumpToSpawn: - id - - - openWorld: - id - - - selectScheme: - id - - - toggleCaveMode: - id - - - toggleDepth: - id - - - toggleEnder: - id - - - toggleHell: - id - - - toggleLighting: - id - - - toggleMob: - id - - - toggleObscured: - id - - - - - YES - - YES - colorSchemes - enderItem - hellItem - mapViewer - worldMenu - - - YES - id - id - id - id - id - - - - YES - - YES - colorSchemes - enderItem - hellItem - mapViewer - worldMenu - - - YES - - colorSchemes - id - - - enderItem - id - - - hellItem - id - - - mapViewer - id - - - worldMenu - id - - - - - IBProjectSource - ./Classes/minutorAppDelegate.h - - - - - 0 - IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 - - - YES - 3 - - YES - - YES - NSAddTemplate - NSMenuCheckmark - NSMenuMixedState - NSRemoveTemplate - - - YES - {8, 8} - {11, 11} - {10, 3} - {8, 8} - - - - diff --git a/OSX/Map.m b/OSX/Map.m deleted file mode 100644 index 67aa8658..00000000 --- a/OSX/Map.m +++ /dev/null @@ -1,267 +0,0 @@ -/* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Map.h" -#include "MinutorMap.h" - -#define MINZOOM 1.0 -#define MAXZOOM 10.0 - - -@implementation Map - -- (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - if (self) { - curX=0.0; - curZ=0.0; - curDepth=255; - curScale=1.0; - world=nil; - curWidth=496; - curHeight=400; - moving=0; - bits=malloc(curWidth*curHeight*4); - } - return self; -} - -static id progressBar; -- (void)setProgress:(id)progress -{ - progressBar=progress; -} - -void updateProgress(float progress) -{ - [progressBar setDoubleValue:progress*100.0]; - [progressBar displayIfNeeded]; -} - -- (void)drawRect:(NSRect)dirtyRect { - if (world==nil) return; - - if (curWidth!=dirtyRect.size.width || curHeight!=dirtyRect.size.height) - { - curWidth=dirtyRect.size.width; - curHeight=dirtyRect.size.height; - bits=realloc(bits, curWidth*curHeight*4); - } - - NSRect myRect = NSMakeRect(0,0,curWidth,curHeight); - - - DrawMap([world UTF8String], curX, curZ, curDepth, curWidth, curHeight, curScale, bits, opts, updateProgress); - NSBitmapImageRep *mapImage=[[NSBitmapImageRep alloc] - initWithBitmapDataPlanes:&bits - pixelsWide:curWidth - pixelsHigh:curHeight - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:NSAlphaNonpremultipliedBitmapFormat - bytesPerRow:curWidth*4 - bitsPerPixel:32]; - - [mapImage drawInRect: myRect]; - [mapImage release]; - updateProgress(0.0); -} - -- (BOOL)acceptsFirstResponder -{ - return YES; -} -- (void)mouseDragged:(NSEvent *)theEvent -{ - curX-=[theEvent deltaX]/curScale; - curZ-=[theEvent deltaY]/curScale; - [self setNeedsDisplay:YES]; -} -- (void)mouseMoved:(NSEvent *)theEvent -{ - NSPoint loc=[self convertPoint:[theEvent locationInWindow] fromView:nil]; - loc.y=curHeight-loc.y; - if (loc.y>=0 && loc.x>=0 && loc.y0.0) - { - curScale+=dy/10.0; - if (curScale>MAXZOOM) curScale=MAXZOOM; - [self setNeedsDisplay:YES]; - } -} - -- (void)keyDown:(NSEvent *)theEvent -{ - NSString *characters=[theEvent characters]; - unichar character=[characters characterAtIndex:0]; - BOOL changed=NO; - - switch (character) - { - case NSUpArrowFunctionKey: - case 'w': - moving|=1; - break; - case NSDownArrowFunctionKey: - case 's': - moving|=2; - break; - case NSLeftArrowFunctionKey: - case 'a': - moving|=4; - break; - case NSRightArrowFunctionKey: - case 'd': - moving|=8; - break; - case NSPageUpFunctionKey: - case 'e': - curScale+=0.5; - if (curScale>MAXZOOM) - curScale=MAXZOOM; - changed=YES; - break; - case NSPageDownFunctionKey: - case 'q': - curScale-=0.5; - if (curScale - - - - CFBundleDevelopmentRegion - English - CFBundleDocumentTypes - - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIconFile - icon.icns - CFBundleIdentifier - com.seancode.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.6.3 - CFBundleSignature - ???? - CFBundleURLTypes - - CFBundleVersion - 1.6.3 - LSApplicationCategoryType - public.app-category.entertainment - LSMinimumSystemVersion - ${MACOSX_DEPLOYMENT_TARGET} - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication - NSServices - - UTExportedTypeDeclarations - - UTImportedTypeDeclarations - - - diff --git a/OSX/minutor.xcodeproj/project.pbxproj b/OSX/minutor.xcodeproj/project.pbxproj deleted file mode 100644 index fdda30bb..00000000 --- a/OSX/minutor.xcodeproj/project.pbxproj +++ /dev/null @@ -1,402 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 14A14F84124BD800002E2FA9 /* Map.m in Sources */ = {isa = PBXBuildFile; fileRef = 14A14F83124BD800002E2FA9 /* Map.m */; }; - 14A14F99124BDC27002E2FA9 /* cache.c in Sources */ = {isa = PBXBuildFile; fileRef = 14A14F92124BDC27002E2FA9 /* cache.c */; }; - 14A14F9A124BDC27002E2FA9 /* MinutorMap.c in Sources */ = {isa = PBXBuildFile; fileRef = 14A14F94124BDC27002E2FA9 /* MinutorMap.c */; }; - 14A14F9B124BDC27002E2FA9 /* nbt.c in Sources */ = {isa = PBXBuildFile; fileRef = 14A14F96124BDC27002E2FA9 /* nbt.c */; }; - 14A14FA2124BDCAA002E2FA9 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 14A14FA1124BDCAA002E2FA9 /* libz.dylib */; }; - 14A15134124C11F2002E2FA9 /* icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 14A15133124C11F2002E2FA9 /* icon.icns */; }; - 14D1F3E2124ACEF8008A7C07 /* MapViewer.m in Sources */ = {isa = PBXBuildFile; fileRef = 14D1F3E1124ACEF8008A7C07 /* MapViewer.m */; }; - 14EC3C4E127B5E33001B3B24 /* ColorScheme.m in Sources */ = {isa = PBXBuildFile; fileRef = 14EC3C4D127B5E33001B3B24 /* ColorScheme.m */; }; - 1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; }; - 256AC3DA0F4B6AC300CF3369 /* minutorAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* minutorAppDelegate.m */; }; - 31A4926613174ACB00719F98 /* region.c in Sources */ = {isa = PBXBuildFile; fileRef = 31A4926513174ACB00719F98 /* region.c */; }; - 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; - 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; - 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; - 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; - 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; - 145BC0FA1251164B005AED91 /* MinutorMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MinutorMap.h; path = ../MinutorMap/MinutorMap.h; sourceTree = SOURCE_ROOT; }; - 14A14F82124BD800002E2FA9 /* Map.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Map.h; sourceTree = ""; }; - 14A14F83124BD800002E2FA9 /* Map.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Map.m; sourceTree = ""; }; - 14A14F91124BDC27002E2FA9 /* blockInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = blockInfo.h; path = ../MinutorMap/blockInfo.h; sourceTree = ""; }; - 14A14F92124BDC27002E2FA9 /* cache.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cache.c; path = ../MinutorMap/cache.c; sourceTree = ""; }; - 14A14F93124BDC27002E2FA9 /* cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cache.h; path = ../MinutorMap/cache.h; sourceTree = ""; }; - 14A14F94124BDC27002E2FA9 /* MinutorMap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = MinutorMap.c; path = ../MinutorMap/MinutorMap.c; sourceTree = ""; }; - 14A14F96124BDC27002E2FA9 /* nbt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = nbt.c; path = ../MinutorMap/nbt.c; sourceTree = ""; }; - 14A14F97124BDC27002E2FA9 /* nbt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = nbt.h; path = ../MinutorMap/nbt.h; sourceTree = ""; }; - 14A14F98124BDC27002E2FA9 /* stdafx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stdafx.h; path = ../MinutorMap/stdafx.h; sourceTree = ""; }; - 14A14FA1124BDCAA002E2FA9 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; - 14A15133124C11F2002E2FA9 /* icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icon.icns; sourceTree = ""; }; - 14D1F3E0124ACEF8008A7C07 /* MapViewer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewer.h; sourceTree = ""; }; - 14D1F3E1124ACEF8008A7C07 /* MapViewer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewer.m; sourceTree = ""; }; - 14EC3C4C127B5E33001B3B24 /* ColorScheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorScheme.h; sourceTree = ""; }; - 14EC3C4D127B5E33001B3B24 /* ColorScheme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorScheme.m; sourceTree = ""; }; - 1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; }; - 256AC3D80F4B6AC300CF3369 /* minutorAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = minutorAppDelegate.h; sourceTree = ""; }; - 256AC3D90F4B6AC300CF3369 /* minutorAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = minutorAppDelegate.m; sourceTree = ""; }; - 256AC3F00F4B6AF500CF3369 /* minutor_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = minutor_Prefix.pch; sourceTree = ""; }; - 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; - 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; - 31A4926513174ACB00719F98 /* region.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = region.c; path = ../MinutorMap/region.c; sourceTree = SOURCE_ROOT; }; - 31A4926713174AD600719F98 /* region.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = region.h; path = ../MinutorMap/region.h; sourceTree = SOURCE_ROOT; }; - 8D1107310486CEB800E47090 /* minutor-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "minutor-Info.plist"; sourceTree = ""; }; - 8D1107320486CEB800E47090 /* minutor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = minutor.app; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 8D11072E0486CEB800E47090 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, - 14A14FA2124BDCAA002E2FA9 /* libz.dylib in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 080E96DDFE201D6D7F000001 /* Classes */ = { - isa = PBXGroup; - children = ( - 145BC0FB12511655005AED91 /* MinutorMap */, - 256AC3D80F4B6AC300CF3369 /* minutorAppDelegate.h */, - 256AC3D90F4B6AC300CF3369 /* minutorAppDelegate.m */, - 14D1F3E0124ACEF8008A7C07 /* MapViewer.h */, - 14D1F3E1124ACEF8008A7C07 /* MapViewer.m */, - 14A14F82124BD800002E2FA9 /* Map.h */, - 14A14F83124BD800002E2FA9 /* Map.m */, - 14A14FA1124BDCAA002E2FA9 /* libz.dylib */, - 14EC3C4C127B5E33001B3B24 /* ColorScheme.h */, - 14EC3C4D127B5E33001B3B24 /* ColorScheme.m */, - ); - name = Classes; - sourceTree = ""; - }; - 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { - isa = PBXGroup; - children = ( - 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, - ); - name = "Linked Frameworks"; - sourceTree = ""; - }; - 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { - isa = PBXGroup; - children = ( - 29B97324FDCFA39411CA2CEA /* AppKit.framework */, - 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */, - 29B97325FDCFA39411CA2CEA /* Foundation.framework */, - ); - name = "Other Frameworks"; - sourceTree = ""; - }; - 145BC0FB12511655005AED91 /* MinutorMap */ = { - isa = PBXGroup; - children = ( - 31A4926713174AD600719F98 /* region.h */, - 31A4926513174ACB00719F98 /* region.c */, - 14A14F91124BDC27002E2FA9 /* blockInfo.h */, - 14A14F92124BDC27002E2FA9 /* cache.c */, - 14A14F93124BDC27002E2FA9 /* cache.h */, - 145BC0FA1251164B005AED91 /* MinutorMap.h */, - 14A14F94124BDC27002E2FA9 /* MinutorMap.c */, - 14A14F96124BDC27002E2FA9 /* nbt.c */, - 14A14F97124BDC27002E2FA9 /* nbt.h */, - 14A14F98124BDC27002E2FA9 /* stdafx.h */, - ); - name = MinutorMap; - sourceTree = ""; - }; - 19C28FACFE9D520D11CA2CBB /* Products */ = { - isa = PBXGroup; - children = ( - 8D1107320486CEB800E47090 /* minutor.app */, - ); - name = Products; - sourceTree = ""; - }; - 29B97314FDCFA39411CA2CEA /* minutor */ = { - isa = PBXGroup; - children = ( - 14A15133124C11F2002E2FA9 /* icon.icns */, - 080E96DDFE201D6D7F000001 /* Classes */, - 29B97315FDCFA39411CA2CEA /* Other Sources */, - 29B97317FDCFA39411CA2CEA /* Resources */, - 29B97323FDCFA39411CA2CEA /* Frameworks */, - 19C28FACFE9D520D11CA2CBB /* Products */, - ); - name = minutor; - sourceTree = ""; - }; - 29B97315FDCFA39411CA2CEA /* Other Sources */ = { - isa = PBXGroup; - children = ( - 256AC3F00F4B6AF500CF3369 /* minutor_Prefix.pch */, - 29B97316FDCFA39411CA2CEA /* main.m */, - ); - name = "Other Sources"; - sourceTree = ""; - }; - 29B97317FDCFA39411CA2CEA /* Resources */ = { - isa = PBXGroup; - children = ( - 8D1107310486CEB800E47090 /* minutor-Info.plist */, - 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, - 1DDD58140DA1D0A300B32029 /* MainMenu.xib */, - ); - name = Resources; - sourceTree = ""; - }; - 29B97323FDCFA39411CA2CEA /* Frameworks */ = { - isa = PBXGroup; - children = ( - 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, - 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, - ); - name = Frameworks; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 8D1107260486CEB800E47090 /* minutor */ = { - isa = PBXNativeTarget; - buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "minutor" */; - buildPhases = ( - 8D1107290486CEB800E47090 /* Resources */, - 8D11072C0486CEB800E47090 /* Sources */, - 8D11072E0486CEB800E47090 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = minutor; - productInstallPath = "$(HOME)/Applications"; - productName = minutor; - productReference = 8D1107320486CEB800E47090 /* minutor.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 29B97313FDCFA39411CA2CEA /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0440; - ORGANIZATIONNAME = "Sean Kasun"; - }; - buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "minutor" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 1; - knownRegions = ( - English, - Japanese, - French, - German, - ); - mainGroup = 29B97314FDCFA39411CA2CEA /* minutor */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 8D1107260486CEB800E47090 /* minutor */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 8D1107290486CEB800E47090 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, - 1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */, - 14A15134124C11F2002E2FA9 /* icon.icns in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 8D11072C0486CEB800E47090 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8D11072D0486CEB800E47090 /* main.m in Sources */, - 256AC3DA0F4B6AC300CF3369 /* minutorAppDelegate.m in Sources */, - 14D1F3E2124ACEF8008A7C07 /* MapViewer.m in Sources */, - 14A14F84124BD800002E2FA9 /* Map.m in Sources */, - 14A14F99124BDC27002E2FA9 /* cache.c in Sources */, - 14A14F9A124BDC27002E2FA9 /* MinutorMap.c in Sources */, - 14A14F9B124BDC27002E2FA9 /* nbt.c in Sources */, - 14EC3C4E127B5E33001B3B24 /* ColorScheme.m in Sources */, - 31A4926613174ACB00719F98 /* region.c in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { - isa = PBXVariantGroup; - children = ( - 089C165DFE840E0CC02AAC07 /* English */, - ); - name = InfoPlist.strings; - sourceTree = ""; - }; - 1DDD58140DA1D0A300B32029 /* MainMenu.xib */ = { - isa = PBXVariantGroup; - children = ( - 1DDD58150DA1D0A300B32029 /* English */, - ); - name = MainMenu.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 148DE24F1283497800B6DF83 /* Release Intel */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - CODE_SIGN_IDENTITY = "Don't Code Sign"; - CURRENT_PROJECT_VERSION = 0.9.3; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - INSTALL_PATH = ""; - MACOSX_DEPLOYMENT_TARGET = 10.7; - PRODUCT_NAME = minutor; - SDKROOT = macosx; - VALID_ARCHS = "i386 x86_64"; - }; - name = "Release Intel"; - }; - 148DE2501283497800B6DF83 /* Release Intel */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = minutor_Prefix.pch; - INFOPLIST_FILE = "minutor-Info.plist"; - INSTALL_PATH = "$(HOME)/Applications"; - MACOSX_DEPLOYMENT_TARGET = 10.6; - PRODUCT_NAME = minutor; - SDKROOT = macosx10.7; - }; - name = "Release Intel"; - }; - C01FCF4B08A954540054247B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - GCC_DYNAMIC_NO_PIC = NO; - GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = minutor_Prefix.pch; - INFOPLIST_FILE = "minutor-Info.plist"; - INSTALL_PATH = "$(HOME)/Applications"; - MACOSX_DEPLOYMENT_TARGET = 10.6; - PRODUCT_NAME = minutor; - SDKROOT = macosx10.7; - }; - name = Debug; - }; - C01FCF4C08A954540054247B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = minutor_Prefix.pch; - INFOPLIST_FILE = "minutor-Info.plist"; - INSTALL_PATH = "$(HOME)/Applications"; - MACOSX_DEPLOYMENT_TARGET = 10.6; - PRODUCT_NAME = minutor; - SDKROOT = macosx10.7; - }; - name = Release; - }; - C01FCF4F08A954540054247B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - CODE_SIGN_IDENTITY = "Don't Code Sign"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - C01FCF5008A954540054247B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - CODE_SIGN_IDENTITY = "Don't Code Sign"; - CURRENT_PROJECT_VERSION = 0.9.3; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - INSTALL_PATH = ""; - MACOSX_DEPLOYMENT_TARGET = 10.7; - PRODUCT_NAME = minutor; - SDKROOT = macosx10.7; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "minutor" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C01FCF4B08A954540054247B /* Debug */, - C01FCF4C08A954540054247B /* Release */, - 148DE2501283497800B6DF83 /* Release Intel */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - C01FCF4E08A954540054247B /* Build configuration list for PBXProject "minutor" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C01FCF4F08A954540054247B /* Debug */, - C01FCF5008A954540054247B /* Release */, - 148DE24F1283497800B6DF83 /* Release Intel */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; -} diff --git a/OSX/minutorAppDelegate.m b/OSX/minutorAppDelegate.m deleted file mode 100644 index a4589845..00000000 --- a/OSX/minutorAppDelegate.m +++ /dev/null @@ -1,160 +0,0 @@ -/* - Copyright (c) 2011, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "minutorAppDelegate.h" -#import "MapViewer.h" -#include "MinutorMap.h" - -@implementation minutorAppDelegate - - -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - opts=0; - [colorSchemes readDefaults]; - - worldPaths=[[NSMutableArray alloc] initWithCapacity:10]; - NSArray *paths=NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); - NSString *root=[paths objectAtIndex:0]; - root=[root stringByAppendingPathComponent:@"minecraft/saves"]; - - id files=[NSFileManager defaultManager]; - id subs=[files contentsOfDirectoryAtPath:root error:NULL]; - for (NSString *f in subs) - { - NSString *path=[root stringByAppendingPathComponent:f]; - BOOL isDirectory; - BOOL exists=[files fileExistsAtPath:path isDirectory:&isDirectory]; - if (exists && isDirectory) - { - [worldPaths addObject:path]; - NSMenuItem *item=[[NSMenuItem alloc] initWithTitle:f action:@selector(openWorld:) keyEquivalent:@""]; - [item setTag:[worldPaths count]]; - [worldMenu insertItem:item atIndex:[worldPaths count]-1]; - [item release]; - } - } -} - -- (BOOL)validateMenuItem:(NSMenuItem *)menuItem -{ - int tag=[menuItem tag]; - if (tag!=0) - { - if (tag>100) - return [mapViewer isVisible]; - id files=[NSFileManager defaultManager]; - BOOL isDirectory; - BOOL exists=[files fileExistsAtPath:[worldPaths objectAtIndex:tag-1] isDirectory:&isDirectory]; - if (exists && isDirectory) - return YES; - return NO; - } - return YES; -} - -- (IBAction) openWorld:sender -{ - NSString *world=nil; - int tag=[sender tag]; - if (tag==0) - { - id fileTypes=[NSArray arrayWithObject:@"dat"]; - id openDlg=[NSOpenPanel openPanel]; - [openDlg setCanChooseFiles:YES]; - [openDlg setAllowedFileTypes:fileTypes]; - if ([openDlg runModal]==NSOKButton) - world=[[openDlg filename] stringByDeletingLastPathComponent]; - } - else - world=[worldPaths objectAtIndex:tag-1]; - if (world!=nil) - [mapViewer openWorld:world]; -} --(IBAction) jumpToSpawn:sender -{ - [mapViewer jumpToSpawn]; -} --(IBAction) jumpToPlayer:sender -{ - [mapViewer jumpToPlayer]; -} --(IBAction) toggleLighting:sender -{ - opts^=LIGHTING; - [sender setState:((opts&LIGHTING)!=0)?NSOnState:NSOffState]; - [mapViewer setOpts:opts]; -} --(IBAction) toggleCaveMode:sender -{ - opts^=CAVEMODE; - [sender setState:((opts&CAVEMODE)!=0)?NSOnState:NSOffState]; - [mapViewer setOpts:opts]; -} --(IBAction) toggleObscured:sender -{ - opts^=HIDEOBSCURED; - [sender setState:((opts&HIDEOBSCURED)!=0)?NSOnState:NSOffState]; - [mapViewer setOpts:opts]; -} --(IBAction) toggleDepth:sender -{ - opts^=DEPTHSHADING; - [sender setState:((opts&DEPTHSHADING)!=0)?NSOnState:NSOffState]; - [mapViewer setOpts:opts]; -} --(IBAction) toggleMob:sender -{ - opts^=MOB; - [sender setState:((opts&MOB)!=0)?NSOnState:NSOffState]; - [mapViewer setOpts:opts]; -} --(IBAction) toggleHell:sender -{ - opts^=HELL; - opts&=~ENDER; - [sender setState:((opts&HELL)!=0)?NSOnState:NSOffState]; - [enderItem setState:NSOffState]; - CloseAll(); - [mapViewer setOpts:opts]; -} --(IBAction) toggleEnder:sender -{ - opts^=ENDER; - opts&=~HELL; - [sender setState:((opts&ENDER)!=0)?NSOnState:NSOffState]; - [hellItem setState:NSOffState]; - CloseAll(); - [mapViewer setOpts:opts]; -} - --(IBAction)selectScheme:sender -{ - [colorSchemes select:sender]; - [mapViewer setColorScheme:[colorSchemes current]]; -} - -@end diff --git a/OSX/minutor_Prefix.pch b/OSX/minutor_Prefix.pch deleted file mode 100644 index 24b0f271..00000000 --- a/OSX/minutor_Prefix.pch +++ /dev/null @@ -1,7 +0,0 @@ -// -// Prefix header for all source files of the 'Minutor' target -// - -#ifdef __OBJC__ - #import -#endif diff --git a/README b/README index b9f9197c..d1beb2e4 100644 --- a/README +++ b/README @@ -1,50 +1,17 @@ -All 3 platform source files are here. -MinutorMap/ contains the map generating code used by all 3 versions. (in C) -Win/ contains the Windows UI (in C++) -OSX/ contains the OSX UI (in ObjC) -./ contains the GTK UI. (in C) +This is the source code for Minutor 2.0 (beta) +web/ contains the source code for the web-based pack builder. The live version +can be found at http://seancode.com/minutor/packs + +The Makefile inside web/ will use the Closure Compiler to compile all the .js files +into a single editor.min.js. To host the pack builder on your own website, you +only need editor.min.js, index.html, main.css, and the mods/ folder. COMPILING: --------- -Windows - (You can compile this with Visual Studio Express 2010) - Open Minutorwin.sln in Visual C++, switch the target to Release, compile the solution to - generate Minutor.exe - Run make_installer.bat to make the minutor.msi installer. - (This part requires you to install WiX) - -OSX - - Open minutor.xcodeproj in XCode. Compile the solution to - generate minutor.app - Run DiskUtility to create a dmg. Put app in dmg. :) - -Linux - - $ make - $ sudo make install - -Linux .deb creation - - first you need to create a pbuilder environment for Lucid (10.04 LTS). - - $ pbuilder-dist lucid create - - if you're on amd64 and want to create an i386 version, do this too: - - $ pbuilder-dist lucid i386 create - - once that's done, you won't need to do that again, except maybe - to run pbuilder-dist lucid update to install new patches - Next we need to build the tar.gz and .dsc - - $ cd minutor - $ debuild -S -us - - (-us means don't sign the .dsc) - Finally we want to compile the .dsc and tar.gz into a .deb - - $ cd .. - $ pbuilder-dist lucid build *.dsc - - and if we want to do it for i386 on amd64: - - $ pbuilder-dist lucid i386 build *.dsc +All Platforms: +Use QtCreator (Qt5 version) and open minutor.pro. Change kit to Release. Build. +Linux: +If you'd rather use the command line, run qmake to generate a Makefile from +minutor.pro, then run make \ No newline at end of file diff --git a/Win/ColorSchemes.cpp b/Win/ColorSchemes.cpp deleted file mode 100644 index 409c9b62..00000000 --- a/Win/ColorSchemes.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "stdafx.h" -#include -#include "Resource.h" -#include "../MinutorMap/blockInfo.h" -#include "ColorSchemes.h" - - -#define COLORKEY L"Software\\Sean Kasun\\Minutor\\ColorSchemes" - -ColorManager::ColorManager() -{ - RegCreateKeyEx(HKEY_CURRENT_USER,COLORKEY,0,NULL, - REG_OPTION_NON_VOLATILE,KEY_READ|KEY_WRITE,NULL,&key,NULL); -} -ColorManager::~ColorManager() -{ - RegCloseKey(key); -} - -void ColorManager::Init(ColorScheme *cs) -{ - for (int i=0;i>16; - g=color>>8; - b=color; - double alpha=blocks[i].alpha; - r=(unsigned char)(r/alpha); - g=(unsigned char)(g/alpha); - b=(unsigned char)(b/alpha); - a=(unsigned char)(alpha*255); - color=(r<<24)|(g<<16)|(b<<8)|a; - cs->colors[i]=color; - } -} -void ColorManager::create(ColorScheme *cs) -{ - DWORD schemeId,len; - len=sizeof(schemeId); - long result=RegQueryValueEx(key,L"schemeId",NULL,NULL,(LPBYTE)&schemeId,&len); - if (result==ERROR_FILE_NOT_FOUND) - schemeId=0; - schemeId++; - RegSetValueEx(key,L"schemeId",NULL,REG_DWORD,(LPBYTE)&schemeId,sizeof(schemeId)); - ColorManager::Init(cs); - cs->id=schemeId; - save(cs); -} -int ColorManager::next(int id,ColorScheme *cs) -{ - TCHAR name[50]; - DWORD nameLen; - DWORD type,csLen; - do { - nameLen=50; - csLen=sizeof(ColorScheme); - LONG result=RegEnumValue(key,id,name,&nameLen,NULL,&type,(LPBYTE)cs,&csLen); - id++; - if (result==ERROR_NO_MORE_ITEMS) - return 0; - if (type==REG_BINARY) - return id; - } while (1); -} -void ColorManager::save(ColorScheme *cs) -{ - wchar_t keyname[50]; - swprintf(keyname,50,L"scheme %d",cs->id); - RegSetValueEx(key,keyname,NULL,REG_BINARY,(LPBYTE)cs,sizeof(ColorScheme)); -} -void ColorManager::load(ColorScheme *cs) -{ - wchar_t keyname[50]; - swprintf(keyname,50,L"scheme %d",cs->id); - DWORD csLen=sizeof(ColorScheme); - RegQueryValueEx(key,keyname,NULL,NULL,(LPBYTE)cs,&csLen); -} -void ColorManager::remove(int id) -{ - wchar_t keyname[50]; - swprintf(keyname,50,L"scheme %d",id); - RegDeleteValue(key,keyname); -} - -INT_PTR CALLBACK ColorSchemes(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK ColorSchemeEdit(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam); - -void doColorSchemes(HINSTANCE hInst,HWND hWnd) -{ - DialogBox(hInst,MAKEINTRESOURCE(IDD_COLORSCHEMES),hWnd,ColorSchemes); -} - -static void validateButtons(HWND hDlg); -static ColorScheme curCS; - -INT_PTR CALLBACK ColorSchemes(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - HWND list; - UNREFERENCED_PARAMETER(lParam); - switch (message) - { - case WM_INITDIALOG: - { - ColorManager cm; - list=GetDlgItem(hDlg,IDC_SCHEMELIST); - int id=0; - ColorScheme cs; - while (id=cm.next(id,&cs)) - { - int pos=SendMessage(list,LB_ADDSTRING,0,(LPARAM)cs.name); - SendMessage(list,LB_SETITEMDATA,pos,cs.id); - } - validateButtons(hDlg); - } - return (INT_PTR)TRUE; - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_SCHEMELIST: - switch (HIWORD(wParam)) - { - case LBN_SELCHANGE: - case LBN_SELCANCEL: - validateButtons(hDlg); - break; - } - break; - case IDC_EDIT: - { - list=GetDlgItem(hDlg,IDC_SCHEMELIST); - int item=(int)SendMessage(list,LB_GETCURSEL,0,0); - curCS.id=(int)SendMessage(list,LB_GETITEMDATA,item,0); - ColorManager cm; - cm.load(&curCS); - DialogBox(NULL,MAKEINTRESOURCE(IDD_COLORSCHEME),hDlg,ColorSchemeEdit); - cm.save(&curCS); - SendMessage(list,LB_DELETESTRING,item,0); - int pos=(int)SendMessage(list,LB_INSERTSTRING,item,(LPARAM)curCS.name); - SendMessage(list,LB_SETITEMDATA,pos,curCS.id); - } - break; - case IDC_ADD: - { - ColorManager cm; - ColorScheme cs; - wcsncpy_s(cs.name,255,L"Color Scheme",255); - cm.create(&cs); - list=GetDlgItem(hDlg,IDC_SCHEMELIST); - int pos=SendMessage(list,LB_ADDSTRING,0,(LPARAM)cs.name); - SendMessage(list,LB_SETITEMDATA,pos,cs.id); - validateButtons(hDlg); - } - break; - case IDC_REMOVE: - { - ColorManager cm; - list=GetDlgItem(hDlg,IDC_SCHEMELIST); - int item=(int)SendMessage(list,LB_GETCURSEL,0,0); - if (item!=LB_ERR) - { - int id=(int)SendMessage(list,LB_GETITEMDATA,item,0); - cm.remove(id); - SendMessage(list,LB_DELETESTRING,item,0); - } - validateButtons(hDlg); - } - break; - case IDCANCEL: - case IDOK: - EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; - } - break; - } - return (INT_PTR)FALSE; -} -static void validateButtons(HWND hDlg) -{ - HWND edit=GetDlgItem(hDlg,IDC_EDIT); - HWND remove=GetDlgItem(hDlg,IDC_REMOVE); - HWND list=GetDlgItem(hDlg,IDC_SCHEMELIST); - int item=(int)SendMessage(list,LB_GETCURSEL,0,0); - if (item==LB_ERR) - { - EnableWindow(edit,FALSE); - EnableWindow(remove,FALSE); - } - else - { - EnableWindow(edit,TRUE); - EnableWindow(remove,TRUE); - } -} - -INT_PTR CALLBACK ColorSchemeEdit(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - static int curSel; - static wchar_t row[255]; - NMLVDISPINFO *info; - UNREFERENCED_PARAMETER(lParam); - switch (message) - { - case WM_INITDIALOG: - { - SetDlgItemText(hDlg,IDC_SCHEMENAME,curCS.name); - - HWND ctl=GetDlgItem(hDlg,IDC_CURCOLOR); - EnableWindow(ctl,FALSE); - ctl=GetDlgItem(hDlg,IDC_CURALPHA); - EnableWindow(ctl,FALSE); - - HWND lv=GetDlgItem(hDlg,IDC_COLORLIST); - ListView_SetExtendedListViewStyle(lv,LVS_EX_FULLROWSELECT); - - LVCOLUMN lvc; - lvc.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; - for (int i=0;i<4;i++) - { - lvc.iSubItem=i; - switch (i) - { - case 0: - lvc.pszText=L"Id"; - lvc.cx=30; - break; - case 1: - lvc.pszText=L"Name"; - lvc.cx=200; - break; - case 2: - lvc.pszText=L"Color"; - lvc.cx=80; - break; - case 3: - lvc.pszText=L"Alpha"; - lvc.cx=50; - break; - } - lvc.fmt=LVCFMT_LEFT; - ListView_InsertColumn(lv,i,&lvc); - } - LVITEM item; - item.mask=LVIF_TEXT|LVIF_STATE; - item.iSubItem=0; - item.state=0; - item.stateMask=0; - item.pszText=LPSTR_TEXTCALLBACK; - for (int i=0;icode) - { - case LVN_ITEMCHANGED: - { - LPNMLISTVIEW item=(LPNMLISTVIEW)lParam; - if (item->uNewState&LVIS_SELECTED) - { - curSel=item->iItem; - swprintf(row,255,L"#%06x",curCS.colors[item->iItem]>>8); - SetDlgItemText(hDlg,IDC_CURCOLOR,row); - swprintf(row,255,L"%d",curCS.colors[item->iItem]&0xff); - SetDlgItemText(hDlg,IDC_CURALPHA,row); - HWND ctl=GetDlgItem(hDlg,IDC_CURCOLOR); - EnableWindow(ctl,TRUE); - ctl=GetDlgItem(hDlg,IDC_CURALPHA); - EnableWindow(ctl,TRUE); - } - } - break; - case LVN_GETDISPINFO: - info=(NMLVDISPINFO*)lParam; - switch (info->item.iSubItem) - { - case 0: - swprintf(row,255,L"%d.",info->item.iItem); - break; - case 1: - swprintf(row,255,L"%S",blocks[info->item.iItem].name); - break; - case 2: - swprintf(row,255,L"#%06x",curCS.colors[info->item.iItem]>>8); - break; - case 3: - swprintf(row,255,L"%d",curCS.colors[info->item.iItem]&0xff); - break; - } - info->item.pszText=row; - break; - } - break; - case WM_COMMAND: - switch (HIWORD(wParam)) - { - case EN_CHANGE: - switch (LOWORD(wParam)) - { - case IDC_SCHEMENAME: - GetDlgItemText(hDlg,IDC_SCHEMENAME,curCS.name,255); - break; - case IDC_CURCOLOR: - { - HWND lv=GetDlgItem(hDlg,IDC_COLORLIST); - GetDlgItemText(hDlg,IDC_CURCOLOR,row,255); - unsigned int color=0; - for (int i=0;row[i];i++) - { - if (row[i]>='0' && row[i]<='9') - { - color<<=4; - color|=row[i]-'0'; - } - if (row[i]>='a' && row[i]<='f') - { - color<<=4; - color|=row[i]+10-'a'; - } - if (row[i]>='A' && row[i]<='F') - { - color<<=4; - color|=row[i]+10-'A'; - } - } - curCS.colors[curSel]&=0xff; - curCS.colors[curSel]|=color<<8; - ListView_RedrawItems(lv,curSel,curSel); - } - break; - case IDC_CURALPHA: - { - HWND lv=GetDlgItem(hDlg,IDC_COLORLIST); - curCS.colors[curSel]&=~0xff; - curCS.colors[curSel]|=GetDlgItemInt(hDlg,IDC_CURALPHA,NULL,FALSE)&0xff; - ListView_RedrawItems(lv,curSel,curSel); - } - } - break; - } - switch (LOWORD(wParam)) - { - case IDCANCEL: - case IDOK: - { - EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; - } - } - break; - } - return (INT_PTR)FALSE; -} \ No newline at end of file diff --git a/Win/ColorSchemes.h b/Win/ColorSchemes.h deleted file mode 100644 index 7b5be35c..00000000 --- a/Win/ColorSchemes.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -typedef struct -{ - int id; - wchar_t name[255]; - unsigned int colors[256]; -} ColorScheme; - -class ColorManager -{ -public: - ColorManager(); - ~ColorManager(); - static void Init(ColorScheme *cs); // initializes a colorscheme with default colors - void create(ColorScheme *cs); //creates a colorscheme, inits it and saves it - int next(int id,ColorScheme *cs); //enumerate colorschemes - void load(ColorScheme *cs); //loads a color scheme (id must be set) - void save(ColorScheme *cs); //saves a color scheme - void remove(int id); //remove a color scheme -private: - HKEY key; -}; - -void doColorSchemes(HINSTANCE hInst,HWND hWnd); \ No newline at end of file diff --git a/Win/Minutor.cpp b/Win/Minutor.cpp deleted file mode 100644 index c05acad2..00000000 --- a/Win/Minutor.cpp +++ /dev/null @@ -1,812 +0,0 @@ -/* -Copyright (c) 2011, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "stdafx.h" -#include "Minutor.h" -#include "ColorSchemes.h" -#include -#include -#include - -#define MAXZOOM 10.0 -#define MINZOOM 1.0 - -#define MAX_LOADSTRING 100 - - -// Global Variables: -HINSTANCE hInst; // current instance -TCHAR szTitle[MAX_LOADSTRING]; // The title bar text -TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name -TCHAR *worlds[1000]; // up to 1000 worlds - -static char world[MAX_PATH]; //path to currently loaded world -static BOOL loaded=FALSE; //world loaded? -static double curX,curZ; //current X and Z -static double curScale=1.0; //current scale -static int curDepth=255; //current depth - -static int spawnX,spawnY,spawnZ; -static int playerX,playerY,playerZ; - -static int opts=0; - -// Forward declarations of functions included in this code module: -ATOM MyRegisterClass(HINSTANCE hInstance); -BOOL InitInstance(HINSTANCE, int); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); -static void loadWorld(); -static void worldPath(TCHAR *path); -static void validateItems(HMENU menu); -static void loadWorldList(HMENU menu); -static void draw(); -static void populateColorSchemes(HMENU menu); -static void useCustomColor(int wmId,HWND hWnd); - -int APIENTRY _tWinMain(HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPTSTR lpCmdLine, - int nCmdShow) -{ - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); - - // TODO: Place code here. - MSG msg; - HACCEL hAccelTable; - - // Initialize global strings - LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadString(hInstance, IDC_MINUTOR, szWindowClass, MAX_LOADSTRING); - MyRegisterClass(hInstance); - - // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) - { - return FALSE; - } - - hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MINUTOR)); - - // Main message loop: - while (GetMessage(&msg, NULL, 0, 0)) - { - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - return (int) msg.wParam; -} - - - -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// -// COMMENTS: -// -// This function and its usage are only necessary if you want this code -// to be compatible with Win32 systems prior to the 'RegisterClassEx' -// function that was added to Windows 95. It is important to call this function -// so that the application will get 'well formed' small icons associated -// with it. -// -ATOM MyRegisterClass(HINSTANCE hInstance) -{ - WNDCLASSEX wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MINUTOR)); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MINUTOR); - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); - - return RegisterClassEx(&wcex); -} - -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - HWND hWnd; - - hInst = hInstance; // Store instance handle in our global variable - - hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, 0, 500, 450, NULL, NULL, hInstance, NULL); - - if (!hWnd) - { - return FALSE; - } - - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); - - return TRUE; -} - -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// -static unsigned char *map; -static int bitWidth=0; -static int bitHeight=0; -static HWND progressBar=NULL; -static HBRUSH ctlBrush=NULL; -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - int wmId, wmEvent; - PAINTSTRUCT ps; - HDC hdc; - static HWND hwndSlider,hwndLabel,hwndStatus; - static BITMAPINFO bmi; - static HBITMAP bitmap=NULL; - static HDC hdcMem=NULL; - static int oldX=0,oldY=0; - static const char *blockLabel=""; - static const char *biomeLabel=""; - static BOOL dragging=FALSE; - static int moving=0; - INITCOMMONCONTROLSEX ice; - DWORD pos; - wchar_t text[4]; - wchar_t buf[100]; - RECT rect; - TCHAR path[MAX_PATH]; - OPENFILENAME ofn; - - switch (message) - { - case WM_CREATE: - - validateItems(GetMenu(hWnd)); - loadWorldList(GetMenu(hWnd)); - populateColorSchemes(GetMenu(hWnd)); - CheckMenuItem(GetMenu(hWnd),IDM_CUSTOMCOLOR,MF_CHECKED); - - ctlBrush=CreateSolidBrush(GetSysColor(COLOR_WINDOW)); - - ice.dwSize=sizeof(INITCOMMONCONTROLSEX); - ice.dwICC=ICC_BAR_CLASSES; - InitCommonControlsEx(&ice); - GetClientRect(hWnd,&rect); - hwndSlider=CreateWindowEx( - 0,TRACKBAR_CLASS,L"Trackbar Control", - WS_CHILD | WS_VISIBLE | TBS_NOTICKS, - 10,0,rect.right-rect.left-50,30, - hWnd,(HMENU)ID_LAYERSLIDER,NULL,NULL); - SendMessage(hwndSlider,TBM_SETRANGE,TRUE,MAKELONG(0,255)); - SendMessage(hwndSlider,TBM_SETPAGESIZE,0,10); - EnableWindow(hwndSlider,FALSE); - - hwndLabel=CreateWindowEx( - 0,L"STATIC",NULL, - WS_CHILD | WS_VISIBLE | ES_RIGHT, - rect.right-40,5,30,20, - hWnd,(HMENU)ID_LAYERLABEL,NULL,NULL); - SetWindowText(hwndLabel,L"255"); - EnableWindow(hwndLabel,FALSE); - - hwndStatus=CreateWindowEx( - 0,STATUSCLASSNAME,NULL, - WS_CHILD | WS_VISIBLE | WS_BORDER, - -100,-100,10,10, - hWnd,(HMENU)ID_STATUSBAR,NULL,NULL); - { - int parts[]={300,400}; - RECT rect; - SendMessage(hwndStatus,SB_SETPARTS,2,(LPARAM)parts); - - progressBar=CreateWindowEx( - 0,PROGRESS_CLASS,NULL, - WS_CHILD | WS_VISIBLE, - 0,0,10,10,hwndStatus,(HMENU)ID_PROGRESS,NULL,NULL); - SendMessage(hwndStatus,SB_GETRECT,1,(LPARAM)&rect); - MoveWindow(progressBar,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); - SendMessage(progressBar,PBM_SETSTEP,(WPARAM)5,0); - SendMessage(progressBar,PBM_SETPOS,0,0); - } - - rect.top+=30; - bitWidth=rect.right-rect.left; - bitHeight=rect.bottom-rect.top; - ZeroMemory(&bmi.bmiHeader,sizeof(BITMAPINFOHEADER)); - bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biWidth=bitWidth; - bmi.bmiHeader.biHeight=-bitHeight; //flip - bmi.bmiHeader.biPlanes=1; - bmi.bmiHeader.biBitCount=32; - bmi.bmiHeader.biCompression=BI_RGB; - bitmap=CreateDIBSection(NULL,&bmi,DIB_RGB_COLORS,(void **)&map,NULL,0); - break; - case WM_LBUTTONDOWN: - dragging=TRUE; - SetFocus(hWnd); - SetCapture(hWnd); - oldX=LOWORD(lParam); - oldY=HIWORD(lParam); - break; - case WM_MOUSEWHEEL: - if (loaded) - { - int zDelta=GET_WHEEL_DELTA_WPARAM(wParam); - curScale+=(double)zDelta/WHEEL_DELTA; - if (curScaleMAXZOOM) - curScale=MAXZOOM; - draw(); - InvalidateRect(hWnd,NULL,FALSE); - UpdateWindow(hWnd); - } - break; - case WM_LBUTTONUP: - dragging=FALSE; - ReleaseCapture(); - break; - case WM_MOUSEMOVE: - if (loaded) - { - short bx=LOWORD(lParam); - short by=HIWORD(lParam); - if (dragging) - { - curZ-=(by-oldY)/curScale; - curX-=(bx-oldX)/curScale; - oldX=bx; - oldY=by; - draw(); - InvalidateRect(hWnd,NULL,FALSE); - UpdateWindow(hWnd); - } - else //don't update statusbar while dragging - { - int mx,mz; - blockLabel=IDBlock(bx,by-30,curX,curZ, - bitWidth,bitHeight,curScale,&mx,&mz,&biomeLabel); - wsprintf(buf,L"X:%d Z:%d %S - %S",mx,mz,biomeLabel,blockLabel); - SendMessage(hwndStatus,SB_SETTEXT,0,(LPARAM)buf); - } - } - break; - case WM_KEYDOWN: - // only care about keys hit when loaded, and control is up - if (loaded && GetKeyState(VK_CONTROL)>=0) - { - BOOL changed=FALSE; - switch (wParam) - { - case VK_UP: - case 'W': - moving|=1; - break; - case VK_DOWN: - case 'S': - moving|=2; - break; - case VK_LEFT: - case 'A': - moving|=4; - break; - case VK_RIGHT: - case 'D': - moving|=8; - break; - case VK_PRIOR: - case 'E': - curScale+=0.5; - if (curScale>MAXZOOM) - curScale=MAXZOOM; - changed=TRUE; - break; - case VK_NEXT: - case 'Q': - curScale-=0.5; - if (curScale=IDM_CUSTOMCOLOR && wmIdIDM_WORLD && wmIdIDM_CUSTOMCOLOR) - { - MENUITEMINFO info; - info.cbSize=sizeof(MENUITEMINFO); - info.fMask=MIIM_DATA; - GetMenuItemInfo(GetMenu(hWnd),wmId,FALSE,&info); - cs.id=info.dwItemData; - cm.load(&cs); - } - else - ColorManager::Init(&cs); - SetMapPalette(cs.colors,256); - draw(); - InvalidateRect(hWnd,NULL,TRUE); - UpdateWindow(hWnd); -} - -static void updateProgress(float progress) -{ - SendMessage(progressBar,PBM_SETPOS,(int)(progress*100),0); -} - -static void draw() -{ - if (loaded) - DrawMap(world,curX,curZ,curDepth,bitWidth,bitHeight,curScale,map,opts,updateProgress); - else - memset(map,0xff,bitWidth*bitHeight*4); - SendMessage(progressBar,PBM_SETPOS,0,0); - for (int i=0;i - - - - Debug - Win32 - - - Release - Win32 - - - - {DFF5C3E2-4DE5-4C7D-8E85-D13ADED53655} - Win32Proj - Minutor - - - - Application - true - Unicode - Static - - - Application - false - true - Unicode - Static - - - - - - - - - - - - - true - - - false - - - - Use - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - Windows - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;%(AdditionalDependencies) - LIBCMT.lib - - - - - Level3 - Use - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreaded - - - Windows - true - true - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;comctl32.lib;shlwapi.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - - Create - Create - - - - - - - - {9e6153b8-20a1-42dc-b889-dad936a8a786} - - - - - - \ No newline at end of file diff --git a/Win/Resource.h b/Win/Resource.h deleted file mode 100644 index e41ddcbd..00000000 --- a/Win/Resource.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#define IDS_APP_TITLE 100 - -#define IDR_MAINFRAME 128 -#define IDD_MINUTOR_DIALOG 101 -#define IDD_ABOUTBOX 102 -#define IDD_COLORSCHEMES 103 -#define IDD_COLORSCHEME 104 -#define IDM_ABOUT 500 -#define IDM_CLOSE 501 -#define IDM_OPEN 502 -#define IDM_JUMPSPAWN 508 -#define IDM_JUMPPLAYER 509 -#define IDM_LIGHTING 510 -#define IDM_CAVEMODE 511 -#define IDM_OBSCURED 512 -#define IDM_DEPTH 513 -#define IDM_COLOR 514 -#define IDM_HELL 515 -#define IDM_END 516 -#define IDM_MOB 517 -#define IDM_WORLD 2000 -#define IDM_CUSTOMCOLOR 3000 -#define IDI_MINUTOR 600 -#define IDI_SMALL 601 -#define IDC_MINUTOR 700 -#define IDC_MYICON 701 -#define IDC_SCHEMELIST 702 -#define IDC_ADD 703 -#define IDC_REMOVE 704 -#define IDC_EDIT 705 -#define IDC_COLORLIST 706 -#define IDC_SCHEMENAME 707 -#define IDC_CURCOLOR 708 -#define IDC_CURALPHA 709 -#define ID_LAYERSLIDER 1001 -#define ID_LAYERLABEL 1002 -#define ID_STATUSBAR 1003 -#define ID_PROGRESS 1004 - -#ifndef IDC_STATIC -#define IDC_STATIC -1 -#endif -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS - -#define _APS_NO_MFC 130 -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 110 -#endif -#endif diff --git a/Win/icon.ico b/Win/icon.ico deleted file mode 100644 index ab6d2622..00000000 Binary files a/Win/icon.ico and /dev/null differ diff --git a/Win/stdafx.cpp b/Win/stdafx.cpp deleted file mode 100644 index b06f8072..00000000 --- a/Win/stdafx.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/Win/stdafx.h b/Win/stdafx.h deleted file mode 100644 index ea278ad2..00000000 --- a/Win/stdafx.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#pragma once - -#include "targetver.h" -#include "../MinutorMap/MinutorMap.h" - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -// Windows Header Files: -#include -#include - -// C RunTime Header Files -#include -#include -#include -#include - - -// TODO: reference additional headers your program requires here diff --git a/Win/targetver.h b/Win/targetver.h deleted file mode 100644 index b5a7b335..00000000 --- a/Win/targetver.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#include diff --git a/biomeidentifier.cpp b/biomeidentifier.cpp new file mode 100644 index 00000000..f03b808b --- /dev/null +++ b/biomeidentifier.cpp @@ -0,0 +1,86 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "biomeidentifier.h" +#include "json.h" + +static BiomeInfo unknownBiome; +BiomeIdentifier::BiomeIdentifier() +{ + unknownBiome.name="Unknown"; +} + +BiomeInfo &BiomeIdentifier::getBiome(int biome) +{ + QList &list=biomes[biome]; + //search backwards for priority sorting to work + for (int i=list.length()-1;i>=0;i--) + if (list[i]->enabled) + return *list[i]; + return unknownBiome; +} + +void BiomeIdentifier::enableDefinitions(int pack) +{ + if (pack<0) return; + int len=packs[pack].length(); + for (int i=0;ienabled=true; +} +void BiomeIdentifier::disableDefinitions(int pack) +{ + if (pack<0) return; + int len=packs[pack].length(); + for (int i=0;ienabled=false; +} + +int BiomeIdentifier::addDefinitions(JSONArray *defs,int pack) +{ + if (pack==-1) + { + pack=packs.length(); + packs.append(QList()); + } + + int len=defs->length(); + for (int i=0;i(defs->at(i)); + int id=b->at("id")->asNumber(); + + BiomeInfo *biome=new BiomeInfo(); + biome->enabled=true; + if (b->has("name")) + biome->name=b->at("name")->asString(); + else + biome->name="Unknown"; + biomes[id].append(biome); + packs[pack].append(biome); + } + return pack; +} diff --git a/biomeidentifier.h b/biomeidentifier.h new file mode 100644 index 00000000..7efc555a --- /dev/null +++ b/biomeidentifier.h @@ -0,0 +1,56 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __BIOMEIDENTIFIER_H__ +#define __BIOMEIDENTIFIER_H__ + +#include +#include +#include +class JSONArray; + +class BiomeInfo +{ +public: + BiomeInfo() {} + QString name; + bool enabled; +}; + +class BiomeIdentifier +{ +public: + BiomeIdentifier(); + int addDefinitions(JSONArray *,int pack=-1); + void enableDefinitions(int); + void disableDefinitions(int); + BiomeInfo &getBiome(int); +private: + QHash > biomes; + QList > packs; +}; + +#endif diff --git a/blockidentifier.cpp b/blockidentifier.cpp new file mode 100644 index 00000000..d7d55f6c --- /dev/null +++ b/blockidentifier.cpp @@ -0,0 +1,221 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "blockidentifier.h" +#include "json.h" +#include + +static BlockInfo unknownBlock; +BlockIdentifier::BlockIdentifier() +{ + for (int i=0;i<16;i++) + unknownBlock.colors[i]=0xff00ff; + unknownBlock.alpha=1.0; + unknownBlock.flags=0; + unknownBlock.name="Unknown"; +} + +// this routine is ridiculously slow +BlockInfo &BlockIdentifier::getBlock(int id, int data) +{ + quint32 bid=id|(data<<12); + //first check the cache + if (cache[bid]!=NULL) + return *cache[bid]; + + //first get the mask + if (blocks.contains(id)) + data&=blocks[id].first()->mask; + //now find the variant + if (blocks.contains(bid)) + { + QList &list=blocks[bid]; + //run backwards for priority sorting + for (int i=list.length()-1;i>=0;i--) + { + if (list[i]->enabled) + { + cache[bid]=list[i]; + return *list[i]; + } + } + } + //no enabled variant found + if (blocks.contains(id)) + { + QList &list=blocks[id]; + for (int i=list.length()-1;i>=0;i--) + { + if (list[i]->enabled) + { + cache[bid]=list[i]; + return *list[i]; + } + } + } + //no blocks at all found.. dammit + return unknownBlock; +} + +void BlockIdentifier::enableDefinitions(int pack) +{ + if (pack<0) return; + int len=packs[pack].length(); + for (int i=0;ienabled=true; + //clear cache + for (int i=0;i<65536;i++) + cache[i]=NULL; +} + +void BlockIdentifier::disableDefinitions(int pack) +{ + if (pack<0) return; + int len=packs[pack].length(); + for (int i=0;ienabled=false; + //clear cache + for (int i=0;i<65536;i++) + cache[i]=NULL; +} + +int BlockIdentifier::addDefinitions(JSONArray *defs,int pack) +{ + if (pack==-1) + { + pack=packs.length(); + packs.append(QList()); + } + int len=defs->length(); + for (int i=0;i(defs->at(i)),NULL,pack); + //clear cache + for (int i=0;i<65536;i++) + cache[i]=NULL; + return pack; +} + +static int clamp(int v,int min,int max) +{ + return (vmin?v:min):max); +} + +void BlockIdentifier::parseDefinition(JSONObject *b, BlockInfo *parent, int pack) +{ + int id; + if (parent==NULL) + id=b->at("id")->asNumber(); + else + { + id=parent->id; + int data=b->at("data")->asNumber(); + id|=data<<12; + } + BlockInfo *block=new BlockInfo(); + block->id=id; + + if (b->has("name")) + block->name=b->at("name")->asString(); + else if (parent!=NULL) + block->name=parent->name; + else + block->name="Unknown"; + block->enabled=true; + if (b->has("flags")) + block->flags=b->at("flags")->asNumber(); + else if (parent!=NULL) + block->flags=parent->flags; + else + block->flags=0; + if (b->has("color")) + { + QString color=b->at("color")->asString(); + quint32 col=0; + for (int h=0;h='0' && c<='9') + col|=c-'0'; + else if (c>='A' && c<='F') + col|=c-'A'+10; + else if (c>='a' && c<='f') + col|=c-'a'+10; + } + int rd=col>>16; + int gn=(col>>8)&0xff; + int bl=col&0xff; + + if (b->has("alpha")) + block->alpha=b->at("alpha")->asNumber(); + else if (parent!=NULL) + block->alpha=parent->alpha; + else + block->alpha=1.0; + + //pre multiply alphas + rd*=block->alpha; + gn*=block->alpha; + bl*=block->alpha; + + //pre-calculate light spectrum + double y=0.299*rd+0.587*gn+0.114*bl; + double u=(bl-y)*0.565; + double v=(rd-y)*0.713; + double delta=y/15; + for (int i=0;i<16;i++) + { + y=i*delta; + rd=(unsigned int)clamp(y+1.403*v,0,255); + gn=(unsigned int)clamp(y-0.344*u-0.714*v,0,255); + bl=(unsigned int)clamp(y+1.770*u,0,255); + block->colors[i]=(rd<<16)|(gn<<8)|bl; + } + + } + else if (parent!=NULL) + { + for (int i=0;i<16;i++) + block->colors[i]=parent->colors[i]; + block->alpha=parent->alpha; + } + else + block->alpha=0.0; + if (b->has("mask")) + block->mask=b->at("mask")->asNumber(); + else + block->mask=0xff; + if (b->has("variants")) + { + JSONArray *variants=dynamic_cast(b->at("variants")); + int vlen=variants->length(); + for (int j=0;j(variants->at(j)),block,pack); + } + blocks[id].append(block); + packs[pack].append(block); +} diff --git a/blockidentifier.h b/blockidentifier.h new file mode 100644 index 00000000..abcefad0 --- /dev/null +++ b/blockidentifier.h @@ -0,0 +1,75 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __BLOCKIDENTIFIER_H__ +#define __BLOCKIDENTIFIER_H__ + +#include +#include +#include +#include + +class JSONArray; +class JSONObject; + +// bit masks for the flags +#define BlockTransparent 1 +#define BlockSolid 2 +#define BlockLiquid 4 + +// mobs can't spawn on transparent, but need 2 blocks of transparent, +// non solid, non liquid above + +class BlockInfo +{ +public: + BlockInfo() {} + int id; + QString name; + double alpha; + quint8 flags; + quint8 mask; + bool enabled; + quint32 colors[16]; +}; + +class BlockIdentifier +{ +public: + BlockIdentifier(); + int addDefinitions(JSONArray *,int pack=-1); + void enableDefinitions(int); + void disableDefinitions(int); + BlockInfo &getBlock(int id,int data); +private: + void parseDefinition(JSONObject *block,BlockInfo *parent,int pack); + QMap > blocks; + QList > packs; + BlockInfo *cache[65536]; +}; + +#endif diff --git a/chunk.cpp b/chunk.cpp new file mode 100644 index 00000000..9a5db4d6 --- /dev/null +++ b/chunk.cpp @@ -0,0 +1,88 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "chunk.h" + +Chunk::Chunk() +{ + loaded=false; +} + +void Chunk::load(NBT &nbt) +{ + renderedAt=-1; //impossible. + memset(this->biomes,127,256); //init to unknown biome + for (int i=0;i<16;i++) + this->sections[i]=NULL; + highest=0; + + Tag *level=nbt.at("Level"); + Tag *biomes=level->at("Biomes"); + memcpy(this->biomes,biomes->toByteArray(),biomes->length()); + Tag *sections=level->at("Sections"); + int numSections=sections->length(); + for (int i=0;iat(i); + ChunkSection *cs=new ChunkSection(); + const quint8 *raw=section->at("Blocks")->toByteArray(); + for (int i=0;i<4096;i++) + cs->blocks[i]=raw[i]; + if (section->has("Add")) + { + raw=section->at("Add")->toByteArray(); + for (int i=0;i<2048;i++) + { + cs->blocks[i*2]|=(raw[i]&0xf)<<8; + cs->blocks[i*2+1]|=(raw[i]&0xf0)<<4; + } + } + memcpy(cs->data,section->at("Data")->toByteArray(),2048); + memcpy(cs->light,section->at("BlockLight")->toByteArray(),2048); + int idx=section->at("Y")->toInt(); + this->sections[idx]=cs; + } + loaded=true; + for (int i=15;i>=0;i--) //check for the highest block in this chunk + { + if (this->sections[i]) + for (int j=4095;j>=0;j--) + if (this->sections[i]->blocks[j]) + { + highest=i*16+(j>>8); + return; + } + } +} +Chunk::~Chunk() +{ + if (loaded) + for (int i=0;i<16;i++) + if (sections[i]) + delete sections[i]; +} diff --git a/OSX/MapViewer.h b/chunk.h similarity index 61% rename from OSX/MapViewer.h rename to chunk.h index f3a926d1..dc89e105 100644 --- a/OSX/MapViewer.h +++ b/chunk.h @@ -1,17 +1,17 @@ /* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -24,26 +24,38 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import -#import "Map.h" - -@interface MapViewer : NSObject { - - IBOutlet id window; - IBOutlet Map *map; - IBOutlet id slider; - IBOutlet id depthText; - IBOutlet id status; - IBOutlet id progressBar; - int curDepth; - int spawnX,spawnY,spawnZ; - int playerX,playerY,playerZ; -} --(void)openWorld:(NSString *)world; --(void)jumpToSpawn; --(void)jumpToPlayer; --(IBAction) sliderChanged:(NSSlider*)sender; --(void)setOpts:(int)options; --(void)setColorScheme:(unsigned int *)colors; - -@end + + +#ifndef __CHUNK_H__ +#define __CHUNK_H__ + +#include +#include "nbt.h" +class BlockIdentifier; + +class ChunkSection +{ +public: + quint16 blocks[4096]; + quint8 data[2048]; + quint8 light[2048]; +}; + +class Chunk +{ +public: + Chunk(); + void load(NBT &nbt); + ~Chunk(); +protected: + quint8 biomes[256]; + int highest; + ChunkSection *sections[16]; + int renderedAt; + bool loaded; + uchar image[16*16*4]; //cached render + friend class MapView; + friend class ChunkCache; +}; + +#endif diff --git a/chunkcache.cpp b/chunkcache.cpp new file mode 100644 index 00000000..a4d61be6 --- /dev/null +++ b/chunkcache.cpp @@ -0,0 +1,84 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "chunkcache.h" +#include "chunkloader.h" + +ChunkID::ChunkID(int x,int z) : x(x),z(z) +{ +} +bool ChunkID::operator==(const ChunkID &other) const +{ + return other.x==x && other.z==z; +} +uint qHash(const ChunkID &c) +{ + return c.x^c.z; //quick way to hash a pair of integers +} + +ChunkCache::ChunkCache() +{ + cache.setMaxCost(5000); // 5000 chunks, or 1600x1600 blocks +} + +ChunkCache::~ChunkCache() +{ +} + +void ChunkCache::clear() +{ + QThreadPool::globalInstance()->waitForDone(); + cache.clear(); +} + +void ChunkCache::setPath(QString path) +{ + this->path=path; +} + +Chunk *ChunkCache::fetch(int x, int z) +{ + ChunkID id(x,z); + if (cache.contains(id)) + { + if (cache[id]->loaded) + return cache[id]; + return NULL; //we're loading this chunk, or it's blank. + } + // launch background process to load this chunk + Chunk *chunk=new Chunk(); + cache.insert(id,chunk); + ChunkLoader *loader=new ChunkLoader(path,x,z,chunk); + connect(loader,SIGNAL(loaded(int,int)), + this,SLOT(gotChunk(int,int))); + QThreadPool::globalInstance()->start(loader); + return NULL; +} +void ChunkCache::gotChunk(int x,int z) +{ + emit chunkLoaded(x,z); +} diff --git a/chunkcache.h b/chunkcache.h new file mode 100644 index 00000000..ec9b5742 --- /dev/null +++ b/chunkcache.h @@ -0,0 +1,68 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __CHUNKCACHE_H__ +#define __CHUNKCACHE_H__ + +#include +#include +#include "chunk.h" + +class ChunkID +{ +public: + ChunkID(int x,int z); + bool operator==(const ChunkID &) const; + friend uint qHash(const ChunkID &); +protected: + int x,z; +}; + +class ChunkCache : public QObject +{ + Q_OBJECT + +public: + ChunkCache(); + ~ChunkCache(); + void clear(); + void setPath(QString path); + Chunk *fetch(int x,int z); + +signals: + void chunkLoaded(int x,int z); + +private slots: + void gotChunk(int x,int z); + +private: + QString path; + QCache cache; +}; + +#endif diff --git a/OSX/minutorAppDelegate.h b/chunkloader.cpp similarity index 50% rename from OSX/minutorAppDelegate.h rename to chunkloader.cpp index 6a23ac9a..3c1ca420 100644 --- a/OSX/minutorAppDelegate.h +++ b/chunkloader.cpp @@ -1,17 +1,17 @@ /* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -25,31 +25,46 @@ THE POSSIBILITY OF SUCH DAMAGE. */ -#import -#import "ColorScheme.h" - -@interface minutorAppDelegate : NSObject { - NSWindow *window; - NSMutableArray *worldPaths; - NSString *customWorld; - IBOutlet id mapViewer; - int opts; - IBOutlet id colorSchemes; - IBOutlet id worldMenu; - IBOutlet id hellItem; - IBOutlet id enderItem; +#include "chunkloader.h" +#include "chunk.h" + +ChunkLoader::ChunkLoader(QString path,int x,int z,Chunk *chunk) : path(path),x(x),z(z),chunk(chunk) +{ +} +ChunkLoader::~ChunkLoader() +{ +} + +void ChunkLoader::run() +{ + int rx=x>>5; + int rz=z>>5; + + QFile f(path+QDir::toNativeSeparators("/region/r.")+QString::number(rx)+"."+QString::number(rz)+".mca"); + if (!f.open(QIODevice::ReadOnly)) //no chunks in this region + { + emit loaded(x,z); + return; + } + //map header into memory + uchar *header=f.map(0,4096); + int offset=4*((x&31)+(z&31)*32); + int coffset=(header[offset]<<16)|(header[offset+1]<<8)|header[offset+2]; + int numSectors=header[offset+3]; + f.unmap(header); + + if (coffset==0) // no chunk + { + f.close(); + emit loaded(x,z); + return; + } + + uchar *raw=f.map(coffset*4096,numSectors*4096); + NBT nbt(raw); + chunk->load(nbt); + f.unmap(raw); + f.close(); + + emit loaded(x,z); } -- (IBAction) openWorld: sender; -- (IBAction) jumpToSpawn: sender; -- (IBAction) jumpToPlayer: sender; -- (IBAction) toggleLighting: sender; -- (IBAction) toggleCaveMode: sender; -- (IBAction) toggleObscured: sender; -- (IBAction) toggleDepth: sender; -- (IBAction) toggleMob: sender; -- (IBAction) toggleHell: sender; -- (IBAction) toggleEnder: sender; -- (IBAction) selectScheme: sender; - - -@end diff --git a/OSX/main.m b/chunkloader.h similarity index 65% rename from OSX/main.m rename to chunkloader.h index 32bce55a..896a6c33 100644 --- a/OSX/main.m +++ b/chunkloader.h @@ -1,17 +1,17 @@ /* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -25,9 +25,27 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import +#ifndef __CHUNKLOADER_H__ +#define __CHUNKLOADER_H__ + +#include +#include +class Chunk; -int main(int argc, char *argv[]) +class ChunkLoader : public QObject, public QRunnable { - return NSApplicationMain(argc, (const char **) argv); -} + Q_OBJECT +public: + ChunkLoader(QString path,int x,int z,Chunk *chunk); + ~ChunkLoader(); +signals: + void loaded(int x,int z); +protected: + void run(); +private: + QString path; + int x,z; + Chunk *chunk; +}; + +#endif diff --git a/colorschemes.c b/colorschemes.c deleted file mode 100644 index 9bc69eac..00000000 --- a/colorschemes.c +++ /dev/null @@ -1,445 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include "MinutorMap/blockInfo.h" - -extern void selectColorScheme(GtkMenuItem *menuItem,gpointer user_data); - -static void renameScheme(GtkCellRendererText *renderer,gchar *path,gchar *text,GtkTreeModel *model); -static void editScheme(GtkButton *widget,GtkListStore *store); -static void addScheme(GtkButton *widget,GtkListStore *store); -static void removeScheme(GtkButton *widget,GtkListStore *store); -static void updateColor(GtkCellRendererText *renderer,gchar *path,gchar *text,GtkTreeModel *model); -static void updateAlpha(GtkCellRendererText *renderer,gchar *path,gchar *text,GtkTreeModel *model); -static void renderId(GtkTreeViewColumn *column,GtkCellRenderer *cell, - GtkTreeModel *model,GtkTreeIter *iter,gpointer data); -static void renderColor(GtkTreeViewColumn *column,GtkCellRenderer *cell, - GtkTreeModel *model,GtkTreeIter *iter,gpointer data); - -typedef struct -{ - int id; - char name[256]; - uint32_t colors[256]; -} ColorScheme; - -GArray *schemes=NULL; - -static void destroy() -{ -} - -GArray *menuitems=NULL; - -#define COLORGROUP "ColorSchemes" - -static GtkMenuShell *menu; -static int menupos; -static GSList *itemgroup; -void initColorSchemes(GtkMenuShell *menushell,int startpos,GSList *group) -{ - menu=menushell; - menupos=startpos; - itemgroup=group; - - menuitems=g_array_new(FALSE,TRUE,sizeof(GtkWidget *)); - schemes=g_array_new(FALSE,TRUE,sizeof(ColorScheme)); - - GKeyFile *keyfile=g_key_file_new(); - gchar *filename=g_strdup_printf("%s/.minutor",g_get_home_dir()); - if (g_key_file_load_from_file(keyfile,filename,G_KEY_FILE_NONE,NULL)) - { - ColorScheme cs; - int num=g_key_file_get_integer(keyfile,COLORGROUP,"count",NULL); - for (int i=0;ilen; - g_array_append_val(schemes,cs); - GtkWidget *item=gtk_radio_menu_item_new_with_label(itemgroup,cs.name); - itemgroup=gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(item)); - g_array_append_val(menuitems,item); - gtk_menu_shell_insert(menu,item,menupos); - g_signal_connect(G_OBJECT(item),"activate", - G_CALLBACK(selectColorScheme),GINT_TO_POINTER(cs.id)); - } - } - g_key_file_free(keyfile); - g_free(filename); -} -static void saveSchemes() -{ - GKeyFile *keyfile=g_key_file_new(); - gchar *filename=g_strdup_printf("%s/.minutor",g_get_home_dir()); - g_key_file_load_from_file(keyfile,filename,G_KEY_FILE_NONE,NULL); - - //should delete all existing colorschemes - g_key_file_remove_group(keyfile,COLORGROUP,NULL); - - ColorScheme *cs; - int num=0; - gint list[256]; - for (int i=0;ilen;i++) - { - cs=&g_array_index(schemes,ColorScheme,i); - if (cs->id==-1) continue; - gchar *key=g_strdup_printf("name%d",num); - g_key_file_set_string(keyfile,COLORGROUP,key,cs->name); - g_free(key); - key=g_strdup_printf("color%d",num); - for (int j=0;j<256;j++) - list[j]=cs->colors[j]; - g_key_file_set_integer_list(keyfile,COLORGROUP,key,list,256); - g_free(key); - num++; - } - g_key_file_set_integer(keyfile,COLORGROUP,"count",num); - - gsize len; - gchar *data=g_key_file_to_data(keyfile,&len,NULL); - GFile *f=g_file_new_for_path(filename); - g_file_replace_contents(f,data,len,NULL,FALSE,G_FILE_CREATE_NONE,NULL,NULL,NULL); - g_free(data); - g_free(filename); - g_key_file_free(keyfile); - g_object_unref(G_OBJECT(f)); -} - -ColorScheme *newScheme(char *name) -{ - ColorScheme cs; - g_memmove(cs.name,name,256); - cs.id=schemes->len; - g_array_append_val(schemes,cs); - GtkWidget *item=gtk_radio_menu_item_new_with_label(itemgroup,cs.name); - itemgroup=gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(item)); - g_array_append_val(menuitems,item); - gtk_menu_shell_insert(menu,item,menupos); - g_signal_connect(G_OBJECT(item),"activate", - G_CALLBACK(selectColorScheme),GINT_TO_POINTER(cs.id)); - gtk_widget_show(item); - return &g_array_index(schemes,ColorScheme,cs.id); -} -static void initScheme(ColorScheme *cs) -{ - for (int i=0;i>16; - g=color>>8; - b=color; - double alpha=blocks[i].alpha; - r/=alpha; - g/=alpha; - b/=alpha; - a=alpha*255; - color=(r<<24)|(g<<16)|(b<<8)|a; - cs->colors[i]=color; - } - for (int i=numBlocks;i<256;i++) - cs->colors[i]=0; -} - -static GtkWidget *schemeList; -static GtkWidget *colorList; - -void editColorSchemes(GtkMenuItem *menuItem,gpointer user_data) -{ - GtkWidget *win=gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win),"Color Schemes"); - gtk_window_set_default_size(GTK_WINDOW(win),300,300); - g_signal_connect(G_OBJECT(win),"destroy", - G_CALLBACK(destroy),NULL); - - //main hbox - GtkWidget *hbox=gtk_hbox_new(FALSE,5); - gtk_container_add(GTK_CONTAINER(win),hbox); - - GtkListStore *store=gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_INT); - - ColorScheme *cs; - GtkTreeIter iter; - for (int i=0;ilen;i++) - { - cs=&g_array_index(schemes,ColorScheme,i); - if (cs->id==-1) continue; - gtk_list_store_append(store,&iter); - gtk_list_store_set(store,&iter, - 0,cs->name,1,cs->id,-1); - } - - schemeList=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - GtkTreeSelection *sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(schemeList)); - gtk_tree_selection_set_mode(sel,GTK_SELECTION_SINGLE); - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - renderer=gtk_cell_renderer_text_new(); - g_object_set(renderer,"editable",TRUE,NULL); - g_signal_connect(G_OBJECT(renderer),"edited", - G_CALLBACK(renameScheme),GTK_TREE_MODEL(store)); - column=gtk_tree_view_column_new_with_attributes(NULL, - renderer,"text",0,NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(schemeList),column); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(schemeList),FALSE); - gtk_box_pack_start(GTK_BOX(hbox),schemeList,TRUE,TRUE,0); - - //button box - GtkWidget *vbox=gtk_vbox_new(FALSE,5); - gtk_box_pack_start(GTK_BOX(hbox),vbox,FALSE,FALSE,0); - - GtkWidget *edit=gtk_button_new_with_label("Edit"); - gtk_box_pack_start(GTK_BOX(vbox),edit,FALSE,FALSE,0); - g_signal_connect(G_OBJECT(edit),"clicked", - G_CALLBACK(editScheme),store); - - GtkWidget *add=gtk_button_new_with_label("Add"); - gtk_box_pack_start(GTK_BOX(vbox),add,FALSE,FALSE,0); - g_signal_connect(G_OBJECT(add),"clicked", - G_CALLBACK(addScheme),store); - - GtkWidget *remove=gtk_button_new_with_label("Remove"); - gtk_box_pack_start(GTK_BOX(vbox),remove,FALSE,FALSE,0); - g_signal_connect(G_OBJECT(remove),"clicked", - G_CALLBACK(removeScheme),store); - - gtk_widget_show_all(win); -} -static void renameScheme(GtkCellRendererText *renderer,gchar *path,gchar *text,GtkTreeModel *model) -{ - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model,&iter,path); - gtk_list_store_set(GTK_LIST_STORE(model),&iter,0,text,-1); - int id; - gtk_tree_model_get(model,&iter,1,&id,-1); - ColorScheme *cs=&g_array_index(schemes,ColorScheme,id); - g_stpcpy(cs->name,text); - GtkWidget *item=g_array_index(menuitems,GtkWidget *,id); - gtk_menu_item_set_label(GTK_MENU_ITEM(item),text); - saveSchemes(); -} -static void addScheme(GtkButton *widget,GtkListStore *store) -{ - ColorScheme *cs=newScheme("Color Scheme"); - initScheme(cs); - - GtkTreeIter iter; - gtk_list_store_append(store,&iter); - gtk_list_store_set(store,&iter, - 0,cs->name,1,cs->id,-1); - saveSchemes(); -} -static void removeScheme(GtkButton *widget,GtkListStore *store) -{ - GtkTreeSelection *sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(schemeList)); - GtkTreeIter iter; - if (gtk_tree_selection_get_selected(sel,NULL,&iter)) - { - int id; - gtk_tree_model_get(GTK_TREE_MODEL(store),&iter,1,&id,-1); - gtk_list_store_remove(store,&iter); - ColorScheme *cs=&g_array_index(schemes,ColorScheme,id); - GtkWidget *w=g_array_index(menuitems,GtkWidget *,id); - gtk_container_remove(GTK_CONTAINER(menu),w); - cs->id=-1; - saveSchemes(); - } - -} - -static void closeScheme() -{ -} - -uint32_t *getColorScheme(int id) -{ - static ColorScheme standard; - if (id==-1) - { - initScheme(&standard); - return standard.colors; - } - ColorScheme *cs=&g_array_index(schemes,ColorScheme,id); - return cs->colors; -} -static ColorScheme *curScheme; -static void editScheme(GtkButton *widget,GtkListStore *store) -{ - GtkTreeSelection *sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(schemeList)); - GtkTreeIter iter; - if (gtk_tree_selection_get_selected(sel,NULL,&iter)) - { - int id; - gtk_tree_model_get(GTK_TREE_MODEL(store),&iter,1,&id,-1); - curScheme=&g_array_index(schemes,ColorScheme,id); - - GtkWidget *win=gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win),"Color Scheme"); - gtk_window_set_default_size(GTK_WINDOW(win),350,400); - g_signal_connect(G_OBJECT(win),"destroy", - G_CALLBACK(closeScheme),NULL); - - //main vbox - GtkWidget *vbox=gtk_vbox_new(FALSE,5); - gtk_container_add(GTK_CONTAINER(win),vbox); - - GtkListStore *substore=gtk_list_store_new(4,G_TYPE_INT,G_TYPE_STRING,G_TYPE_INT,G_TYPE_INT); - - GtkTreeIter iter; - for (int i=0;icolors[i]>>8, - 3,curScheme->colors[i]&0xff, - -1); - } - - - colorList=gtk_tree_view_new_with_model(GTK_TREE_MODEL(substore)); - GtkWidget *scroll=gtk_scrolled_window_new(gtk_tree_view_get_hadjustment(GTK_TREE_VIEW(colorList)),gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(colorList))); - gtk_box_pack_start(GTK_BOX(vbox),scroll,TRUE,TRUE,0); - gtk_container_add(GTK_CONTAINER(scroll),colorList); - - GtkTreeSelection *sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(colorList)); - gtk_tree_selection_set_mode(sel,GTK_SELECTION_SINGLE); - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - renderer=gtk_cell_renderer_text_new(); - column=gtk_tree_view_column_new_with_attributes("Id", - renderer,"text",0,NULL); - gtk_tree_view_column_set_cell_data_func(column,renderer, - renderId,NULL,NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(colorList),column); - renderer=gtk_cell_renderer_text_new(); - column=gtk_tree_view_column_new_with_attributes("Name", - renderer,"text",1,NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(colorList),column); - renderer=gtk_cell_renderer_text_new(); - column=gtk_tree_view_column_new_with_attributes("Color", - renderer,"text",2,NULL); - gtk_tree_view_column_set_cell_data_func(column,renderer, - renderColor,NULL,NULL); - g_object_set(renderer,"editable",TRUE,NULL); - g_signal_connect(G_OBJECT(renderer),"edited", - G_CALLBACK(updateColor),GTK_TREE_MODEL(substore)); - gtk_tree_view_append_column(GTK_TREE_VIEW(colorList),column); - renderer=gtk_cell_renderer_text_new(); - column=gtk_tree_view_column_new_with_attributes("Alpha", - renderer,"text",3,NULL); - g_object_set(renderer,"editable",TRUE,NULL); - g_signal_connect(G_OBJECT(renderer),"edited", - G_CALLBACK(updateAlpha),GTK_TREE_MODEL(substore)); - gtk_tree_view_append_column(GTK_TREE_VIEW(colorList),column); - - gtk_widget_show_all(win); - } -} -static void updateColor(GtkCellRendererText *renderer,gchar *path,gchar *text,GtkTreeModel *model) -{ - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model,&iter,path); - int id; - gtk_tree_model_get(model,&iter,0,&id,-1); - uint32_t color=0; - for (int i=0;text[i];i++) - { - if (text[i]>='0' && text[i]<='9') - { - color<<=4; - color|=text[i]-'0'; - } - if (text[i]>='a' && text[i]<='f') - { - color<<=4; - color|=text[i]+10-'a'; - } - if (text[i]>='A' && text[i]<='F') - { - color<<=4; - color|=text[i]+10-'A'; - } - } - gtk_list_store_set(GTK_LIST_STORE(model),&iter,2,color,-1); - curScheme->colors[id]&=0xff; - curScheme->colors[id]|=color<<8; - saveSchemes(); -} -static void updateAlpha(GtkCellRendererText *renderer,gchar *path,gchar *text,GtkTreeModel *model) -{ - GtkTreeIter iter; - gtk_tree_model_get_iter_from_string(model,&iter,path); - int id; - gtk_tree_model_get(model,&iter,0,&id,-1); - uint8_t alpha=0; - for (int i=0;text[i];i++) - { - if (text[i]>='0' && text[i]<='9') - { - alpha*=10; - alpha+=text[i]-'0'; - } - } - gtk_list_store_set(GTK_LIST_STORE(model),&iter,3,alpha,-1); - curScheme->colors[id]&=~0xff; - curScheme->colors[id]|=alpha; - saveSchemes(); -} -static void renderId(GtkTreeViewColumn *column,GtkCellRenderer *cell, - GtkTreeModel *model,GtkTreeIter *iter,gpointer data) -{ - int id; - gtk_tree_model_get(model,iter,0,&id,-1); - gchar *name=g_strdup_printf("%d.",id); - g_object_set(G_OBJECT(cell),"text",name,NULL); - g_free(name); -} -static void renderColor(GtkTreeViewColumn *column,GtkCellRenderer *cell, - GtkTreeModel *model,GtkTreeIter *iter,gpointer data) -{ - uint32_t color; - gtk_tree_model_get(model,iter,2,&color,-1); - gchar *name=g_strdup_printf("#%06x",color); - g_object_set(G_OBJECT(cell),"text",name,NULL); - g_free(name); -} diff --git a/colorschemes.h b/colorschemes.h deleted file mode 100644 index 8e3d8d1a..00000000 --- a/colorschemes.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __COLORSCHEMES_H__ -#define __COLORSCHEMES_H__ - -#include - -void initColorSchemes(GtkMenuShell *menushell,int startpos,GSList *group); -void editColorSchemes(GtkMenuItem *menuItem,gpointer user_data); -uint32_t *getColorScheme(int id); - -#endif diff --git a/definitionmanager.cpp b/definitionmanager.cpp new file mode 100644 index 00000000..e2b312f8 --- /dev/null +++ b/definitionmanager.cpp @@ -0,0 +1,512 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + + +#include "definitionmanager.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "biomeidentifier.h" +#include "blockidentifier.h" +#include "dimensions.h" +#include "mapview.h" +#include "json.h" +#include "zipreader.h" +#include "definitionupdater.h" + +DefinitionManager::DefinitionManager(QWidget *parent) : QWidget(parent) +{ + setWindowFlags(Qt::Window); + setWindowTitle(tr("Definitions")); + + QVBoxLayout *layout=new QVBoxLayout; + QStringList labels; + labels<setHorizontalHeaderLabels(labels); + table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + table->horizontalHeader()->setSectionResizeMode(0,QHeaderView::Stretch); + table->horizontalHeader()->setHighlightSections(false); + table->verticalHeader()->hide(); + table->setShowGrid(false); + table->setSelectionBehavior(QAbstractItemView::SelectRows); + layout->addWidget(table,1); + + QWidget *buttonBar=new QWidget; + QHBoxLayout *buttons=new QHBoxLayout; + QPushButton *add=new QPushButton(tr("Add Pack...")); + connect(add,SIGNAL(clicked()), + this,SLOT(addPack())); + buttons->addWidget(add); + QPushButton *remove=new QPushButton(tr("Remove Pack")); + connect(remove,SIGNAL(clicked()), + this,SLOT(removePack())); + connect(this,SIGNAL(packSelected(bool)), + remove,SLOT(setEnabled(bool))); + buttons->addWidget(remove); + QPushButton *save=new QPushButton(tr("Export Pack...")); + connect(save,SIGNAL(clicked()), + this,SLOT(exportPack())); + connect(this,SIGNAL(packSelected(bool)), + save,SLOT(setEnabled(bool))); + buttons->addWidget(save); + buttonBar->setLayout(buttons); + layout->addWidget(buttonBar,0); + + emit packSelected(false); + setLayout(layout); + + dimensionList = new Dimensions; + blocks=new BlockIdentifier; + biomes=new BiomeIdentifier; + + QSettings settings; + sorted=settings.value("packs").toList(); + + //copy over built-in definitions if necessary + QString defdir=QStandardPaths::writableLocation(QStandardPaths::DataLocation); + QDir dir; + dir.mkpath(defdir); + QDirIterator it(":/definitions",QDir::Files|QDir::Readable); + while (it.hasNext()) + { + it.next(); + installJson(it.filePath(),false,false); + } + settings.setValue("packs",sorted); + // we load the definitions backwards for priority. + for (int i=sorted.length()-1;i>=0;i--) + loadDefinition(sorted[i].toString()); + + //hook up table selection signal + connect(table,SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), + this, SLOT(selectedPack(QTableWidgetItem*,QTableWidgetItem*))); + //fill out table + refresh(); +} + +BlockIdentifier *DefinitionManager::blockIdentifier() +{ + return blocks; +} +BiomeIdentifier *DefinitionManager::biomeIdentifier() +{ + return biomes; +} +Dimensions *DefinitionManager::dimensions() +{ + return dimensionList; +} + +void DefinitionManager::refresh() +{ + table->clearContents(); + table->setRowCount(0); + QStringList types; + types<rowCount(); + table->insertRow(row); + QTableWidgetItem *name=new QTableWidgetItem(def.name); + name->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); + name->setData(Qt::UserRole,def.path); + table->setItem(row,0,name); + QTableWidgetItem *ver=new QTableWidgetItem(def.version); + ver->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); + ver->setData(Qt::UserRole,def.path); + table->setItem(row,1,ver); + QTableWidgetItem *type=new QTableWidgetItem(types[def.type]); + type->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); + type->setData(Qt::UserRole,def.path); + table->setItem(row,2,type); + QCheckBox *active=new QCheckBox; + active->setChecked(def.enabled); + connect(active,SIGNAL(toggled(bool)), + this,SLOT(toggledPack(bool))); + checks.append(active); + table->setCellWidget(row,3,active); + } +} + +void DefinitionManager::selectedPack(QTableWidgetItem *item,QTableWidgetItem *) +{ + emit packSelected(item!=NULL); + if (item!=NULL) + selected=item->data(Qt::UserRole).toString(); + else + selected=QString(); +} + +void DefinitionManager::toggledPack(bool) +{ + qDebug()<<"toggled pack"; + //we disable the pack + //emit packsChanged() +} + +void DefinitionManager::addPack() +{ + QString packName=QFileDialog::getOpenFileName(this,tr("Open Pack"),QString(),tr("Definitions (*.zip *.json)")); + if (!packName.isEmpty()) + { + if (packName.endsWith(".json",Qt::CaseInsensitive)) //raw json + installJson(packName); + else + installZip(packName); + emit packsChanged(); + QSettings settings; + settings.setValue("packs",sorted); + refresh(); + } +} +void DefinitionManager::installJson(QString path,bool overwrite,bool install) +{ + QString destdir=QStandardPaths::writableLocation(QStandardPaths::DataLocation); + + JSONData *def; + QFile f(path); + f.open(QIODevice::ReadOnly); + try { + def=JSON::parse(f.readAll()); + f.close(); + } catch (JSONParseException e) { + f.close(); + QMessageBox::warning(this, + tr("Couldn't install %1").arg(path), + e.reason, + QMessageBox::Cancel); + return; + } + + QString key=def->at("name")->asString()+def->at("type")->asString(); + delete def; + QString dest=QDir::toNativeSeparators(destdir+"/"+QString("%1").arg(qHash(key))+".json"); + if (!QFile::exists(dest) || overwrite) + { + if (QFile::exists(dest) && install) + removeDefinition(dest); + if (!QFile::copy(path,dest)) + { + QMessageBox::warning(this, + tr("Couldn't install %1").arg(path), + tr("Copy error"), + QMessageBox::Cancel); + return; + } + sorted.prepend(dest); + if (install) + loadDefinition(dest); + } +} +void DefinitionManager::installZip(QString path,bool overwrite,bool install) +{ + QString destdir=QStandardPaths::writableLocation(QStandardPaths::DataLocation); + ZipReader zip(path); + if (!zip.open()) + { + QMessageBox::warning(this, + tr("Couldn't install %1").arg(path), + tr("Corrupt zip"), + QMessageBox::Cancel); + return; + } + //fetch the pack info + JSONData *info; + try { + info=JSON::parse(zip.get("pack_info.json")); + } catch (JSONParseException e) { + QMessageBox::warning(this, + tr("Couldn't install %1").arg(path), + tr("pack_info.json : %1").arg(e.reason), + QMessageBox::Cancel); + zip.close(); + return; + } + // let's verify all the jsons in the pack + for (int i=0;iat("data")->length();i++) + { + JSONData *def; + try { + def=JSON::parse(zip.get(info->at("data")->at(i)->asString())); + } catch (JSONParseException e) { + QMessageBox::warning(this, + tr("Couldn't install %1").arg(path), + tr("%1: %2").arg(info->at("data")->at(i)->asString(),e.reason), + QMessageBox::Cancel); + delete def; + delete info; + zip.close(); + return; + } + } + + QString key=info->at("name")->asString()+info->at("type")->asString(); + delete info; + QString dest=QDir::toNativeSeparators(destdir+"/"+QString("%1").arg(qHash(key))+".zip"); + if (!QFile::exists(dest) || overwrite) + { + if (QFile::exists(dest) && install) + removeDefinition(dest); + if (!QFile::copy(path,dest)) + { + QMessageBox::warning(this, + tr("Couldn't install %1").arg(path), + tr("Copy error"), + QMessageBox::Cancel); + return; + } + sorted.prepend(dest); + if (install) + loadDefinition(dest); + } +} +void DefinitionManager::removePack() +{ + //find selected pack + if (definitions.contains(selected)) + { + int ret=QMessageBox::question(this, + tr("Delete Pack"), + tr("Are you sure you want to delete %1?").arg(definitions[selected].name), + QMessageBox::Yes|QMessageBox::No, + QMessageBox::No); + if (ret==QMessageBox::Yes) + removeDefinition(selected); + } +} + +void DefinitionManager::exportPack() +{ + //find selected pack + if (definitions.contains(selected)) + { + QString fname=definitions[selected].name; + switch (definitions[selected].type) + { + case Definition::Block: fname+="_blocks"; break; + case Definition::Biome: fname+="_biomes"; break; + case Definition::Dimension: fname+="_dims"; break; + default: break; + } + if (selected.endsWith(".zip")) + fname+=".zip"; + else + fname+=".json"; + QString dest=QFileDialog::getSaveFileName(this,tr("Save Pack As"),fname,tr("Definitions (*.zip *.json)")); + if (!dest.isEmpty()) + { + if (!QFile::copy(selected,dest)) + { + QMessageBox::warning(this, + tr("Couldn't write to %1").arg(dest), + tr("Copy error"), + QMessageBox::Cancel); + } + } + } +} + +QSize DefinitionManager::minimumSizeHint() const +{ + return QSize(300,300); +} +QSize DefinitionManager::sizeHint() const +{ + return QSize(400,300); +} + +void DefinitionManager::loadDefinition(QString path) +{ + //determine if we're loading a single json or a pack + if (path.endsWith(".json",Qt::CaseInsensitive)) + { + JSONData *def; + QFile f(path); + f.open(QIODevice::ReadOnly); + try { + def=JSON::parse(f.readAll()); + f.close(); + } catch (JSONParseException e) { + return; + } + Definition d; + d.name=def->at("name")->asString(); + d.version=def->at("version")->asString(); + d.path=path; + d.update=def->at("update")->asString(); + QString type=def->at("type")->asString(); + QString key=d.name+type; + d.enabled=true; //should look this up + if (type=="block") + { + d.id=blocks->addDefinitions(dynamic_cast(def->at("data"))); + d.type=Definition::Block; + } else if (type=="biome") { + d.id=biomes->addDefinitions(dynamic_cast(def->at("data"))); + d.type=Definition::Biome; + } else if (type=="dimension") { + d.id=dimensionList->addDefinitions(dynamic_cast(def->at("data"))); + d.type=Definition::Dimension; + } + definitions.insert(path,d); + delete def; + } + else + { + ZipReader zip(path); + if (!zip.open()) + return; + JSONData *info; + try { + info=JSON::parse(zip.get("pack_info.json")); + } catch (JSONParseException e) { + return; + } + Definition d; + d.name=info->at("name")->asString(); + d.version=info->at("version")->asString(); + d.update=info->at("update")->asString(); + d.path=path; + d.enabled=true; + d.id=0; + d.type=Definition::Pack; + d.blockid=-1; + d.biomeid=-1; + d.dimensionid=-1; + QString key=d.name+"pack"; + for (int i=0;iat("data")->length();i++) + { + JSONData *def; + try { + def=JSON::parse(zip.get(info->at("data")->at(i)->asString())); + } catch (JSONParseException e) { + continue; + } + QString type=def->at("type")->asString(); + if (type=="block") + d.blockid=blocks->addDefinitions(dynamic_cast(def->at("data")),d.blockid); + else if (type=="biome") + d.biomeid=biomes->addDefinitions(dynamic_cast(def->at("data")),d.biomeid); + else if (type=="dimension") + d.dimensionid=dimensionList->addDefinitions(dynamic_cast(def->at("data")),d.dimensionid); + delete def; + } + definitions.insert(path,d); + delete info; + zip.close(); + } +} +void DefinitionManager::removeDefinition(QString path) +{ + + //find the definition and remove it from disk + Definition &def=definitions[path]; + if (def.path==path) + { + switch (def.type) + { + case Definition::Block: + blocks->disableDefinitions(def.id); + break; + case Definition::Biome: + biomes->disableDefinitions(def.id); + break; + case Definition::Dimension: + dimensionList->disableDefinitions(def.id); + break; + case Definition::Pack: + blocks->disableDefinitions(def.blockid); + biomes->disableDefinitions(def.biomeid); + dimensionList->disableDefinitions(def.dimensionid); + break; + } + definitions.remove(path); + QFile::remove(path); + sorted.removeOne(path); + QSettings settings; + settings.setValue("packs",sorted); + emit packsChanged(); + refresh(); + } + +} + +void DefinitionManager::checkForUpdates() +{ + // show update dialog + if (!isUpdating) + autoUpdate(); + if (!isUpdating) // nothing needs updating + { + //hide update dialog + //show completion + } +} + +void DefinitionManager::autoUpdate() +{ + for (int i=0;iupdate(); + } + } +} + +void DefinitionManager::updatePack(DefinitionUpdater *updater,QString filename, QDateTime timestamp) +{ + updateQueue.removeOne(updater); + delete updater; + if (lastUpdated[filename]!=timestamp) + { + // updated + } + lastUpdated[filename]=timestamp; + if (updateQueue.isEmpty()) + emit updateFinished(); +} diff --git a/definitionmanager.h b/definitionmanager.h new file mode 100644 index 00000000..8bbe84a5 --- /dev/null +++ b/definitionmanager.h @@ -0,0 +1,112 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __DEFINITIONMANAGER_H__ +#define __DEFINITIONMANAGER_H__ + +#include +#include +#include +#include +#include +#include + +class QTableWidget; +class QTableWidgetItem; +class QCheckBox; +class BiomeIdentifier; +class BlockIdentifier; +class Dimensions; +class MapView; +class JSONData; +class DefinitionUpdater; + +struct Definition +{ + QString name; + QString version; + QString path; + QString update; + enum {Block,Biome,Dimension,Pack} type; + int id; + bool enabled; + // for packs only + int blockid,biomeid,dimensionid; +}; + +class DefinitionManager : public QWidget +{ + Q_OBJECT +public: + explicit DefinitionManager(QWidget *parent = 0); + void attachMapView(MapView *mapview); + QSize minimumSizeHint() const; + QSize sizeHint() const; + + BlockIdentifier *blockIdentifier(); + BiomeIdentifier *biomeIdentifier(); + Dimensions *dimensions(); + + void autoUpdate(); + +signals: + void packSelected(bool); + void packsChanged(); + void updateFinished(); + +public slots: + void selectedPack(QTableWidgetItem *,QTableWidgetItem *); + void toggledPack(bool); + void addPack(); + void removePack(); + void exportPack(); + void checkForUpdates(); + void updatePack(DefinitionUpdater *updater,QString filename,QDateTime timestamp); + +private: + QTableWidget *table; + QListchecks; + void installJson(QString path,bool overwrite=true,bool install=true); + void installZip(QString path,bool overwrite=true,bool install=true); + void loadDefinition(QString path); + void loadDefinition(JSONData *,int pack=-1); + void removeDefinition(QString path); + void refresh(); + QHash definitions; + BiomeIdentifier *biomes; + BlockIdentifier *blocks; + Dimensions *dimensionList; + QString selected; + QList sorted; + + bool isUpdating; + QList updateQueue; + QHash lastUpdated; +}; + +#endif diff --git a/definitions/vanilla_biomes.json b/definitions/vanilla_biomes.json new file mode 100644 index 00000000..be6494b9 --- /dev/null +++ b/definitions/vanilla_biomes.json @@ -0,0 +1 @@ +{"name":"Vanilla","type":"biome","version":"1.4.5","data":[{"id":0,"name":"Ocean"},{"id":1,"name":"Plains"},{"id":2,"name":"Desert"},{"id":3,"name":"Extreme Hills"},{"id":4,"name":"Forest"},{"id":5,"name":"Taiga"},{"id":6,"name":"Swampland"},{"id":7,"name":"River"},{"id":8,"name":"Hell"},{"id":9,"name":"Sky"},{"id":10,"name":"Frozen Ocean"},{"id":11,"name":"Frozen River"},{"id":12,"name":"Ice Plains"},{"id":13,"name":"Ice Mountains"},{"id":14,"name":"Mushroom Island"},{"id":15,"name":"Mushroom Island Shore"},{"id":16,"name":"Beach"},{"id":17,"name":"Desert Hills"},{"id":18,"name":"Forest Hills"},{"id":19,"name":"Taiga Hills"},{"id":20,"name":"Extreme Hills Edge"},{"id":21,"name":"Jungle"},{"id":22,"name":"Jungle Hills"}],"update":"http://seancode.com/minutor/packs/vanilla_biomes.json"} \ No newline at end of file diff --git a/definitions/vanilla_dims.json b/definitions/vanilla_dims.json new file mode 100644 index 00000000..f15bdf37 --- /dev/null +++ b/definitions/vanilla_dims.json @@ -0,0 +1 @@ +{"name":"Vanilla","type":"dimension","version":"1.4.5","data":[{"name":"Overworld","path":".","scale":1},{"name":"Nether","path":"DIM-1","scale":8},{"name":"End","path":"DIM1","scale":0}],"update":"http://seancode.com/minutor/packs/vanilla_dims.json"} \ No newline at end of file diff --git a/definitions/vanilla_ids.json b/definitions/vanilla_ids.json new file mode 100644 index 00000000..df926728 --- /dev/null +++ b/definitions/vanilla_ids.json @@ -0,0 +1 @@ +{"name":"Vanilla","type":"block","version":"1.4.5","data":[{"id":0,"name":"Air","flags":1},{"id":1,"name":"Stone","color":"747474"},{"id":2,"name":"Grass","color":"78bf64"},{"id":3,"name":"Dirt","color":"966c4a"},{"id":4,"name":"Cobblestone","color":"8f8f8f"},{"id":5,"name":"Oak Plank","color":"b4905a","variants":[{"data":1,"name":"Spruce Plank","color":"805e36"},{"data":2,"name":"Birch Plank","color":"c8b77a"},{"data":3,"name":"Jungle Plank","color":"b1805c"}]},{"id":6,"name":"Oak Sapling","color":"1f6519","mask":3,"flags":1,"variants":[{"data":1,"name":"Spruce Sapling","color":"395a39"},{"data":2,"name":"Birch Sapling","color":"51742d"},{"data":3,"name":"Jungle Sapling","color":"2c6c18"}]},{"id":7,"name":"Bedrock","color":"333333"},{"id":8,"name":"Water","color":"1f55ff","alpha":0.53,"flags":5},{"id":9,"name":"Water","color":"1f55ff","alpha":0.53,"flags":5},{"id":10,"name":"Lava","color":"fc5700","flags":5},{"id":11,"name":"Lava","color":"fc5700","flags":5},{"id":12,"name":"Sand","color":"d6cf97"},{"id":13,"name":"Gravel","color":"817f7f"},{"id":14,"name":"Gold Ore","color":"fcee4b"},{"id":15,"name":"Iron Ore","color":"af8e77"},{"id":16,"name":"Coal Ore","color":"454545"},{"id":17,"name":"Oak Wood","color":"665130","mask":3,"variants":[{"data":1,"name":"Spruce Wood","color":"2e1d0a"},{"data":2,"name":"Birch Wood","color":"d6dad6"},{"data":3,"name":"Jungle Wood","color":"584219"}]},{"id":18,"name":"Oak Leaves","color":"3d9b3d","flags":3,"mask":3,"variants":[{"data":1,"name":"Spruce Leaves","color":"519b5a"},{"data":2,"name":"Birch Leaves","color":"6faa3b"},{"data":3,"name":"Jungle Leaves","color":"649642"}]},{"id":19,"name":"Sponge","color":"d3d34b"},{"id":20,"name":"Glass","color":"c0f5fe","alpha":0.5,"flags":3},{"id":21,"name":"Lapis Lazuli Ore","color":"1b43ad"},{"id":22,"name":"Lapis Lazuli Block","color":"0f26b8"},{"id":23,"name":"Dispenser","color":"848484"},{"id":24,"name":"Sandstone","color":"dfd7a5","variants":[{"data":1,"name":"Chiseled Sandstone","color":"ddd8ab"},{"data":2,"name":"Smooth Sandstone","color":"d9d29a"}]},{"id":25,"name":"Note Block","color":"915840"},{"id":26,"name":"Bed","color":"8c1616","flags":3},{"id":27,"name":"Powered Rail","color":"ab0301","flags":1},{"id":28,"name":"Detector Rail","color":"7d7171","flags":1},{"id":29,"name":"Sticky Piston","color":"7bc070","flags":3},{"id":30,"name":"Cobweb","color":"ededed","flags":1},{"id":31,"name":"Dead Shrub","color":"946428","flags":1,"variants":[{"data":1,"name":"Tall Grass","color":"83bf54"},{"data":2,"name":"Fern","color":"8fbb64"}]},{"id":32,"name":"Dead Bush","color":"946428","flags":1},{"id":33,"name":"Piston","color":"9f844d","flags":3},{"id":34,"name":"Piston Extension","color":"b4905a"},{"id":35,"name":"White Wool","color":"eaeaea","variants":[{"data":1,"name":"Orange Wool","color":"db7b3b"},{"data":2,"name":"Magenta Wool","color":"af44b8"},{"data":3,"name":"Light Blue Wool","color":"7e99d0"},{"data":4,"name":"Yellow Wool","color":"bcb02a"},{"data":5,"name":"Lime Wool","color":"44b93b"},{"data":6,"name":"Pink Wool","color":"d28a9e"},{"data":7,"name":"Gray Wool","color":"454545"},{"data":8,"name":"Light Gray Wool","color":"909898"},{"data":9,"name":"Cyan Wool","color":"30728e"},{"data":10,"name":"Purple Wool","color":"7737ad"},{"data":11,"name":"Blue Wool","color":"2b3585"},{"data":12,"name":"Brown Wool","color":"563822"},{"data":13,"name":"Green Wool","color":"314119"},{"data":14,"name":"Red Wool","color":"91312f"},{"data":15,"name":"Black Wool","color":"1d1b1b"}]},{"id":37,"name":"Dandelion","color":"f1f902","flags":1},{"id":38,"name":"Rose","color":"d10609","flags":1},{"id":39,"name":"Brown Mushroom","color":"916d55","flags":1},{"id":40,"name":"Red Mushroom","color":"e21212","flags":1},{"id":41,"name":"Gold Block","color":"fdfb4f"},{"id":42,"name":"Iron Block","color":"e6e6e6"},{"id":43,"name":"Double Stone Slab","color":"a3a3a3","variants":[{"data":1,"name":"Double Sandstone Slab","color":"d7ce95"},{"data":2,"name":"Double Wooden Slab","color":"b4905a"},{"data":3,"name":"Double Cobblestone Slab","color":"8f8f8f"},{"data":4,"name":"Double Brick Slab","color":"7c4536"},{"data":5,"name":"Double Stone Brick Slab","color":"797979"}]},{"id":44,"name":"Stone Slab","color":"a3a3a3","mask":7,"flags":3,"variants":[{"data":1,"name":"Sandstone Slab","color":"d7ce95"},{"data":2,"name":"Wooden Slab","color":"b4905a"},{"data":3,"name":"Cobblestone Slab","color":"8f8f8f"},{"data":4,"name":"Brick Slab","color":"7c4536"},{"data":5,"name":"Stone Brick Slab","color":"797979"}]},{"id":45,"name":"Bricks","color":"6a3b2e"},{"id":46,"name":"TNT","color":"a83414","flags":3},{"id":47,"name":"Bookshelf","color":"9f844d"},{"id":48,"name":"Moss Stone","color":"3a623a"},{"id":49,"name":"Obsidian","color":"0e0e16"},{"id":50,"name":"Torch","color":"ffd800","flags":1},{"id":51,"name":"Fire","color":"ff8f00","flags":1},{"id":52,"name":"Monster Spawner","color":"1b2a35","flags":3},{"id":53,"name":"Oak Wood Stairs","color":"9f844d","flags":3},{"id":54,"name":"Chest","color":"976b20","flags":3},{"id":55,"name":"Redstone Wire","color":"d60000","flags":1},{"id":56,"name":"Diamond Ore","color":"5decf5"},{"id":57,"name":"Diamond Block","color":"91e8e4"},{"id":58,"name":"Crafting Table","color":"a0693c"},{"id":59,"name":"Immature Wheat","color":"8ba803","flags":1,"variants":[{"data":7,"name":"Grown Wheat","color":"8e7c10"}]},{"id":60,"name":"Wet Farmland","color":"43240b","flags":3,"variants":[{"data":0,"name":"Dry Farmland","color":"633f24"}]},{"id":61,"name":"Furnace","color":"535353"},{"id":62,"name":"Burning Furnace","color":"535353"},{"id":63,"name":"Sign Post","color":"9f844d","flags":1},{"id":64,"name":"Wooden Door","color":"b0572a","flags":3},{"id":65,"name":"Ladder","color":"8e733c","flags":3},{"id":66,"name":"Rail","color":"a4a4a4","flags":1},{"id":67,"name":"Cobblestone Stairs","color":"565656","flags":3},{"id":68,"name":"Wall Sign","color":"b4905a","flags":1},{"id":69,"name":"Lever","color":"735e39","flags":1},{"id":70,"name":"Stone Pressure Plate","color":"8f8f8f","flags":1},{"id":71,"name":"Iron Door","color":"b6b6b6","flags":3},{"id":72,"name":"Wooden Pressure Plate","color":"bc9862","flags":1},{"id":73,"name":"Redstone Ore","color":"8f0303"},{"id":74,"name":"Redstone Ore","color":"8f0303"},{"id":75,"name":"Redstone Torch (off)","color":"480000","flags":1},{"id":76,"name":"Redstone Torch (on)","color":"fd0000","flags":1},{"id":77,"name":"Stone Button","color":"a8a8a8","flags":1},{"id":78,"name":"Snow","color":"eeffff","flags":1},{"id":79,"name":"Ice","color":"77a9ff","alpha":0.62,"flags":3},{"id":80,"name":"Snow Block","color":"eeffff"},{"id":81,"name":"Cactus","color":"107e1d","flags":1},{"id":82,"name":"Clay Block","color":"9da3ae"},{"id":83,"name":"Sugar Cane","color":"aadb74","flags":1},{"id":84,"name":"Jukebox","color":"945f44"},{"id":85,"name":"Fence","color":"735e39","flags":3},{"id":86,"name":"Pumpkin","color":"e3901d"},{"id":87,"name":"Netherrack","color":"955744"},{"id":88,"name":"Soul Sand","color":"554134"},{"id":89,"name":"Glowstone Block","color":"f9d49c","flags":3},{"id":90,"name":"Nether Portal","color":"d67fff","flags":1},{"id":91,"name":"Jack o' Lantern","color":"e9b416"},{"id":92,"name":"Cake Block","color":"eae9eb","flags":3},{"id":93,"name":"Redstone Repeater (off)","color":"2a0002","flags":3},{"id":94,"name":"Redstone Repeater (on)","color":"fd0101","flags":3},{"id":95,"name":"Locked Chest","color":"976b20","flags":3},{"id":96,"name":"Trapdoor","color":"8f6b35","flags":3},{"id":97,"name":"Monster Egg","color":"767676","variants":[{"data":1,"color":"919191"},{"data":2,"color":"7b7b7b"}]},{"id":98,"name":"Stone Brick","color":"797979","variants":[{"data":1,"name":"Mossy Stone Brick","color":"637049"},{"data":2,"name":"Cracked Stone Brick","color":"656565"},{"data":3,"name":"Chiseled Stone Brick","color":"9c9c9c"}]},{"id":99,"name":"Huge Brown Mushroom","color":"d2b17d","variants":[{"data":1,"color":"8f6b53"},{"data":2,"color":"8f6b53"},{"data":3,"color":"8f6b53"},{"data":4,"color":"8f6b53"},{"data":5,"color":"8f6b53"},{"data":6,"color":"8f6b53"},{"data":7,"color":"8f6b53"},{"data":8,"color":"8f6b53"},{"data":9,"color":"8f6b53"}]},{"id":100,"name":"Huge Red Mushroom","color":"d2b17d","variants":[{"data":1,"color":"b51d1b"},{"data":2,"color":"b51d1b"},{"data":3,"color":"b51d1b"},{"data":4,"color":"b51d1b"},{"data":5,"color":"b51d1b"},{"data":6,"color":"b51d1b"},{"data":7,"color":"b51d1b"},{"data":8,"color":"b51d1b"},{"data":9,"color":"b51d1b"}]},{"id":101,"name":"Iron Bars","color":"6d6e6e","flags":3},{"id":102,"name":"Glass Pane","color":"c0f5fe","alpha":0.5,"flags":3},{"id":103,"name":"Melon","color":"adb82c"},{"id":104,"name":"Pumpkin Stem","color":"6b6b0b","flags":1},{"id":105,"name":"Melon Stem","color":"6b6b0b","flags":1},{"id":106,"name":"Vines","color":"6cc44a","flags":1},{"id":107,"name":"Fence Gate","color":"9f844d","flags":3},{"id":108,"name":"Brick Stairs","color":"7c4536","flags":3},{"id":109,"name":"Stone Brick Stairs","color":"727272","flags":3},{"id":110,"name":"Mycelium","color":"806b6f"},{"id":111,"name":"Lily Pad","color":"88bf54"},{"id":112,"name":"Nether Brick","color":"30181c"},{"id":113,"name":"Nether Brick Fence","color":"1c0e10","flags":3},{"id":114,"name":"Nether Brick Stairs","color":"381a1f","flags":3},{"id":115,"name":"Immature Nether Wart","color":"70081c","flags":1,"variants":[{"data":3,"name":"Mature Nether Wart","color":"8e181b"}]},{"id":116,"name":"Enchantment Table","color":"3c3056","flags":1},{"id":117,"name":"Brewing Stand","color":"bea84a","flags":1},{"id":118,"name":"Cauldron","color":"4d4d4d"},{"id":119,"name":"End Portal","color":"0c0b0a","flags":1},{"id":120,"name":"End Portal Frame","color":"2f5754","mask":4,"variants":[{"data":4,"name":"End Portal Frame (on)","color":"406852"}]},{"id":121,"name":"End Stone","color":"d9dc9e"},{"id":122,"name":"Dragon Egg","color":"2d0133"},{"id":123,"name":"Redstone Lamp (off)","color":"b0744c"},{"id":124,"name":"Redstone Lamp (on)","color":"f1d1af"},{"id":125,"name":"Double Oak Slab","color":"b4905a","variants":[{"data":1,"name":"Double Spruce Slab","color":"664f2f"},{"data":2,"name":"Double Birch Slab","color":"d7cb8d"},{"data":3,"name":"Double Jungle Slab","color":"b1805c"}]},{"id":126,"name":"Oak Slab","color":"b4905a","mask":7,"flags":3,"variants":[{"data":1,"name":"Spruce Slab","color":"664f2f"},{"data":2,"name":"Birch Slab","color":"d7cb8d"},{"data":3,"name":"Jungle Slab","color":"b1805c"}]},{"id":127,"name":"Immature Cocoa Pod","color":"929943","mask":12,"variants":[{"data":8,"name":"Mature Cocoa Pod","color":"d4924c"}]},{"id":128,"name":"Sandstone Stairs","color":"e9e0b3","flags":3},{"id":129,"name":"Emerald Ore","color":"17dd62"},{"id":130,"name":"Ender Chest","color":"2d4042","flags":3},{"id":131,"name":"Tripwire Hook","color":"6e6e6e","flags":1},{"id":132,"name":"Tripwire","color":"ebebeb","flags":1},{"id":133,"name":"Emerald Block","color":"64ea8a"},{"id":134,"name":"Spruce Wood Stairs","color":"664f2f","flags":3},{"id":135,"name":"Birch Wood Stairs","color":"d7cb8d","flags":3},{"id":136,"name":"Jungle Wood Stairs","color":"b1805c","flags":3},{"id":137,"name":"Command Block","color":"cfa68b"},{"id":138,"name":"Beacon","color":"c4fffe"},{"id":139,"name":"Cobblestone Wall","color":"505050","flags":3},{"id":140,"name":"Flower Pot (empty)","color":"7c4536","flags":1,"variants":[{"data":1,"name":"Flower Pot (rose)","color":"910205"},{"data":2,"name":"Flower Pot (dandelion)","color":"f1f902"},{"data":3,"name":"Flower Pot (oak)","color":"408f2f"},{"data":4,"name":"Flower Pot (spruce)","color":"395a39"},{"data":5,"name":"Flower Pot (birch)","color":"cfe3ba"},{"data":6,"name":"Flower Pot (jungle)","color":"2c6c18"},{"data":7,"name":"Flower Pot (red mushroom)","color":"9a171c"},{"data":8,"name":"Flower Pot (brown mushroom)","color":"725643"},{"data":9,"name":"Flower Pot (cactus)","color":"128a20"},{"data":10,"name":"Flower Pot (dead bush)","color":"946428"},{"data":11,"name":"Flower Pot (fern)","color":"315e05"}]},{"id":141,"name":"Immature Carrots","color":"00c617","flags":1,"variants":[{"data":7,"name":"Mature Carrots","color":"004e00"}]},{"id":142,"name":"Immature Potatoes","color":"00c617","flags":1,"variants":[{"data":7,"name":"Mature Potatoes","color":"3aa649"}]},{"id":143,"name":"Wooden Button","color":"b4905a","flags":1},{"id":144,"name":"Head","color":"1a1a1a","flags":1},{"id":145,"name":"Anvil","color":"474747"}],"update":"http://seancode.com/minutor/packs/vanilla_ids.json"} \ No newline at end of file diff --git a/definitionupdater.cpp b/definitionupdater.cpp new file mode 100644 index 00000000..598250c8 --- /dev/null +++ b/definitionupdater.cpp @@ -0,0 +1,89 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "definitionupdater.h" +#include +#include +#include +#include + +DefinitionUpdater::DefinitionUpdater(QString filename, + QString url, + QDateTime timestamp) : filename(filename), url(url), timestamp(timestamp) +{ + save=NULL; +} + +void DefinitionUpdater::update() +{ + reply=qnam.head(QNetworkRequest(url)); + connect(reply,SIGNAL(finished()), + this,SLOT(checkTime())); +} + +void DefinitionUpdater::checkTime() +{ + QVariant redir=reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (!redir.isNull()) + { + reply->deleteLater(); + url=redir.toUrl(); + update(); + return; + } + QVariant lmod=reply->header(QNetworkRequest::LastModifiedHeader); + if (lmod.isValid() && lmod.toDateTime()>timestamp) + { + timestamp=lmod.toDateTime(); + qDebug()<<"timestamp:"<deleteLater(); + reply=qnam.get(QNetworkRequest(url)); + save=new QFile(filename); + save->open(QIODevice::WriteOnly); + connect(reply,SIGNAL(finished()), + this,SLOT(didUpdate())); + connect(reply,SIGNAL(readyRead()), + this,SLOT(saveFile())); + return; + } + reply->deleteLater(); + // no need to update + emit updated(this,filename,timestamp); +} +void DefinitionUpdater::didUpdate() +{ + save->flush(); + save->close(); + delete save; + save=NULL; + emit updated(this,filename,timestamp); +} +void DefinitionUpdater::saveFile() +{ + if (save) + save->write(reply->readAll()); +} diff --git a/definitionupdater.h b/definitionupdater.h new file mode 100644 index 00000000..10f1970d --- /dev/null +++ b/definitionupdater.h @@ -0,0 +1,59 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __DEFINITIONUPDATER_H__ +#define __DEFINITIONUPDATER_H__ + +#include +#include +#include +#include + +class QFile; +class QNetworkReply; + +class DefinitionUpdater : public QObject +{ + Q_OBJECT +public: + DefinitionUpdater(QString filename,QString url,QDateTime timestamp); + void update(); +signals: + void updated(DefinitionUpdater *,QString filename,QDateTime timestamp); +private slots: + void checkTime(); + void didUpdate(); + void saveFile(); +private: + QString filename; + QUrl url; + QDateTime timestamp; + QNetworkAccessManager qnam; + QNetworkReply *reply; + QFile *save; +}; + +#endif diff --git a/dimensions.cpp b/dimensions.cpp new file mode 100644 index 00000000..fec45206 --- /dev/null +++ b/dimensions.cpp @@ -0,0 +1,207 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "dimensions.h" +#include +#include +#include "json.h" + +class DimensionDef +{ +public: + DimensionDef() {} + QString name; + QString path; + int scale; + bool regex; + bool enabled; +}; + +Dimensions::Dimensions() +{ + group=NULL; +} +Dimensions::~Dimensions() +{ +} + +void Dimensions::enableDefinitions(int pack) +{ + if (pack<0) return; + int len=packs[pack].length(); + for (int i=0;ienabled=true; +} +void Dimensions::disableDefinitions(int pack) +{ + if (pack<0) return; + int len=packs[pack].length(); + for (int i=0;ienabled=false; +} + +int Dimensions::addDefinitions(JSONArray *defs,int pack) +{ + if (pack==-1) + { + pack=packs.length(); + packs.append(QList()); + } + + int len=defs->length(); + for (int i=0;i(defs->at(i)); + DimensionDef *dim=new DimensionDef(); + dim->enabled=true; + if (d->has("name")) + dim->name=d->at("name")->asString(); + else + dim->name="Unknown"; + if (d->has("path")) + dim->path=d->at("path")->asString(); + else + dim->path="."; + if (d->has("scale")) + dim->scale=d->at("scale")->asNumber(); + else + dim->scale=1; + if (d->has("regex")) + dim->regex=d->at("regex")->asBool(); + else + dim->regex=false; + definitions.append(dim); + packs[pack].append(dim); + } + return pack; +} + +void Dimensions::removeDimensions(QMenu *menu) +{ + for (int i=0;iremoveAction(items[i]); + delete items[i]; + } + items.clear(); + dimensions.clear(); + foundDimensions.clear(); + menu->setEnabled(false); + if (group!=NULL) + { + delete group; + group=NULL; + } +} +void Dimensions::getDimensions(QDir path,QMenu *menu,QObject *parent) +{ + //first get the currently selected dimension so it doesn't change + QString current; + for (int i=0;iisChecked()) + current=dimensions[i].path; + removeDimensions(menu); + group=new QActionGroup(parent); + + for (int i=0;ienabled) + { + //check path for regex + if (definitions[i]->regex) + { + QDirIterator it(path.absolutePath(),QDir::Dirs); + QRegExp rx(definitions[i]->path); + while (it.hasNext()) + { + it.next(); + if (rx.indexIn(it.fileName())!=-1) + { + QString name=definitions[i]->name; + for (int c=0;cscale,parent); + } + } + } + else + addDimension(path,definitions[i]->path,definitions[i]->name,definitions[i]->scale,parent); + } + } + menu->addActions(items); + if (items.count()>0) + { + bool changed=true; + //locate our old selected item + for (int i=0;idata().toInt()].path==current) + { + items[i]->setChecked(true); + changed=false; + break; + } + if (changed) + { + items.first()->setChecked(true); + emit dimensionChanged(dimensions[items.first()->data().toInt()]); + } + menu->setEnabled(true); + } +} + +void Dimensions::addDimension(QDir path,QString dir,QString name,int scale,QObject *parent) +{ + if (!path.exists(dir)) + return; + + if (foundDimensions.contains(dir)) + return; + + path.cd(dir); + if (path.exists("region")) //is it a used dimension? + { + QAction *d=new QAction(parent); + d->setText(name); + d->setData(dimensions.count()); + dimensions.append(Dimension(path.absolutePath(),scale)); + d->setCheckable(true); + parent->connect(d, SIGNAL(triggered()), + this, SLOT(viewDimension())); + group->addAction(d); + items.append(d); + foundDimensions.insert(dir,true); + } + path.cdUp(); +} + +void Dimensions::viewDimension() +{ + QAction *action=qobject_cast(sender()); + if (action) + emit dimensionChanged(dimensions[action->data().toInt()]); +} diff --git a/dimensions.h b/dimensions.h new file mode 100644 index 00000000..b2efbe9b --- /dev/null +++ b/dimensions.h @@ -0,0 +1,78 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __DIMENSIONS_H__ +#define __DIMENSIONS_H__ + +#include +#include +#include +#include + +class QMenu; +class QAction; +class QActionGroup; +class JSONArray; + +class Dimension +{ +public: + Dimension(QString path,int scale):path(path),scale(scale) {} + QString path; + int scale; +}; + +class DimensionDef; + +class Dimensions : public QObject +{ + Q_OBJECT +public: + Dimensions(); + ~Dimensions(); + int addDefinitions(JSONArray *,int pack=-1); + void enableDefinitions(int); + void disableDefinitions(int); + void getDimensions(QDir path,QMenu *menu,QObject *parent); + void removeDimensions(QMenu *menu); +signals: + void dimensionChanged(Dimension &dim); +private slots: + void viewDimension(); +private: + void addDimension(QDir path,QString dir,QString name,int scale,QObject *parent); + QList items; + QList dimensions; + QList definitions; + QList > packs; + QActionGroup *group; + + QHash foundDimensions; +}; + +#endif diff --git a/json.cpp b/json.cpp new file mode 100644 index 00000000..17038caa --- /dev/null +++ b/json.cpp @@ -0,0 +1,380 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "json.h" +#include + +enum Token { + TokenNULL, + TokenTRUE, + TokenFALSE, + TokenString, + TokenNumber, + TokenObject, + TokenArray, + TokenObjectClose, + TokenArrayClose, + TokenKeySeparator, + TokenValueSeparator +}; + +class JSONHelper +{ +public: + JSONHelper(QString data) : data(data) {pos=0;len=data.length();} + ~JSONHelper() {} + Token nextToken() + { + while (pos='0' && c<='9') + num|=c-'0'; + else if (c>='a' && c<='f') + num|=c-'a'+10; + else if (c>='A' && c<='F') + num|=c-'A'+10; + else throw JSONParseException("Invalid hex code",location()); + } + r+=QChar(num); + } + break; + default: throw JSONParseException("Unknown escape sequence",location()); + } + } + else + r+=data.at(pos++); + } + pos++; + return r; + } + double readDouble() + { + double sign=1.0; + if (data.at(pos)=='-') + { + sign=-1.0; + pos++; + } + else if (data.at(pos)=='+') + pos++; + double value=0.0; + while (pos308) expon=308; + while (expon>=50) {scale *= 1E50; expon-=50; } + while (expon>=8) {scale *=1E8; expon-=8; } + while (expon>0) {scale*=10.0; expon-=1;} + } + return sign*(frac?(value/scale):(value*scale)); + } + QString location() + { + int line=1; + int col=0; + int cpos=pos; + bool doneCol=false; + while (cpos>=0) + { + if (data.at(cpos)=='\n') + { + doneCol=true; + line++; + } + if (!doneCol) col++; + cpos--; + } + return QString("Line: %1, Offset: %2").arg(line).arg(col); + } +private: + int pos,len; + QString data; +}; + +JSONData *JSON::parse(const QString data) +{ + JSONHelper reader(data); + Token type=reader.nextToken(); + switch (type) + { + case TokenObject: //hash + return new JSONObject(reader); + case TokenArray: //array + return new JSONArray(reader); + default: + throw JSONParseException("Doesn't start with object or array",reader.location()); + break; + } + return NULL; +} +static JSONData Null; +JSONData::JSONData() +{ +} +JSONData::~JSONData() +{ +} +bool JSONData::has(const QString) +{ + return false; +} +JSONData *JSONData::at(const QString) +{ + return &Null; +} +JSONData *JSONData::at(int) +{ + return &Null; +} +int JSONData::length() +{ + return 0; +} +QString JSONData::asString() +{ + return ""; +} +double JSONData::asNumber() +{ + return 0.0; +} +bool JSONData::asBool() +{ + return false; +} + +JSONBool::JSONBool(bool val) +{ + data=val; +} +bool JSONBool::asBool() +{ + return data; +} + +JSONString::JSONString(QString val) +{ + data=val; +} +QString JSONString::asString() +{ + return data; +} + +JSONNumber::JSONNumber(double val) +{ + data=val; +} +double JSONNumber::asNumber() +{ + return data; +} + +JSONObject::JSONObject(JSONHelper &reader) +{ + while (true) + { + Token type=reader.nextToken(); + if (type==TokenObjectClose) + break; + if (type!=TokenString) + throw JSONParseException("Expected quoted string",reader.location()); + QString key=reader.readString(); + if (key.length()==0) throw JSONParseException("Empty object key",reader.location()); + if (reader.nextToken()!=TokenKeySeparator) throw JSONParseException("Expected ':'",reader.location()); + JSONData *value; + switch (reader.nextToken()) + { + case TokenNULL: value=NULL; break; + case TokenTRUE: value=new JSONBool(true); break; + case TokenFALSE: value=new JSONBool(false); break; + case TokenString: value=new JSONString(reader.readString()); break; + case TokenNumber: value=new JSONNumber(reader.readDouble()); break; + case TokenObject: value=new JSONObject(reader); break; + case TokenArray: value=new JSONArray(reader); break; + default: throw JSONParseException("Expected value",reader.location()); + } + children[key]=value; + type=reader.nextToken(); //comma or end + if (type==TokenObjectClose) + break; + if (type!=TokenValueSeparator) + throw JSONParseException("Expected ',' or '}'",reader.location()); + } +} +JSONObject::~JSONObject() +{ + QHash::const_iterator i; + for (i=children.constBegin();i!=children.constEnd();i++) + delete i.value(); +} +bool JSONObject::has(QString key) +{ + return children.contains(key); +} +JSONData *JSONObject::at(QString key) +{ + if (children.contains(key)) + return children[key]; + return &Null; +} + +JSONArray::JSONArray(JSONHelper &reader) +{ + while (true) + { + Token type=reader.nextToken(); + if (type==TokenArrayClose) + break; + JSONData *value; + switch (type) + { + case TokenNULL: value=NULL; break; + case TokenTRUE: value=new JSONBool(true); break; + case TokenFALSE: value=new JSONBool(false); break; + case TokenString: value=new JSONString(reader.readString()); break; + case TokenNumber: value=new JSONNumber(reader.readDouble()); break; + case TokenObject: value=new JSONObject(reader); break; + case TokenArray: value=new JSONArray(reader); break; + default: throw JSONParseException("Expected Value",reader.location()); + } + data.append(value); + type=reader.nextToken(); //comma or end + if (type==TokenArrayClose) + break; + if (type!=TokenValueSeparator) + throw JSONParseException("Expected ',' or ']'",reader.location()); + } +} +JSONArray::~JSONArray() +{ + QList::const_iterator i; + for (i=data.constBegin();i!=data.constEnd();i++) + delete *i; +} +int JSONArray::length() +{ + return data.length(); +} +JSONData *JSONArray::at(int index) +{ + if (index +#include + +class JSONHelper; + +class JSONData +{ +public: + JSONData(); + virtual ~JSONData(); + virtual bool has(const QString key); + virtual JSONData *at(const QString key); + virtual JSONData *at(int index); + virtual int length(); + virtual QString asString(); + virtual double asNumber(); + virtual bool asBool(); +}; + +class JSONBool : public JSONData +{ +public: + JSONBool(bool val); + bool asBool(); +private: + bool data; +}; + +class JSONString : public JSONData +{ +public: + JSONString(QString val); + QString asString(); +private: + QString data; +}; + +class JSONNumber : public JSONData +{ +public: + JSONNumber(double val); + double asNumber(); +private: + double data; +}; + +class JSONObject : public JSONData +{ +public: + JSONObject(JSONHelper &); + ~JSONObject(); + bool has(const QString key); + JSONData *at(const QString key); +private: + QHashchildren; +}; +class JSONArray : public JSONData +{ +public: + JSONArray(JSONHelper &); + ~JSONArray(); + JSONData *at(int index); + int length(); +private: + QListdata; +}; + +class JSONParseException +{ +public: + JSONParseException(QString reason,QString at) : reason(QString("%1 at %2").arg(reason).arg(at)) {} + QString reason; +}; + +class JSON +{ +public: + static JSONData *parse(const QString data); +}; + +#endif diff --git a/labelledslider.cpp b/labelledslider.cpp new file mode 100644 index 00000000..1cb7f430 --- /dev/null +++ b/labelledslider.cpp @@ -0,0 +1,68 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "labelledslider.h" +#include +#include +#include + +LabelledSlider::LabelledSlider(QWidget *parent) : QWidget(parent) +{ + slider = new QSlider(Qt::Horizontal); + slider->setRange(0,255); + + label = new QLabel(); + label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + label->setFixedWidth(label->fontMetrics().width("888")); + label->setNum(255); + + connect(slider, SIGNAL(valueChanged(int)), + this, SLOT(invValueChanged(int))); + + QHBoxLayout *myLayout = new QHBoxLayout; + myLayout->addWidget(slider); + myLayout->addWidget(label); + setLayout(myLayout); + setFocusProxy(slider); +} + +int LabelledSlider::value() const +{ + return 255-slider->value(); +} + +void LabelledSlider::setValue(int v) +{ + slider->setValue(255-v); +} + +void LabelledSlider::invValueChanged(int v) +{ + label->setNum(255-v); + emit valueChanged(255-v); +} diff --git a/OSX/Map.h b/labelledslider.h similarity index 63% rename from OSX/Map.h rename to labelledslider.h index 7fc72935..20b3a272 100644 --- a/OSX/Map.h +++ b/labelledslider.h @@ -1,17 +1,17 @@ /* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -25,25 +25,34 @@ THE POSSIBILITY OF SUCH DAMAGE. */ -#import - - -@interface Map : NSView { - int curDepth; - double curX,curZ,curScale; - NSString *world; - unsigned char *bits; - int curWidth,curHeight; - int moving; - id status; - int opts; -} --(void)setX:(double)x andZ:(double)z; --(void)setDepth:(int)depth; --(void)setWorld:(NSString *)newWorld; --(void)setStatus:(id)status; --(void)setOptions:(int)options; --(void)setColorScheme:(unsigned int *)colors; --(void)setProgress:(id)progress; - -@end + +#ifndef __LABELLEDSLIDER_H__ +#define __LABELLEDSLIDER_H__ + +#include + +class QSlider; +class QLabel; + +class LabelledSlider : public QWidget +{ + Q_OBJECT +public: + explicit LabelledSlider(QWidget *parent = 0); + int value() const; + +signals: + void valueChanged(int); + +public slots: + void setValue(int); + +private slots: + void invValueChanged(int); + +private: + QSlider *slider; + QLabel *label; +}; + +#endif diff --git a/OSX/ColorScheme.h b/main.cpp similarity index 56% rename from OSX/ColorScheme.h rename to main.cpp index f79c6c2a..4b9d1c93 100644 --- a/OSX/ColorScheme.h +++ b/main.cpp @@ -1,17 +1,17 @@ /* - Copyright (c) 2010, Sean Kasun - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -25,28 +25,27 @@ THE POSSIBILITY OF SUCH DAMAGE. */ -#import +#include +#include +#include +#include "minutor.h" -@interface ColorSchemes : NSObject { - NSMutableArray *schemes; - IBOutlet id menu; - IBOutlet id schemeList; - IBOutlet id schemesWin; - IBOutlet id schemeWin; - id standard; - int selected; -} --(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tc row:(NSInteger)row; --(void)tableView:(NSTableView *)tv setObjectValue:obj forTableColumn:(NSTableColumn *)tc row:(NSInteger)row; --(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView; +int main(int argc,char *argv[]) +{ + QApplication app(argc,argv); + + QString locale = QLocale::system().name(); --(void)readDefaults; --(void)select:sender; --(unsigned int *)current; + QTranslator translator; + translator.load(QString("minutor_")+locale); + app.installTranslator(&translator); --(IBAction)editColorSchemes:sender; --(IBAction)addOrRemove:sender; --(IBAction)edit:sender; + app.setApplicationName("Minutor"); + app.setApplicationVersion("2.0 beta"); + app.setOrganizationName("seancode"); -@end + Minutor minutor; + minutor.show(); + return app.exec(); +} diff --git a/mapview.cpp b/mapview.cpp new file mode 100644 index 00000000..cc42e799 --- /dev/null +++ b/mapview.cpp @@ -0,0 +1,384 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "mapview.h" +#include "definitionmanager.h" +#include "blockidentifier.h" +#include "biomeidentifier.h" +#include +#include + +MapView::MapView(QWidget *parent) : QWidget(parent) +{ + depth=255; + scale=1; + zoom=1.0; + connect(&cache, SIGNAL(chunkLoaded(int,int)), + this, SLOT(chunkUpdated(int,int))); + setMouseTracking(true); + + int offset=0; + for (int y=0;y<16;y++) + for (int x=0;x<16;x++) + { + uchar color=((x&8)^(y&8))==0?0x44:0x88; + placeholder[offset++]=color; + placeholder[offset++]=color; + placeholder[offset++]=color; + placeholder[offset++]=0xff; + } +} + +QSize MapView::minimumSizeHint() const +{ + return QSize(300,300); +} +QSize MapView::sizeHint() const +{ + return QSize(400,400); +} + +void MapView::attach(DefinitionManager *dm) +{ + this->dm=dm; + connect(dm,SIGNAL(packsChanged()), + this,SLOT(redraw())); + this->blocks=dm->blockIdentifier(); + this->biomes=dm->biomeIdentifier(); +} + +void MapView::setLocation(double x, double z) +{ + this->x=x/scale; + this->z=z/scale; + + redraw(); +} + +void MapView::setDimension(QString path, int scale) +{ + if (scale>0) + { + this->x*=this->scale; + this->z*=this->scale; //undo current scale transform + this->scale=scale; + this->x/=scale; //and do the new scale transform + this->z/=scale; + } + else + { + this->scale=1; //no scaling because no relation to overworld + this->x=0; //and we jump to the center spawn automatically + this->z=0; + } + cache.clear(); + cache.setPath(path); + redraw(); +} + +void MapView::setDepth(int depth) +{ + this->depth=depth; + redraw(); +} + +void MapView::chunkUpdated(int x, int z) +{ + drawChunk(x,z); + update(); +} + +static int lastX=-1,lastY=-1; +static bool dragging=false; +void MapView::mousePressEvent(QMouseEvent *event) +{ + lastX=event->x(); + lastY=event->y(); + dragging=true; +} +void MapView::mouseMoveEvent(QMouseEvent *event) +{ + if (!dragging) + { + int centerblockx=floor(this->x); + int centerblockz=floor(this->z); + + int centerx=image.width()/2; + int centery=image.height()/2; + + centerx-=(this->x-centerblockx)*zoom; + centery-=(this->z-centerblockz)*zoom; + + int mx=floor(centerblockx-(centerx-event->x())/zoom); + int mz=floor(centerblockz-(centery-event->y())/zoom); + + getToolTip(mx,mz); + return; + } + x+=(lastX-event->x())/zoom; + z+=(lastY-event->y())/zoom; + lastX=event->x(); + lastY=event->y(); + redraw(); +} +void MapView::mouseReleaseEvent(QMouseEvent *) +{ + dragging=false; +} +void MapView::wheelEvent(QWheelEvent *event) +{ + zoom+=floor(event->delta()/90.0); + if (zoom<1.0) zoom=1.0; + if (zoom>20.0) zoom=20.0; + redraw(); +} + +void MapView::resizeEvent(QResizeEvent *event) +{ + image=QImage(event->size(),QImage::Format_RGB32); + redraw(); +} +void MapView::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.drawImage(QPoint(0,0),image); + p.end(); +} + +void MapView::redraw() +{ + if (!this->isEnabled()) + return; + + double chunksize=16*zoom; + + //first find the center block position + int centerchunkx=floor(x/16); + int centerchunkz=floor(z/16); + // and the center of the screen + int centerx=image.width()/2; + int centery=image.height()/2; + // and align for panning + centerx-=(x-centerchunkx*16)*zoom; + centery-=(z-centerchunkz*16)*zoom; + // now calculate the topleft block on the screen + int startx=centerchunkx-floor(centerx/chunksize)-1; + int startz=centerchunkz-floor(centery/chunksize)-1; + // and the dimensions of the screen in blocks + int blockswide=image.width()/chunksize+3; + int blockstall=image.height()/chunksize+3; + + for (int z=startz;zisEnabled()) + return; + + uchar *src=placeholder; + //fetch the chunk + Chunk *chunk=cache.fetch(x,z); + + if (chunk && chunk->renderedAt!=depth) + renderChunk(chunk); + + //this figures out where on the screen this chunk should be drawn + + + // first find the center chunk + int centerchunkx=floor(this->x/16); + int centerchunkz=floor(this->z/16); + // and the center chunk screen coordinates + int centerx=image.width()/2; + int centery=image.height()/2; + // which need to be shifted to account for panning inside that chunk + centerx-=(this->x-centerchunkx*16)*zoom; + centery-=(this->z-centerchunkz*16)*zoom; + // centerx,y now points to the top left corner of the center chunk + // so now calculate our x,y in relation + double chunksize=16*zoom; + centerx+=(x-centerchunkx)*chunksize; + centery+=(z-centerchunkz)*chunksize; + + int srcoffset=0; + uchar *bits=image.bits(); + int imgstride=image.bytesPerLine(); + + int skipx=0,skipy=0; + int blockwidth=chunksize,blockheight=chunksize; + // now if we're off the screen we need to crop + if (centerx<0) + { + skipx=-centerx; + centerx=0; + } + if (centery<0) + { + skipy=-centery; + centery=0; + } + // or the other side, we need to trim + if (centerx+blockwidth>image.width()) + blockwidth=image.width()-centerx; + if (centery+blockheight>image.height()) + blockheight=image.height()-centery; + if (blockwidth<=0 || skipx>=blockwidth) return; + int imgoffset=centerx*4+centery*imgstride; + if (chunk) + src=chunk->image; + //blit (or scale blit) + for (int z=skipy;zimage; + for (int z=0;z<16;z++) //n->s + { + int lasty=-1; + for (int x=0;x<16;x++,offset++) //e->w + { + uchar r=0,g=0,b=0; + double alpha=0.0; + int top=depth; + if (top>chunk->highest) + top=chunk->highest; + int highest=0; + for (int y=top;y>=0;y--) + { + int sec=y>>4; + ChunkSection *section=chunk->sections[sec]; + if (!section) + { + y=(sec<<4)-1; //skip whole section + continue; + } + int yoffset=(y&0xf)<<8; + int data=section->data[(offset+yoffset)/2]; + if (x&1) data>>=4; + BlockInfo &block=blocks->getBlock(section->blocks[offset+yoffset],data&0xf); + if (block.alpha==0.0) continue; + int light=12; + if (alpha==0.0) + { + if (lasty!=-1 && lastyy) + light-=5; + } + quint32 color=block.colors[light]; + if (alpha==0.0) + { + alpha=block.alpha; + r=color>>16; + g=(color>>8)&0xff; + b=color&0xff; + highest=y; + } + else + { + r+=(quint8)((1.0-alpha)*(color>>16)); + g+=(quint8)((1.0-alpha)*((color>>8)&0xff)); + b+=(quint8)((1.0-alpha)*(color&0xff)); + alpha+=block.alpha*(1.0-alpha); + } + if (block.alpha==1.0 || alpha>0.9) + break; + } + lasty=highest; + *bits++=b; + *bits++=g; + *bits++=r; + *bits++=0xff; + } + } + chunk->renderedAt=depth; +} + +void MapView::getToolTip(int x, int z) +{ + int cx=floor(x/16.0); + int cz=floor(z/16.0); + Chunk *chunk=cache.fetch(cx,cz); + int offset=(x&0xf)+(z&0xf)*16; + int id,bd; + + QString name="Unknown"; + QString biome="Unknown Biome"; + + if (chunk) + { + int top=depth; + if (top>chunk->highest) + top=chunk->highest; + for (int y=top;y>=0;y--) + { + int sec=y>>4; + ChunkSection *section=chunk->sections[sec]; + if (!section) + { + y=(sec<<4)-1; //skip entire section + continue; + } + int yoffset=(y&0xf)<<8; + int data=section->data[(offset+yoffset)/2]; + if (x&1) data>>=4; + BlockInfo &block=blocks->getBlock(section->blocks[offset+yoffset],data&0xf); + if (block.alpha==0.0) continue; + //found block + name=block.name; + id=section->blocks[offset+yoffset]; + bd=data&0xf; + break; + } + BiomeInfo &bi=biomes->getBiome(chunk->biomes[(x&0xf)+(z&0xf)*16]); + biome=bi.name; + } + emit hoverTextChanged(tr("X:%1 Z:%2 - %3 - %4 (%5:%6)") + .arg(x) + .arg(z) + .arg(biome) + .arg(name) + .arg(id) + .arg(bd)); +} diff --git a/mapview.h b/mapview.h new file mode 100644 index 00000000..72f1bbd1 --- /dev/null +++ b/mapview.h @@ -0,0 +1,86 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __MAPVIEW_H__ +#define __MAPVIEW_H__ + +#include +#include "chunkcache.h" +class DefinitionManager; +class BiomeIdentifier; +class BlockIdentifier; + +class MapView : public QWidget +{ + Q_OBJECT +public: + MapView(QWidget *parent=0); + + QSize minimumSizeHint() const; + QSize sizeHint() const; + + void attach(DefinitionManager *); + + void setLocation(double x,double z); + void setDimension(QString path,int scale); + +public slots: + void setDepth(int depth); + void chunkUpdated(int x,int z); + void redraw(); + +signals: + void hoverTextChanged(QString text); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *); + void wheelEvent(QWheelEvent *event); + void resizeEvent(QResizeEvent *); + void paintEvent(QPaintEvent *); + +private: + + void drawChunk(int x,int z); + void renderChunk(Chunk *chunk); + void getToolTip(int x,int z); + + int depth; + double x,z; + int scale; + double zoom; + ChunkCache cache; + QImage image; + DefinitionManager *dm; + BlockIdentifier *blocks; + BiomeIdentifier *biomes; + uchar placeholder[16*16*4]; // no chunk found placeholder +}; + +#endif diff --git a/mapviewer.c b/mapviewer.c deleted file mode 100644 index a59db8e0..00000000 --- a/mapviewer.c +++ /dev/null @@ -1,596 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include "MinutorMap/MinutorMap.h" -#include "minutor.xpm" -#include "colorschemes.h" - -#define MINZOOM 1.0 -#define MAXZOOM 10.0 - -static GtkWidget *win; -static GtkWidget *slider,*da,*status,*progressbar; -static GtkWidget *jumpplayer,*jumpspawn; -static GtkWidget *lighting, *cavemode, *hideobscured, *depthshading, *mob, *hell, *ender; -static GtkWidget *standard; -static double curX,curZ; -static int curDepth=255; -static double curScale=1.0; -static char *world=NULL; -static unsigned char *bits; -static int curWidth,curHeight; -static int spawnX,spawnY,spawnZ; -static int playerX,playerY,playerZ; -static long long randomSeed; -static gboolean mouseUp(GtkWidget *widget,GdkEventButton *event); - -static void destroy() -{ - gtk_main_quit(); -} - -static void updateProgress(float progress) -{ - if (progress>1.0) progress=1.0; - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar),progress); -} - - -static gboolean drawMap(GtkWidget *widget) -{ - // don't do anything if we haven't loaded a world - if (world==NULL) return FALSE; - // don't draw anything for a disabled widget - if (!gtk_widget_get_sensitive(widget)) return FALSE; - int w=da->allocation.width; - int h=da->allocation.height; - if (w!=curWidth || h!=curHeight) - { - curWidth=w; - curHeight=h; - bits=g_realloc(bits,curWidth*curHeight*4); - } - int opts=0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(cavemode))?CAVEMODE:0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hideobscured))?HIDEOBSCURED:0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(depthshading))?DEPTHSHADING:0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lighting))?LIGHTING:0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(mob))?MOB:0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hell))?HELL:0; - opts|=gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(ender))?ENDER:0; - - DrawMap(world,curX,curZ,curDepth,curWidth,curHeight,curScale,bits,opts,updateProgress); - - gdk_draw_rgb_32_image( - da->window, - da->style->white_gc, - 0,0,curWidth,curHeight, - GDK_RGB_DITHER_NONE, - bits, - curWidth*4); - updateProgress(0.0); - return TRUE; -} - -static gchar *getSliderText(GtkScale *scale,gdouble value) -{ - return g_strdup_printf("%d",255-(int)value); -} -static void adjustMap(GtkRange *range,gpointer user_data) -{ - curDepth=255-(int)gtk_range_get_value(range); - gdk_window_invalidate_rect(GTK_WIDGET(user_data)->window,NULL,FALSE); -} -static gboolean tracking=FALSE; -static double oldX,oldY; -static gboolean mouseDown(GtkWidget *widget,GdkEventButton *event) -{ - gtk_widget_grab_focus(widget); - oldX=event->x; - oldY=event->y; - tracking=TRUE; - return TRUE; -} -static gboolean mouseUp(GtkWidget *widget,GdkEventButton *event) -{ - tracking=FALSE; - return TRUE; -} -static gboolean mouseMove(GtkWidget *widget,GdkEventMotion *event) -{ - if (tracking) - { - curX+=(oldX-event->x)/curScale; - curZ+=(oldY-event->y)/curScale; - oldX=event->x; - oldY=event->y; - gdk_window_invalidate_rect(widget->window,NULL,FALSE); - } - int mx,mz; - const char *biome; - const char *blockLabel=IDBlock(event->x,event->y,curX,curZ, - curWidth,curHeight,curScale,&mx,&mz,&biome); - char *buf=g_strdup_printf("X:%d Z:%d %s - %s",mx,mz,biome,blockLabel); - gtk_statusbar_pop(GTK_STATUSBAR(status),1); - gtk_statusbar_push(GTK_STATUSBAR(status),1,buf); - g_free(buf); - return TRUE; -} -static gboolean mouseWheel(GtkWidget *widget,GdkEventScroll *event) -{ - if (event->direction==GDK_SCROLL_DOWN) - { - curScale-=0.2; - if (curScalewindow,NULL,FALSE); - } - if (event->direction==GDK_SCROLL_UP) - { - curScale+=0.2; - if (curScale>MAXZOOM) curScale=MAXZOOM; - gdk_window_invalidate_rect(widget->window,NULL,FALSE); - } - return TRUE; -} -static int moving=0; -static gboolean keyDown(GtkWidget *widget,GdkEventKey *event) -{ - gboolean changed=FALSE; - switch (event->keyval) - { - case GDK_Up: - case GDK_w: - moving|=1; - break; - case GDK_Down: - case GDK_s: - moving|=2; - break; - case GDK_Left: - case GDK_a: - moving|=4; - break; - case GDK_Right: - case GDK_d: - moving|=8; - break; - case GDK_Page_Up: - case GDK_e: - curScale+=0.5; - if (curScale>MAXZOOM) - curScale=MAXZOOM; - changed=TRUE; - break; - case GDK_Page_Down: - case GDK_q: - curScale-=0.5; - if (curScalewindow,NULL,FALSE); - return TRUE; - } - return FALSE; -} -static gboolean keyUp(GtkWidget *widget,GdkEventKey *event) -{ - switch (event->keyval) - { - case GDK_Up: - case GDK_w: - moving&=~1; - break; - case GDK_Down: - case GDK_s: - moving&=~2; - break; - case GDK_Left: - case GDK_a: - moving&=~4; - break; - case GDK_Right: - case GDK_d: - moving&=~8; - break; - } - return FALSE; -} - -static void loadMap(const gchar *path) -{ - //clear cache - if (world!=NULL) - g_free(world); - CloseAll(); - world=g_strdup(path); - GFile *file=g_file_new_for_path(path); - char *title=g_file_get_basename(file); - char *titlestr=g_strdup_printf("Minutor - %s",title); - gtk_window_set_title(GTK_WINDOW(win),titlestr); - g_free(titlestr); - g_free(title); - g_object_unref(file); - - GetSpawn(path,&spawnX,&spawnY,&spawnZ); - GetPlayer(path,&playerX,&playerY,&playerZ); - curX=spawnX; - curZ=spawnZ; - GetRandomSeed(path, &randomSeed); - - gtk_widget_set_sensitive(jumpspawn,TRUE); - gtk_widget_set_sensitive(jumpplayer,TRUE); - gtk_widget_set_sensitive(slider,TRUE); - gtk_widget_set_sensitive(da,TRUE); - gdk_window_invalidate_rect(da->window,NULL,FALSE); -} - -static void reloadWorld(void* data) -{ - CloseAll(); -} - -static gchar *getSavePath() -{ - return g_strdup_printf("%s/.minecraft/saves/",g_get_home_dir()); -} - -static void openWorld(GtkMenuItem *menuItem,gpointer user_data) -{ - loadMap(user_data); -} - -static void openCustom(GtkMenuItem *menuItem,gpointer user_data) -{ - GtkWidget *chooser=gtk_file_chooser_dialog_new("Open World", - GTK_WINDOW(win),GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT, - NULL); - GtkFileFilter *filter=gtk_file_filter_new(); - gtk_file_filter_add_pattern(filter,"level.dat"); - gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(chooser),filter); - if (gtk_dialog_run(GTK_DIALOG(chooser))==GTK_RESPONSE_ACCEPT) - { - GFile *file=gtk_file_chooser_get_file(GTK_FILE_CHOOSER(chooser)); - GFile *parent=g_file_get_parent(file); - if (parent!=NULL) - { - loadMap(g_file_get_path(parent)); - g_object_unref(parent); - } - else - loadMap("/"); - g_object_unref(file); - } - gtk_widget_destroy(chooser); -} - -static void jumpToSpawn(GtkMenuItem *menuItem,gpointer user_data) -{ - curX=spawnX; - curZ=spawnZ; - if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hell))) - { - curX/=8.0; - curZ/=8.0; - } - gdk_window_invalidate_rect(da->window,NULL,FALSE); -} - -static void jumpToPlayer(GtkMenuItem *menuItem,gpointer user_data) -{ - curX=playerX; - curZ=playerZ; - if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hell))) - { - curX/=8.0; - curZ/=8.0; - } - gdk_window_invalidate_rect(da->window,NULL,FALSE); -} - -static void toggleHell(GtkMenuItem *menuItem,gpointer user_data) -{ - if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hell))) - { - curX/=8.0; - curZ/=8.0; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ender),FALSE); - } - else - { - curX*=8.0; - curZ*=8.0; - } - CloseAll(); - gdk_window_invalidate_rect(da->window,NULL,FALSE); -} - -static void toggleEnd(GtkMenuItem *menuItem,gpointer user_data) -{ - if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(ender))) - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(hell),FALSE); - CloseAll(); - gdk_window_invalidate_rect(da->window,NULL,FALSE); -} -void selectColorScheme(GtkMenuItem *menuItem,gpointer user_data) -{ - int id=GPOINTER_TO_INT(user_data); - uint32_t *colors=getColorScheme(id); - SetMapPalette(colors,256); - gdk_window_invalidate_rect(da->window,NULL,FALSE); -} - -void createMapViewer() -{ - //map window - win=gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(win),"Minutor"); - gtk_window_set_icon(GTK_WINDOW(win),gdk_pixbuf_new_from_xpm_data(icon)); - g_signal_connect(G_OBJECT(win),"destroy", - G_CALLBACK(destroy),NULL); - - //main vbox - GtkWidget *vbox=gtk_vbox_new(FALSE,0); - gtk_container_add(GTK_CONTAINER(win),vbox); - - //menu bar - GtkWidget *menubar=gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(vbox),menubar,FALSE,FALSE,0); - GtkAccelGroup *menuGroup=gtk_accel_group_new(); - //file menu - GtkWidget *filemenu=gtk_menu_item_new_with_mnemonic("_File"); - gtk_menu_shell_append(GTK_MENU_SHELL(menubar),filemenu); - GtkWidget *fileitems=gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(filemenu),fileitems); - - GtkWidget *openworld=gtk_menu_item_new_with_label("Open World"); - gtk_menu_shell_append(GTK_MENU_SHELL(fileitems),openworld); - GtkWidget *openitems=gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(openworld),openitems); - - gchar *save_dir = getSavePath(); - DIR* save_dirp = opendir(save_dir); - - int n = 0; - if (save_dirp) - { - gchar *level_dat; - struct dirent *world_dir; - while ((world_dir = readdir(save_dirp)) != NULL) { - level_dat = g_strdup_printf("%s%s/level.dat", save_dir, world_dir->d_name); - if (g_file_test(level_dat, G_FILE_TEST_IS_REGULAR)) { - GtkWidget *w=gtk_menu_item_new_with_label(world_dir->d_name); - if (n < 9) { - gtk_widget_add_accelerator(w,"activate",menuGroup, - GDK_1+n,GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE); - n++; - } - gtk_menu_shell_append(GTK_MENU_SHELL(openitems),w); - g_signal_connect(G_OBJECT(w),"activate", - G_CALLBACK(openWorld),g_strdup_printf("%s%s", save_dir, world_dir->d_name)); - } - g_free(level_dat); - } - - closedir(save_dirp); - } - - g_free(save_dir); - - GtkWidget *open=gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN,menuGroup); - gtk_menu_shell_append(GTK_MENU_SHELL(fileitems),open); - g_signal_connect(G_OBJECT(open),"activate", - G_CALLBACK(openCustom),NULL); - - GtkWidget *reload=gtk_image_menu_item_new_with_mnemonic("_Reload"); - gtk_widget_add_accelerator(reload,"activate",menuGroup, - GDK_R,GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(fileitems),reload); - g_signal_connect(G_OBJECT(reload),"activate", - G_CALLBACK(reloadWorld),NULL); - - GtkWidget *sep=gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(fileitems),sep); - - GtkWidget *quit=gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT,menuGroup); - gtk_menu_shell_append(GTK_MENU_SHELL(fileitems),quit); - g_signal_connect(G_OBJECT(quit),"activate", - G_CALLBACK(destroy),NULL); - - GtkWidget *viewmenu=gtk_menu_item_new_with_mnemonic("_View"); - gtk_menu_shell_append(GTK_MENU_SHELL(menubar),viewmenu); - GtkWidget *viewitems=gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(viewmenu),viewitems); - - jumpspawn=gtk_menu_item_new_with_label("Jump to Spawn"); - gtk_widget_add_accelerator(jumpspawn,"activate",menuGroup, - GDK_F2,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),jumpspawn); - g_signal_connect(G_OBJECT(jumpspawn),"activate", - G_CALLBACK(jumpToSpawn),NULL); - gtk_widget_set_sensitive(jumpspawn,FALSE); - - jumpplayer=gtk_menu_item_new_with_label("Jump to Player"); - gtk_widget_add_accelerator(jumpplayer,"activate",menuGroup, - GDK_F3,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),jumpplayer); - g_signal_connect(G_OBJECT(jumpplayer),"activate", - G_CALLBACK(jumpToPlayer),NULL); - gtk_widget_set_sensitive(jumpplayer,FALSE); - - GtkWidget *sep2=gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),sep2); - - hell=gtk_check_menu_item_new_with_label("Nether"); - gtk_widget_add_accelerator(hell,"activate",menuGroup, - GDK_F5,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),hell); - g_signal_connect(G_OBJECT(hell),"activate", - G_CALLBACK(toggleHell),NULL); - - ender=gtk_check_menu_item_new_with_label("End"); - gtk_widget_add_accelerator(ender,"activate",menuGroup, - GDK_F6,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),ender); - g_signal_connect(G_OBJECT(ender),"activate", - G_CALLBACK(toggleEnd),NULL); - GtkWidget *sep3=gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),sep3); - - - GtkWidget *colormenu=gtk_menu_item_new_with_mnemonic("_Colors"); - gtk_menu_shell_append(GTK_MENU_SHELL(menubar),colormenu); - GtkWidget *coloritems=gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(colormenu),coloritems); - - standard=gtk_radio_menu_item_new_with_label(NULL,"Standard"); - GSList *group=gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(standard)); - gtk_menu_shell_append(GTK_MENU_SHELL(coloritems),standard); - g_signal_connect(G_OBJECT(standard),"activate", - G_CALLBACK(selectColorScheme),GINT_TO_POINTER(-1)); - GtkWidget *sep4=gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(coloritems),sep4); - - GtkWidget *colorschemes=gtk_menu_item_new_with_label("Color Schemes..."); - gtk_menu_shell_append(GTK_MENU_SHELL(coloritems),colorschemes); - g_signal_connect(G_OBJECT(colorschemes),"activate", - G_CALLBACK(editColorSchemes),NULL); - - gtk_window_add_accel_group(GTK_WINDOW(win),menuGroup); - - //control hbox - GtkWidget *hbox=gtk_hbox_new(FALSE,5); - gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,TRUE,0); - - //slider - slider=gtk_hscale_new_with_range(0.0,255.0,1.0); - gtk_widget_set_sensitive(slider,FALSE); - gtk_box_pack_start(GTK_BOX(hbox),slider,TRUE,TRUE,0); - g_signal_connect(G_OBJECT(slider),"format-value", - G_CALLBACK(getSliderText),NULL); - - //map - da=gtk_drawing_area_new(); - gtk_widget_set_sensitive(da,FALSE); - curWidth=496; - curHeight=400; - gtk_drawing_area_size(GTK_DRAWING_AREA(da),curWidth,curHeight); - gtk_box_pack_start(GTK_BOX(vbox),da,TRUE,TRUE,0); - gtk_widget_add_events(da,GDK_SCROLL_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK|GDK_KEY_PRESS_MASK); - g_signal_connect(G_OBJECT(da),"expose-event", - G_CALLBACK(drawMap),NULL); - g_signal_connect(G_OBJECT(da),"button-press-event", - G_CALLBACK(mouseDown),NULL); - g_signal_connect(G_OBJECT(da),"button-release-event", - G_CALLBACK(mouseUp),NULL); - g_signal_connect(G_OBJECT(da),"motion-notify-event", - G_CALLBACK(mouseMove),NULL); - g_signal_connect(G_OBJECT(da),"scroll-event", - G_CALLBACK(mouseWheel),NULL); - g_signal_connect(G_OBJECT(da),"key-press-event", - G_CALLBACK(keyDown),NULL); - g_signal_connect(G_OBJECT(da),"key-release-event", - G_CALLBACK(keyUp),NULL); - gtk_widget_set_can_focus(da,TRUE); - gtk_widget_grab_focus(da); - - g_signal_connect(G_OBJECT(slider),"value-changed", - G_CALLBACK(adjustMap),G_OBJECT(da)); - - //view menu > rendering options - lighting=gtk_check_menu_item_new_with_mnemonic("_Lighting"); - gtk_widget_add_accelerator(lighting,"activate",menuGroup, - GDK_1,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),lighting); - g_signal_connect(G_OBJECT(lighting),"toggled", - G_CALLBACK(drawMap),NULL); - - - cavemode=gtk_check_menu_item_new_with_mnemonic("_Cave Mode"); - gtk_widget_add_accelerator(cavemode,"activate",menuGroup, - GDK_2,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),cavemode); - g_signal_connect(G_OBJECT(cavemode),"toggled", - G_CALLBACK(drawMap),NULL); - - hideobscured=gtk_check_menu_item_new_with_mnemonic("Hide _Obscured"); - gtk_widget_add_accelerator(hideobscured,"activate",menuGroup, - GDK_3,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),hideobscured); - g_signal_connect(G_OBJECT(hideobscured),"toggled", - G_CALLBACK(drawMap),NULL); - - depthshading=gtk_check_menu_item_new_with_mnemonic("_Depth Shading"); - gtk_widget_add_accelerator(depthshading,"activate",menuGroup, - GDK_4,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),depthshading); - g_signal_connect(G_OBJECT(depthshading),"toggled", - G_CALLBACK(drawMap),NULL); - - mob=gtk_check_menu_item_new_with_mnemonic("Show _Mob Spawn"); - gtk_widget_add_accelerator(mob,"activate",menuGroup, - GDK_5,0,GTK_ACCEL_VISIBLE); - gtk_menu_shell_append(GTK_MENU_SHELL(viewitems),mob); - g_signal_connect(G_OBJECT(mob),"toggled", - G_CALLBACK(drawMap),NULL); - - //statusbar - status=gtk_statusbar_new(); - gtk_box_pack_end(GTK_BOX(vbox),status,FALSE,TRUE,0); - //progressbar - progressbar=gtk_progress_bar_new(); - gtk_box_pack_start(GTK_BOX(status),progressbar,FALSE,TRUE,0); - - - bits=g_malloc(curWidth*curHeight*4); - - // 2 = position to start inserting color schemes - initColorSchemes(GTK_MENU_SHELL(coloritems),1,group); - - //and show it - gtk_widget_show_all(win); -} diff --git a/mapviewer.h b/mapviewer.h deleted file mode 100644 index 5c8cf71b..00000000 --- a/mapviewer.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __MAPVIEWER_H__ -#define __MAPVIEWER_H__ - -void createMapViewer(); - -#endif diff --git a/minutor.c b/minutor.c deleted file mode 100644 index e87bf83f..00000000 --- a/minutor.c +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright (c) 2010, Sean Kasun -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. -*/ -#include -#include -#include -#include "mapviewer.h" - -int main(int argc,char *argv[]) -{ - gtk_init(&argc,&argv); - - //main window - createMapViewer(); - gtk_main(); - return 0; -} diff --git a/minutor.cpp b/minutor.cpp new file mode 100644 index 00000000..8cf50cfb --- /dev/null +++ b/minutor.cpp @@ -0,0 +1,398 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "minutor.h" +#include "mapview.h" +#include "labelledslider.h" +#include "nbt.h" +#include "json.h" +#include "definitionmanager.h" +#include "settings.h" +#include "dimensions.h" + +Minutor::Minutor() +{ + mapview = new MapView; + connect(mapview,SIGNAL(hoverTextChanged(QString)), + statusBar(),SLOT(showMessage(QString))); + dm=new DefinitionManager(this); + mapview->attach(dm); + connect(dm,SIGNAL(packsChanged()), + this,SLOT(updateDimensions())); + dimensions=dm->dimensions(); + connect(dimensions,SIGNAL(dimensionChanged(Dimension &)), + this,SLOT(viewDimension(Dimension &))); + settings = new Settings(this); + connect(settings,SIGNAL(settingsUpdated()), + this,SLOT(rescanWorlds())); + + if (settings->update) + dm->autoUpdate(); + + createActions(); + createMenus(); + createStatusBar(); + + depth = new LabelledSlider; + depth->setValue(255); + + connect(depth, SIGNAL(valueChanged(int)), + mapview, SLOT(setDepth(int))); + connect(this, SIGNAL(worldLoaded(bool)), + mapview, SLOT(setEnabled(bool))); + connect(this, SIGNAL(worldLoaded(bool)), + depth, SLOT(setEnabled(bool))); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(depth); + mainLayout->addWidget(mapview,1); + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(0,0,0,0); + + QWidget *central=new QWidget; + central->setLayout(mainLayout); + + setCentralWidget(central); + layout()->setContentsMargins(0,0,0,0); + + setWindowTitle(qApp->applicationName()); + + emit worldLoaded(false); +} + +void Minutor::openWorld() +{ + QAction *action=qobject_cast(sender()); + if (action) + loadWorld(action->data().toString()); +} + +void Minutor::open() +{ + QString dirName = QFileDialog::getExistingDirectory(this,tr("Open World")); + if (!dirName.isEmpty()) + { + QDir path(dirName); + if (!path.exists("level.dat")) + { + QMessageBox::warning(this, + tr("Couldn't open world"), + tr("%1 is not a valid Minecraft world").arg(dirName), + QMessageBox::Cancel); + return; + } + loadWorld(dirName); + } +} + +void Minutor::reload() +{ +} + +void Minutor::closeWorld() +{ + locations.clear(); + for (int i=0;iremoveAction(players[i]); + delete players[i]; + } + players.clear(); + jumpMenu->setEnabled(false); + dimensions->removeDimensions(dimMenu); + currentWorld=QString(); + emit worldLoaded(false); +} + +void Minutor::jumpToLocation() +{ + QAction *action=qobject_cast(sender()); + if (action) + { + Location loc=locations[action->data().toInt()]; + mapview->setLocation(loc.x,loc.z); + } +} + +void Minutor::toggleLighting() +{ +} +void Minutor::toggleCaveMode() +{ +} + +void Minutor::viewDimension(Dimension &dim) +{ + mapview->setDimension(dim.path,dim.scale); +} + +void Minutor::about() +{ + QMessageBox::about(this,tr("About %1").arg(qApp->applicationName()), + tr("%1 v%2
\n" + "© Copyright %3, %4").arg(qApp->applicationName()) + .arg(qApp->applicationVersion()) + .arg(2013) + .arg(qApp->organizationName())); +} + +void Minutor::updateDimensions() +{ + dimensions->getDimensions(currentWorld,dimMenu,this); +} + +void Minutor::createActions() +{ + getWorldList(); + + openAct=new QAction(tr("&Open..."),this); + openAct->setShortcut(tr("Ctrl+O")); + openAct->setStatusTip(tr("Open a world")); + connect(openAct, SIGNAL(triggered()), + this, SLOT(open())); + + reloadAct=new QAction(tr("&Reload"),this); + reloadAct->setShortcut(tr("F5")); + reloadAct->setStatusTip(tr("Reload current world")); + connect(reloadAct, SIGNAL(triggered()), + this, SLOT(reload())); + connect(this, SIGNAL(worldLoaded(bool)), + reloadAct, SLOT(setEnabled(bool))); + + exitAct=new QAction(tr("E&xit"),this); + exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setStatusTip(tr("Exit %1").arg(qApp->applicationName())); + connect(exitAct, SIGNAL(triggered()), + this, SLOT(close())); + + jumpSpawnAct=new QAction(tr("Jump to &Spawn"),this); + jumpSpawnAct->setShortcut(tr("F1")); + jumpSpawnAct->setStatusTip(tr("Jump to world spawn")); + connect(jumpSpawnAct, SIGNAL(triggered()), + this, SLOT(jumpToLocation())); + connect(this, SIGNAL(worldLoaded(bool)), + jumpSpawnAct, SLOT(setEnabled(bool))); + + + lightingAct=new QAction(tr("&Lighting"),this); + lightingAct->setCheckable(true); + lightingAct->setShortcut(tr("Ctrl+L")); + lightingAct->setStatusTip(tr("Toggle lighting on/off")); + connect(lightingAct, SIGNAL(triggered()), + this, SLOT(toggleLighting())); + + caveModeAct=new QAction(tr("&Cave Mode"),this); + caveModeAct->setCheckable(true); + caveModeAct->setShortcut(tr("Ctrl+I")); + caveModeAct->setStatusTip(tr("Toggle cave mode on/off")); + connect(caveModeAct, SIGNAL(triggered()), + this, SLOT(toggleCaveMode())); + + + manageDefsAct=new QAction(tr("Manage &Definitions..."),this); + manageDefsAct->setStatusTip(tr("Manage block and biome definitions")); + connect(manageDefsAct, SIGNAL(triggered()), + dm, SLOT(show())); + + aboutAct=new QAction(tr("&About"),this); + aboutAct->setStatusTip(tr("About %1").arg(qApp->applicationName())); + connect(aboutAct, SIGNAL(triggered()), + this, SLOT(about())); + + settingsAct=new QAction(tr("Settings..."),this); + settingsAct->setStatusTip(tr("Change %1 Settings").arg(qApp->applicationName())); + connect(settingsAct, SIGNAL(triggered()), + settings, SLOT(show())); + + updatesAct=new QAction(tr("Check for updates..."),this); + updatesAct->setStatusTip(tr("Check for updated packs")); + connect(updatesAct, SIGNAL(triggered()), + dm, SLOT(checkForUpdates())); +} + +void Minutor::createMenus() +{ + fileMenu=menuBar()->addMenu(tr("&File")); + worldMenu=fileMenu->addMenu(tr("&Open World")); + + worldMenu->addActions(worlds); + if (worlds.size()==0) //no worlds found + worldMenu->setEnabled(false); + + fileMenu->addAction(openAct); + fileMenu->addAction(reloadAct); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + viewMenu=menuBar()->addMenu(tr("&View")); + viewMenu->addAction(jumpSpawnAct); + jumpMenu=viewMenu->addMenu(tr("&Jump to Player")); + jumpMenu->setEnabled(false); + dimMenu=viewMenu->addMenu(tr("&Dimension")); + dimMenu->setEnabled(false); + viewMenu->addSeparator(); + viewMenu->addAction(lightingAct); + viewMenu->addAction(caveModeAct); + viewMenu->addSeparator(); + viewMenu->addAction(manageDefsAct); + + menuBar()->addSeparator(); + + helpMenu=menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addSeparator(); + helpMenu->addAction(settingsAct); + helpMenu->addAction(updatesAct); +} + +void Minutor::createStatusBar() +{ + statusBar()->showMessage(tr("Ready")); +} + +QString Minutor::getWorldName(QDir path) +{ + if (!path.exists("level.dat")) //no level.dat? no world + return QString(); + + NBT level(path.filePath("level.dat")); + return level.at("Data")->at("LevelName")->toString(); +} + + +void Minutor::getWorldList() +{ + QDir mc(settings->mcpath); + if (!mc.cd("saves")) + return; + + QDirIterator it(mc); + int key=1; + while (it.hasNext()) + { + it.next(); + if (it.fileInfo().isDir()) + { + QString name=getWorldName(it.filePath()); + if (!name.isNull()) + { + QAction *w=new QAction(this); + w->setText(name); + w->setData(it.filePath()); + if (key<10) + { + w->setShortcut("Ctrl+"+QString::number(key)); + key++; + } + connect(w, SIGNAL(triggered()), + this, SLOT(openWorld())); + worlds.append(w); + } + } + } +} + +void Minutor::loadWorld(QDir path) +{ + closeWorld(); //just in case + currentWorld=path; + + NBT level(path.filePath("level.dat")); + + Tag *data=level.at("Data"); + //add level name to window title + setWindowTitle(qApp->applicationName()+" - "+data->at("LevelName")->toString()); + //save world spawn + jumpSpawnAct->setData(locations.count()); + locations.append(Location(data->at("SpawnX")->toDouble(), + data->at("SpawnZ")->toDouble())); + //show saved players + if (path.exists("players")) + { + path.cd("players"); + QDirIterator it(path); + bool hasPlayers=false; + while (it.hasNext()) + { + it.next(); + if (it.fileInfo().isFile()) + { + hasPlayers=true; + NBT player(it.filePath()); + Tag *pos=player.at("Pos"); + QAction *p=new QAction(this); + p->setText(it.fileInfo().completeBaseName()); + p->setData(locations.count()); + locations.append(Location(pos->at(0)->toDouble(), + pos->at(2)->toDouble())); + connect(p, SIGNAL(triggered()), + this, SLOT(jumpToLocation())); + players.append(p); + if (player.has("SpawnX")) //player has a bed + { + p=new QAction(this); + p->setText(it.fileInfo().completeBaseName()+"'s Bed"); + p->setData(locations.count()); + locations.append(Location(player.at("SpawnX")->toDouble(), + player.at("SpawnZ")->toDouble())); + connect(p, SIGNAL(triggered()), + this, SLOT(jumpToLocation())); + players.append(p); + } + } + } + jumpMenu->addActions(players); + jumpMenu->setEnabled(hasPlayers); + path.cdUp(); + } + + //show dimensions + dimensions->getDimensions(path,dimMenu,this); + emit worldLoaded(true); + mapview->setLocation(locations.first().x,locations.first().z); + +} + +void Minutor::rescanWorlds() +{ + worlds.clear(); + getWorldList(); + worldMenu->clear(); + worldMenu->addActions(worlds); + worldMenu->setEnabled(worlds.count()!=0); + //we don't care about the auto-update toggle, since that only happens + //on startup anyway. +} diff --git a/minutor.h b/minutor.h new file mode 100644 index 00000000..3c1dfaa4 --- /dev/null +++ b/minutor.h @@ -0,0 +1,114 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __MINUTOR_H__ +#define __MINUTOR_H__ + +#include +#include + +class QAction; +class QActionGroup; +class QMenu; +class MapView; +class LabelledSlider; +class DefinitionManager; +class Settings; +class BiomeIdentifier; +class BlockIdentifier; +class Dimensions; +class Dimension; + +class Location +{ +public: + Location(double x,double z):x(x),z(z) {} + double x,z; +}; + +class Minutor : public QMainWindow +{ + Q_OBJECT +public: + Minutor(); + +private slots: + void openWorld(); + void open(); + void closeWorld(); + void reload(); + + void jumpToLocation(); + void viewDimension(Dimension &dim); + void toggleLighting(); + void toggleCaveMode(); + + void about(); + + void updateDimensions(); + void rescanWorlds(); + +signals: + void worldLoaded(bool isLoaded); + +private: + void createActions(); + void createMenus(); + void createStatusBar(); + + QString getWorldName(QDir path); + void getWorldList(); + + void loadWorld(QDir path); + + MapView *mapview; + LabelledSlider *depth; + + QMenu *fileMenu, *worldMenu; + QMenu *viewMenu, *jumpMenu, *dimMenu; + QMenu *helpMenu; + + QListworlds; + QAction *openAct, *reloadAct, *exitAct; + QAction *jumpSpawnAct; + QListplayers; + QAction *lightingAct, *caveModeAct; + QAction *manageDefsAct; + QAction *aboutAct; + QAction *settingsAct; + QAction *updatesAct; + + //loaded world data + QList locations; + DefinitionManager *dm; + Settings *settings; + Dimensions *dimensions; + QDir currentWorld; +}; + +#endif diff --git a/minutor.pro b/minutor.pro new file mode 100644 index 00000000..61490f0a --- /dev/null +++ b/minutor.pro @@ -0,0 +1,36 @@ +TEMPLATE = app +TARGET = minutor +DEPENDPATH += . +INCLUDEPATH += . +QT += widgets network +unix:LIBS += -lz +win32:LIBS+= $$PWD/zlibstat.lib + +# Input +HEADERS += mapview.h minutor.h nbt.h zlib.h zconf.h \ + labelledslider.h \ + chunk.h \ + chunkcache.h \ + json.h \ + blockidentifier.h \ + biomeidentifier.h \ + dimensions.h \ + definitionmanager.h \ + zipreader.h \ + settings.h \ + chunkloader.h \ + definitionupdater.h +SOURCES += mapview.cpp main.cpp minutor.cpp nbt.cpp \ + labelledslider.cpp \ + chunk.cpp \ + chunkcache.cpp \ + json.cpp \ + blockidentifier.cpp \ + biomeidentifier.cpp \ + dimensions.cpp \ + definitionmanager.cpp \ + zipreader.cpp \ + settings.cpp \ + chunkloader.cpp \ + definitionupdater.cpp +RESOURCES = minutor.qrc diff --git a/minutor.qrc b/minutor.qrc new file mode 100644 index 00000000..71f0a888 --- /dev/null +++ b/minutor.qrc @@ -0,0 +1,7 @@ + + + definitions/vanilla_biomes.json + definitions/vanilla_ids.json + definitions/vanilla_dims.json + + diff --git a/nbt.cpp b/nbt.cpp new file mode 100644 index 00000000..e3c08310 --- /dev/null +++ b/nbt.cpp @@ -0,0 +1,416 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include +#include + +#include "nbt.h" +#include + +// this handles decoding the gzipped level.dat +NBT::NBT(const QString level) +{ + root=&NBT::Null; //just in case we die + + QFile f(level); + f.open(QIODevice::ReadOnly); + QByteArray data=f.readAll(); + f.close(); + + QByteArray nbt; + z_stream strm; + static const int CHUNK_SIZE = 8192; + char out[CHUNK_SIZE]; + strm.zalloc=Z_NULL; + strm.zfree=Z_NULL; + strm.opaque=Z_NULL; + strm.avail_in=data.size(); + strm.next_in=(Bytef*)data.data(); + + inflateInit2(&strm,15+32); + do { + strm.avail_out=CHUNK_SIZE; + strm.next_out=(Bytef*)out; + inflate(&strm,Z_NO_FLUSH); + nbt.append(out,CHUNK_SIZE-strm.avail_out); + } while (strm.avail_out==0); + inflateEnd(&strm); + + TagDataStream s(nbt.constData(),nbt.size()); + + if (s.r8()==10) //compound + { + s.skip(s.r16()); //skip name + root=new Tag_Compound(s); + } +} + + +//this handles decoding a compressed() section of a region file +NBT::NBT(const uchar *chunk) +{ + root=&NBT::Null; //just in case + + // find chunk size + int length=(chunk[0]<<24)|(chunk[1]<<16)|(chunk[2]<<8)|chunk[3]; + if (chunk[4]!=2) //rfc1950 + return; + + z_stream strm; + static const int CHUNK_SIZE = 8192; + char out[CHUNK_SIZE]; + strm.zalloc=Z_NULL; + strm.zfree=Z_NULL; + strm.opaque=Z_NULL; + strm.avail_in=length-1; + strm.next_in=(Bytef*)chunk+5; + + QByteArray nbt; + + inflateInit(&strm); + do { + strm.avail_out=CHUNK_SIZE; + strm.next_out=(Bytef*)out; + inflate(&strm,Z_NO_FLUSH); + nbt.append(out,CHUNK_SIZE-strm.avail_out); + } while (strm.avail_out==0); + inflateEnd(&strm); + + TagDataStream s(nbt.constData(),nbt.size()); + + if (s.r8()==10) //compound + { + s.skip(s.r16()); //skip name + root=new Tag_Compound(s); + } +} + +Tag NBT::Null; + +bool NBT::has(const QString key) +{ + return root->has(key); +} + +Tag *NBT::at(const QString key) +{ + return root->at(key); +} + +NBT::~NBT() +{ + if (root!=&NBT::Null) + delete root; +} + +/********** TAGS ****************/ + +Tag::Tag() +{ +} +Tag::~Tag() +{ +} +int Tag::length() +{ + qWarning()<<"Unhandled length"; + return 0; +} +bool Tag::has(const QString) +{ + return false; +} +Tag *Tag::at(const QString) +{ + return &NBT::Null; +} +Tag *Tag::at(int) +{ + return &NBT::Null; +} +QString Tag::toString() +{ + qWarning()<<"Unhandled toString"; + return ""; +} +qint32 Tag::toInt() +{ + qWarning()<<"Unhandled toInt"; + return 0; +} +double Tag::toDouble() +{ + qWarning()<<"Unhandled toDouble"; + return 0.0; +} +const quint8 *Tag::toByteArray() +{ + qWarning()<<"Unhandled toByteArray"; + return NULL; +} +const qint32 *Tag::toIntArray() +{ + qWarning()<<"Unhandled toIntArray"; + return NULL; +} + +Tag_Byte::Tag_Byte(TagDataStream &s) +{ + data=s.r8(); +} +int Tag_Byte::toInt() +{ + return data; +} + +Tag_Short::Tag_Short(TagDataStream &s) +{ + data=s.r16(); +} + +Tag_Int::Tag_Int(TagDataStream &s) +{ + data=s.r32(); +} +qint32 Tag_Int::toInt() +{ + return data; +} +double Tag_Int::toDouble() +{ + return (double)data; +} + +Tag_Long::Tag_Long(TagDataStream &s) +{ + data=s.r64(); +} + +Tag_Float::Tag_Float(TagDataStream &s) +{ + union {qint32 d; float f;} fl; + fl.d=s.r32(); + data=fl.f; +} + +Tag_Double::Tag_Double(TagDataStream &s) +{ + union {qint64 d; double f;} fl; + fl.d=s.r64(); + data=fl.f; +} +double Tag_Double::toDouble() +{ + return data; +} + +Tag_Byte_Array::Tag_Byte_Array(TagDataStream &s) +{ + len=s.r32(); + data=s.r(len); +} +Tag_Byte_Array::~Tag_Byte_Array() +{ + delete[] data; +} +int Tag_Byte_Array::length() +{ + return len; +} +const quint8 *Tag_Byte_Array::toByteArray() +{ + return data; +} + +Tag_String::Tag_String(TagDataStream &s) +{ + int len=s.r16(); + data=s.utf8(len); +} +QString Tag_String::toString() +{ + return data; +} + + template +static void setListData(QList &data,int len,TagDataStream &s) +{ + for (int i=0;i(data,len,s); break; + case 2: setListData(data,len,s); break; + case 3: setListData(data,len,s); break; + case 4: setListData(data,len,s); break; + case 5: setListData(data,len,s); break; + case 6: setListData(data,len,s); break; + case 7: setListData(data,len,s); break; + case 8: setListData(data,len,s); break; + case 9: setListData(data,len,s); break; + case 10: setListData(data,len,s); break; + case 11: setListData(data,len,s); break; + default: + throw "Unknown type"; + } +} + +Tag_List::~Tag_List() +{ + QList::const_iterator i; + for (i=data.constBegin();i!=data.constEnd();i++) + delete *i; +} +int Tag_List::length() +{ + return data.count(); +} +Tag *Tag_List::at(int index) +{ + return data[index]; +} + +Tag_Compound::Tag_Compound(TagDataStream &s) +{ + quint8 type; + while ((type=s.r8())!=0) //until tag_end + { + quint16 len=s.r16(); + QString key=s.utf8(len); + Tag *child; + switch (type) + { + case 1: child=new Tag_Byte(s); break; + case 2: child=new Tag_Short(s); break; + case 3: child=new Tag_Int(s); break; + case 4: child=new Tag_Long(s); break; + case 5: child=new Tag_Float(s); break; + case 6: child=new Tag_Double(s); break; + case 7: child=new Tag_Byte_Array(s); break; + case 8: child=new Tag_String(s); break; + case 9: child=new Tag_List(s); break; + case 10: child=new Tag_Compound(s); break; + case 11: child=new Tag_Int_Array(s); break; + default: throw "Unknown tag"; + } + children[key]=child; + } +} +Tag_Compound::~Tag_Compound() +{ + QHash::const_iterator i; + for (i=children.constBegin();i!=children.constEnd();i++) + delete i.value(); +} +bool Tag_Compound::has(const QString key) +{ + return children.contains(key); +} +Tag *Tag_Compound::at(const QString key) +{ + if (!children.contains(key)) + return &NBT::Null; + return children[key]; +} + +Tag_Int_Array::Tag_Int_Array(TagDataStream &s) +{ + len=s.r32(); + data=new qint32[len]; + for (int i=0;idata=(const quint8 *)data; + this->len=len; + pos=0; +} + +quint8 TagDataStream::r8() +{ + return data[pos++]; +} +quint16 TagDataStream::r16() +{ + quint16 r=data[pos++]<<8; + r|=data[pos++]; + return r; +} +quint32 TagDataStream::r32() +{ + quint32 r=data[pos++]<<24; + r|=data[pos++]<<16; + r|=data[pos++]<<8; + r|=data[pos++]; + return r; +} +quint64 TagDataStream::r64() +{ + quint64 r=(quint64)r32()<<32; + r|=r32(); + return r; +} +quint8 *TagDataStream::r(int len) //you need to free anything read with this +{ + quint8 *r=new quint8[len]; + memcpy(r,data+pos,len); + pos+=len; + return r; +} +QString TagDataStream::utf8(int len) +{ + int old=pos; + pos+=len; + return QString::fromUtf8((const char *)data+old,len); +} +void TagDataStream::skip(int len) +{ + pos+=len; +} diff --git a/nbt.h b/nbt.h new file mode 100644 index 00000000..dbb98400 --- /dev/null +++ b/nbt.h @@ -0,0 +1,188 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __NBT_H__ +#define __NBT_H__ + +class QString; +class QByteArray; + +class TagDataStream +{ +public: + TagDataStream(const char *data,int len); + quint8 r8(); + quint16 r16(); + quint32 r32(); + quint64 r64(); + quint8 *r(int len); + QString utf8(int len); + void skip(int len); +private: + const quint8 *data; + int pos,len; +}; + +class Tag +{ +public: + Tag(); + virtual ~Tag(); + virtual bool has(const QString key); + virtual int length(); + virtual Tag *at(const QString key); + virtual Tag *at(int index); + virtual QString toString(); + virtual qint32 toInt(); + virtual double toDouble(); + virtual const quint8 *toByteArray(); + virtual const qint32 *toIntArray(); +}; + +class NBT +{ +public: + NBT(const QString level); + NBT(const uchar *chunk); + ~NBT(); + + bool has(const QString key); + Tag *at(const QString key); + + static Tag Null; +private: + Tag *root; +}; + +class Tag_Byte : public Tag +{ +public: + Tag_Byte(TagDataStream &s); + int toInt(); +private: + quint8 data; +}; + +class Tag_Short : public Tag +{ +public: + Tag_Short(TagDataStream &s); +private: + qint16 data; +}; + +class Tag_Int : public Tag +{ +public: + Tag_Int(TagDataStream &s); + qint32 toInt(); + double toDouble(); +private: + qint32 data; +}; + +class Tag_Long : public Tag +{ +public: + Tag_Long(TagDataStream &s); +private: + qint64 data; +}; + +class Tag_Float : public Tag +{ +public: + Tag_Float(TagDataStream &s); +private: + float data; +}; + +class Tag_Double : public Tag +{ +public: + Tag_Double(TagDataStream &s); + double toDouble(); +private: + double data; +}; + +class Tag_Byte_Array : public Tag +{ +public: + Tag_Byte_Array(TagDataStream &s); + ~Tag_Byte_Array(); + int length(); + const quint8 *toByteArray(); +private: + const quint8 *data; + int len; +}; + +class Tag_String : public Tag +{ +public: + Tag_String(TagDataStream &s); + QString toString(); +private: + QString data; +}; + +class Tag_List : public Tag +{ +public: + Tag_List(TagDataStream &s); + ~Tag_List(); + Tag *at(int index); + int length(); +private: + QList data; +}; + +class Tag_Compound : public Tag +{ +public: + Tag_Compound(TagDataStream &s); + ~Tag_Compound(); + bool has(const QString key); + Tag *at(const QString key); +private: + QHash children; +}; + +class Tag_Int_Array : public Tag +{ +public: + Tag_Int_Array(TagDataStream &s); + ~Tag_Int_Array(); + int length(); + const qint32 *toIntArray(); +private: + int len; + qint32 *data; +}; + +#endif diff --git a/settings.cpp b/settings.cpp new file mode 100644 index 00000000..1ee5b1b9 --- /dev/null +++ b/settings.cpp @@ -0,0 +1,143 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "settings.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Settings::Settings(QWidget *parent) : QWidget(parent) +{ + setWindowFlags(Qt::Window); + setWindowTitle(tr("%1 Settings").arg(qApp->applicationName())); + + QVBoxLayout *layout=new QVBoxLayout; + + QGroupBox *paths=new QGroupBox("Minecraft Location"); + QVBoxLayout *pathlayout=new QVBoxLayout; + QCheckBox *def=new QCheckBox("Use Default Location"); + connect(def,SIGNAL(toggled(bool)), + this,SLOT(chooseDefault(bool))); + pathlayout->addWidget(def); + + QSettings info; + + QHBoxLayout *custlayout=new QHBoxLayout; + QLineEdit *le=new QLineEdit(); + connect(this,SIGNAL(locationChanged(QString)), + le,SLOT(setText(const QString &))); + connect(le,SIGNAL(textChanged(const QString &)), + this,SLOT(pathChanged(const QString &))); + //after the connection to set defaults + le->setText(info.value("mcdir","").toString()); + custlayout->addWidget(le); + QPushButton *browse=new QPushButton("Browse"); + connect(browse,SIGNAL(clicked(bool)), + this,SLOT(chooseLocation(bool))); + custlayout->addWidget(browse); + QWidget *custom=new QWidget; + custom->setLayout(custlayout); + pathlayout->addWidget(custom); + + connect(def,SIGNAL(toggled(bool)), + custom,SLOT(setDisabled(bool))); + //after connection to set defaults + def->setChecked(info.value("usedefault",true).toBool()); + + paths->setLayout(pathlayout); + layout->addWidget(paths); + + QCheckBox *update=new QCheckBox("Auto-check for updates"); + connect(update,SIGNAL(toggled(bool)), + this,SLOT(autoUpdate(bool))); + //after connection to set defaults + update->setChecked(info.value("autoupdate",true).toBool()); + layout->addWidget(update); + + setLayout(layout); +} + +QSize Settings::minimumSizeHint() const +{ + return QSize(400,150); +} +QSize Settings::sizeHint() const +{ + return QSize(400,150); +} + +void Settings::autoUpdate(bool up) +{ + update=up; + QSettings info; + info.setValue("autoupdate",up); + emit settingsUpdated(); +} +void Settings::chooseLocation(bool) +{ + QString dirName=QFileDialog::getExistingDirectory(this,tr("Find Minecraft")); + if (!dirName.isEmpty()) + emit locationChanged(dirName); +} +void Settings::pathChanged(const QString &path) +{ + mcpath=path; + QSettings info; + info.setValue("mcdir",path); + //save settings + emit settingsUpdated(); +} +void Settings::chooseDefault(bool def) +{ + QSettings info; + info.setValue("usedefault",def); + if (!def) //we unchecked default.. but we're still technically default + return; + + QString mc; +#ifdef Q_OS_MAC + mc=QDir::homePath()+QDir::toNativeSeparators("/Library/Application Support/minecraft"); +#elif defined Q_OS_WIN32 + //pretend to be minecraft + QSettings ini(QSettings::IniFormat,QSettings::UserScope, + ".minecraft","minecraft1"); + mc=QFileInfo(ini.fileName()).absolutePath(); +#else + mc=QDir::homePath()+QDir::toNativeSeparators("/.minecraft"); +#endif + + emit locationChanged(mc); +} diff --git a/settings.h b/settings.h new file mode 100644 index 00000000..79a4bf20 --- /dev/null +++ b/settings.h @@ -0,0 +1,58 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include + +class Settings : public QWidget +{ + Q_OBJECT +public: + explicit Settings(QWidget *parent = 0); + + QSize minimumSizeHint() const; + QSize sizeHint() const; + + bool update; + QString mcpath; + +signals: + void settingsUpdated(); + +signals: + void locationChanged(const QString &); + +private slots: + void autoUpdate(bool); + void chooseLocation(bool); + void chooseDefault(bool); + void pathChanged(const QString &); +}; + +#endif // SETTINGS_H diff --git a/web/Makefile b/web/Makefile new file mode 100644 index 00000000..5d9cad14 --- /dev/null +++ b/web/Makefile @@ -0,0 +1,15 @@ +# closure compiler +COMPILER=~/compiler.jar +COMPLEVEL=ADVANCED_OPTIMIZATIONS + +.DELETE_ON_ERROR: + +JS=color.js editor.js zip.js mods.js display.js generator.js + +all: editor.min.js + +editor.min.js: $(JS) + java -jar $(COMPILER) --warning_level VERBOSE --compilation_level $(COMPLEVEL) $(addprefix --js=,$^) --externs jquery_externs.js --js_output_file $@ + +clean: + rm -f editor.min.js diff --git a/web/color.js b/web/color.js new file mode 100644 index 00000000..2bf7b78e --- /dev/null +++ b/web/color.js @@ -0,0 +1,432 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +//HSV color wheel popup + +/** + * @param {Element} src + * @param {Number} color + * @param {Function} cb + */ +function pickColor(src,color,cb) +{ + var curR=(color>>16)&0xff; + var curG=(color>>8)&0xff; + var curB=color&0xff; + var wheelSize=200; //width and height of color wheel + var wheelThickness=10; //thickness of the color ring + var wheelGap=2; //gap between wheel and SV square + var wheelBg=[0,0,0,0]; //transparent black background (rgba) + + var diam=wheelSize-wheelThickness*2-wheelGap; + var side=Math.sqrt(diam*diam/2); + + // all numbers scaled 0-255, returns hsv scaled 0-1 + /** + * @param {number} r + * @param {number} g + * @param {number} b + * @returns {Array.} + */ + function rgb2hsv(r,g,b) + { + var h,s,v; + var min=Math.min(r,g,b); + v=Math.max(r,g,b); + if (v==0) // 0,0,0 = 0,0,0 + return [0,0,0]; + var delta=v-min; + s=delta/v; + if (s==0) // grey + return [0,s,v/255]; + if (r==v) //yellow to magenta + h=(g-b)/delta; + else if (g==v) //cyan to yellow + h=2+(b-r)/delta; + else // magenta to cyan + h=4+(r-g)/delta; + h/=6; + if (h<0) + h+=1; + return [h,s,v/255]; + } + // all numbers scaled 0-1.. returns rgb scaled 0-255 + /** + * @param {number} h + * @param {number} s + * @param {number} v + * @returns {Array.} + */ + function hsv2rgb(h,s,v) + { + var r,g,b; + h*=6; + var i=Math.floor(h); + var f=h-i; + var p=v*(1-s); + var q=v*(1-f*s); + var t=v*(1-(1-f)*s); + switch (i%6) + { + case 0: r=v; g=t; b=p; break; + case 1: r=q; g=v; b=p; break; + case 2: r=p; g=v; b=t; break; + case 3: r=p; g=q; b=v; break; + case 4: r=t; g=p; b=v; break; + case 5: r=v; g=p; b=q; break; + } + return [Math.round(r*255),Math.round(g*255),Math.round(b*255)]; + } + + var picker=$(document.createElement('div')); + picker.addClass('picker'); + var pos=src.offset(); + picker.css('top',pos.top+'px'); + picker.css('left',pos.left+'px'); + $(document.body).append(picker); + var canvas=$(document.createElement('canvas')); + canvas.attr('width',wheelSize); + canvas.attr('height',wheelSize); + canvas.css('float','left'); + picker.append(canvas); + var controls=$(document.createElement('div')); + controls.css('float','left'); + picker.append(controls); + var colorswatch=$(document.createElement('div')); + colorswatch.addClass('swatch'); + controls.append(colorswatch); + var hexcolor=$(document.createElement('input')); + hexcolor.attr('type','text'); + hexcolor.addClass('hexcolor'); + hexcolor.keyup(keyhc); + controls.append(hexcolor); + + controls.append($(document.createElement('div')).addClass('colorlabel').text('R:')); + var red=$(document.createElement('input')); + red.attr('type','text'); + red.addClass('colorinput'); + red.keyup(keyred); + controls.append(red); + controls.append($(document.createElement('div')).addClass('colorlabel').text('G:')); + var green=$(document.createElement('input')); + green.attr('type','text'); + green.addClass('colorinput'); + green.keyup(keygreen); + controls.append(green); + controls.append($(document.createElement('div')).addClass('colorlabel').text('B:')); + var blue=$(document.createElement('input')); + blue.attr('type','text'); + blue.addClass('colorinput'); + blue.keyup(keyblue); + controls.append(blue); + + var buttons=$(document.createElement('div')); + buttons.css('clear','left'); + buttons.css('padding-top','10px'); + controls.append(buttons); + var okay=$(document.createElement('button')); + okay.css('float','right'); + okay.text('Okay'); + okay.click(function(){ + picker.remove(); + cb((curR<<16)|(curG<<8)|curB); + }); + buttons.append(okay); + var cancel=$(document.createElement('button')); + cancel.css('float','right'); + cancel.text('Cancel'); + cancel.click(function(){picker.remove();}); + buttons.append(cancel); + + + var clr=$(document.createElement('br')); + clr.css('clear','left'); + picker.append(clr); + + + hexcolor.focus(); + picker.keyup(function(e) { + if (e.keyCode==13) { okay.click(); return false; } + if (e.keyCode==27) { cancel.click(); return false; } + return true; + }); + + canvas.mousedown(function(e){ + var x=e.offsetX; + var y=e.offsetY; + var start=Math.round(wheelSize/2-side/2); + var end=Math.round(wheelSize/2+side/2); + //inside square? + if (x>=start && x=start && y=inner && distanceend) x=end; + if (yend) y=end; + hsv[1]=(x-start)/side; + hsv[2]=1-((y-start)/side); + drawHSV(); + hsvChanged(); + return false; + }); + $(canvas).mouseup(function(){ + $(canvas).unbind("mousemove"); + $(canvas).unbind("mouseup"); + return false + }); + } + + function createHueWheel() + { + //we just loop through all the pixels, figure out if each pixel + //is inside the ring or not, and then calculate the hue if it is. + //This is pretty fast, but only needs to run + //once, since we'll use it as a backdrop buffer for all + //future drawing. + var d=ctx.createImageData(wheelSize,wheelSize); + var offset=0; + var outer=wheelSize/2; + var inner=wheelSize/2-wheelThickness; + for (var y=0;y=inner && distance>16)&0xff; + curG=(color>>8)&0xff; + curB=color&0xff; + hsv=rgb2hsv(curR,curG,curB); + updateRGB(); + updateSwatch(); + drawHSV(); + } + function keyred() + { + curR=parseInt(red.val(),10)&0xff; + color&=0xffff; + color|=curR<<16; + updateHex(); + rgbChanged(); + } + function keygreen() + { + curG=parseInt(green.val(),10)&0xff; + color&=0xff00ff; + color|=curG<<8; + updateHex(); + rgbChanged(); + } + function keyblue() + { + curB=parseInt(blue.val(),10)&0xff; + color&=0xffff00; + color|=curB; + updateHex(); + rgbChanged(); + } + + var colorWheel=createHueWheel(); + var hsv=rgb2hsv(curR,curG,curB); + hsvChanged(); + drawHSV(); +} diff --git a/web/display.js b/web/display.js new file mode 100644 index 00000000..5e954efd --- /dev/null +++ b/web/display.js @@ -0,0 +1,198 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @constructor + */ +function Display() +{ + /** @type {jQuery} */ + var dom=$(document.createElement('div')); + $(document.body).append(dom); + + + var types=['select','button','option','h1','h4','div','br','input','dl','dt','dd','table','tr','td','th','span','a','label']; + + // hides the old screen, creates a new one + this.save=function() + { + var oldDom=dom; + oldDom.hide(); + dom=$(document.createElement('div')); + $(document.body).append(dom); + return oldDom; + } + // destroys current screen, unhides old one + this.restore=function(el) + { + dom.remove(); + dom=el; + dom.show(); + } + // clears current screen + this.clear=function() + { + dom.empty(); + } + + /** + * @param {Object} obj + * @returns {jQuery} + */ + this.toDOM=function(obj) + { + /** @type {string|undefined} */ + var type=undefined; + for (var i=0;i} btns + * @param {Function} cb + */ +function Dialog(display,btns,cb) +{ + var bg=display.toDOM({'div':null,'class':'dialogbg'}); + display.draw(bg); + + var win=display.toDOM({'div':null,'class':'content'}); + var buttons=[]; + for (var i=0;i0); + }); + + /** @type {jQuery} */ + var localmods=display.toDOM({'select':null,'size':'6'}); + /** @type {jQuery} */ + var addmod=display.toDOM({'button':'Add Mod'}); + addmod.click(mods.add); + /** @type {jQuery} */ + var modifymod=display.toDOM({'button':'Modify Mod','disabled':'true'}); + modifymod.click(function(){ + mods.modify(localmods.children(':selected').val()); + }); + /** @type {jQuery} */ + var removemod=display.toDOM({'button':'Remove Mod','disabled':'true'}); + removemod.click(function(){ + mods.remove(localmods.children(':selected').val()); + }); + var exportmod=display.toDOM({'button':'Export Mod','disabled':'true'}); + exportmod.click(function(){ + mods.exportMod(localmods.children(':selected').val()); + }); + localmods.change(function(){ + activate([modifymod,removemod,exportmod],localmods.children(':selected').length>0); + }); + + /** @type {jQuery} */ + var localpacks=display.toDOM({'select':null,'size':'6'}); + /** @type {jQuery} */ + var addpack=display.toDOM({'button':'Add Pack'}); + addpack.click(mods.addPack); + /** @type {jQuery} */ + var modifypack=display.toDOM({'button':'Modify Pack','disabled':'true'}); + modifypack.click(function(){ + mods.modifyPack(localpacks.children(':selected').val()); + }); + /** @type {jQuery} */ + var generatelocal=display.toDOM({'button':'Generate','disabled':'true'}); + generatelocal.click(function(){ + generator.generate(localpacks.children(':selected').val(),true); + }); + /** @type {jQuery} */ + var removepack=display.toDOM({'button':'Remove Pack','disabled':'true'}); + removepack.click(function() { + mods.removePack(localpacks.children(':selected').val()); + }); + localpacks.change(function(){ + activate([modifypack,generatelocal,removepack],localpacks.children(':selected').length>0); + }); + + display.draw([ + {'h1':'Minutor Pack Builder'}, + {'div':[ + {'h4':'Pre-made Packs'}, + packs + ],'css':{'float':'left'}}, + {'div':[ + {'h4':' '}, + generate + ],'css':{'float':'left'}}, + {'div':[ + {'h4':'Your Mods'}, + localmods + ],'css':{'clear':'left','float':'left'}}, + {'div':[ + {'h4':' '}, + addmod, + modifymod, + removemod, + exportmod + ],'css':{'float':'left'}}, + {'div':[ + {'h4':'Your Packs'}, + localpacks + ],'css':{'float':'left'}}, + {'div':[ + {'h4':' '}, + addpack, + modifypack, + removepack, + generatelocal + ],'css':{'float':'left'}} + ]); + + + + /** + * @param {Array.} els + * @param {boolean} onoff + */ + function activate(els,onoff) + { + for (var i=0;ia&&(a+=1);return[a,d,e/255]}function o(a,b,g){var d,e,r,a=6*a,c=Math.floor(a),h=a-c,a=g*(1-b),y=g*(1-h*b),b=g*(1-(1-h)*b);switch(c%6){case 0:d=g;e=b;r=a;break;case 1:d=y;e=g;r=a;break;case 2:d=a;e=g;r=b;break;case 3:d=a;e=y;r=g;break;case 4:d=b;e=a;r=g;break;case 5:d=g,e=a,r=y}return[Math.round(255*d),Math.round(255* +e),Math.round(255*r)]}function t(a,b,g){for(var d=4*(g-3)*h+4*(b-3),e=0,g=0;7>g;g++,d+=4*h-28)for(b=0;7>b;b++,e++)if("."=="..111...10001.10...0110...0110...01.10001...111.."[e])d+=4;else{var r;r="1"=="..111...10001.10...0110...0110...01.10001...111.."[e]?0:255;a.data[d++]=r;a.data[d++]=r;a.data[d++]=r;a.data[d++]=255}}function k(){G.putImageData(H,0,0);for(var a=G.getImageData(0,0,h,h),b=Math.round(h/2-j/2),g=Math.round(h/2+j/2),d=b;da.length;)a="0"+a;I.val(a)}function w(){g.val(String(l));K.val(String(e));L.val(String(d))} +function a(){u.css("background","rgb("+l+","+e+","+d+")")}var l=c>>16&255,e=c>>8&255,d=c&255,h=200,P=10,Q=[0,0,0,0],b=h-2*P-2,j=Math.sqrt(b*b/2),C=$(document.createElement("div"));C.addClass("picker");f=f.offset();C.css("top",f.top+"px");C.css("left",f.left+"px");$(document.body).append(C);var A=$(document.createElement("canvas"));A.attr("width",h);A.attr("height",h);A.css("float","left");C.append(A);f=$(document.createElement("div"));f.css("float","left");C.append(f);var u=$(document.createElement("div")); +u.addClass("swatch");f.append(u);var I=$(document.createElement("input"));I.attr("type","text");I.addClass("hexcolor");I.keyup(function(){c=parseInt(I.val(),16);l=c>>16&255;e=c>>8&255;d=c&255;z=m(l,e,d);w();a();k()});f.append(I);f.append($(document.createElement("div")).addClass("colorlabel").text("R:"));var g=$(document.createElement("input"));g.attr("type","text");g.addClass("colorinput");g.keyup(function(){l=parseInt(g.val(),10)&255;c&=65535;c|=l<<16;q();i()});f.append(g);f.append($(document.createElement("div")).addClass("colorlabel").text("G:")); +var K=$(document.createElement("input"));K.attr("type","text");K.addClass("colorinput");K.keyup(function(){e=parseInt(K.val(),10)&255;c&=16711935;c|=e<<8;q();i()});f.append(K);f.append($(document.createElement("div")).addClass("colorlabel").text("B:"));var L=$(document.createElement("input"));L.attr("type","text");L.addClass("colorinput");L.keyup(function(){d=parseInt(L.val(),10)&255;c&=16776960;c|=d;q();i()});f.append(L);b=$(document.createElement("div"));b.css("clear","left");b.css("padding-top", +"10px");f.append(b);var E=$(document.createElement("button"));E.css("float","right");E.text("Okay");E.click(function(){C.remove();p(l<<16|e<<8|d)});b.append(E);var F=$(document.createElement("button"));F.css("float","right");F.text("Cancel");F.click(function(){C.remove()});b.append(F);f=$(document.createElement("br"));f.css("clear","left");C.append(f);I.focus();C.keyup(function(a){return 13==a.keyCode?(E.click(),B):27==a.keyCode?(F.click(),B):s});A.mousedown(function(a){var b=a.offsetX,a=a.offsetY, +d=Math.round(h/2-j/2),g=Math.round(h/2+j/2);if(b>=d&&b=d&&ay&&(e=y);ry&&(r=y);z[1]=(e-c)/j;z[2]=1-(r-c)/j;k();x();return B});$(A).mouseup(function(){$(A).unbind("mousemove");$(A).unbind("mouseup");return B})}else{var d=h/2,f=a-h/2,l=b-h/2,b=Math.sqrt(l*l+f*f);b>=h/2-P&&b=O&&MD-M?f.data[b++]=255*(D-M):1>M-O?f.data[b++]=255*(M-O):f.data[b++]= +255):(f.data[b++]=Q[0],f.data[b++]=Q[1],f.data[b++]=Q[2],f.data[b++]=Q[3])}H=f;var z=m(l,e,d);x();k()};function S(){function f(a,d){for(var b=0;be.length;)e="0"+e;g.data[a].color=e;1!=b?g.data[a].alpha=b:delete g.data[a].alpha}else delete g.data[a].color,delete g.data[a].alpha;for(e=b=0;e>16)+","+(j>>8&255)+","+(j&255)+")");i.click(function(){N(i,j,function(a){j=a;i.css("background","rgb("+(a>>16)+","+(a>>8&255)+","+(a&255)+")")})});e=100;-1!=a&&(g.data[a].color===n?e=0:g.data[a].alpha!==n&&(e=Math.round(100*g.data[a].alpha)));var q=c.b({input:v,type:"text",size:"4",val:String(e)}),k=[c.b({input:v,type:"checkbox",val:1}),c.b({input:v,type:"checkbox",val:2}),c.b({input:v,type:"checkbox",val:4})];if(-1!=a)for(e=0;e< +k.length;e++)g.data[a].flags&k[e].val()&&k[e].attr("checked","checked");b.c([{dl:[{dt:"ID:"},{dd:h},{dt:"Name:"},{dd:f},{dt:"Color:"},{dd:i},{dt:"Alpha:"},{dd:q},{dt:"Flags:"},{dd:[{label:[k[0],"Transparent"]},{label:[k[1],"Transp. Solid"]},{label:[k[2],"Fluid"]}]},{dt:"Damage Mask:"},{dd:p}]}]);h.focus()}function p(a,b){var e=new X(c,["Save","Cancel"],function(e){if(0==e&&$.isNumeric(h.val())){g.data[a].variants===n&&(g.data[a].variants=[]);-1==b&&(b=g.data[a].variants.length,g.data[a].variants[b]= +{});g.data[a].variants[b].data=parseInt(h.val(),10);e=j.val().trim();e!==g.data[a].name&&""!=e?g.data[a].variants[b].name=e:delete g.data[a].variants[b].name;for(e=l.toString(16);6>e.length;)e="0"+e;g.data[a].color==n||e!==g.data[a].color?g.data[a].variants[b].color=e:delete g.data[a].variants[b].color;u();d()}}),h=c.b({input:v,type:"text",val:-1!=b?g.data[a].variants[b].data:"",size:"4"}),f=g.data[a].name,l=0;g.data[a].color!==n&&(l=parseInt(g.data[a].color,16));-1!=b&&(g.data[a].variants[b].name!== +n&&(f=g.data[a].variants[b].name),g.data[a].variants[b].color!==n&&(l=parseInt(g.data[a].variants[b].color,16)));var j=c.b({input:v,type:"text",val:f,size:"40"}),i=c.b({div:v,"class":"color",css:{background:"rgb("+(l>>16)+","+(l>>8&255)+","+(l&255)+")"}});i.click(function(){N(i,l,function(a){l=a;i.css("background","rgb("+(a>>16)+","+(a>>8&255)+","+(a&255)+")")})});e.c([{dl:[{dt:"Damage:"},{dd:h},{dt:"Name:"},{dd:j},{dt:"Color:"},{dd:i}]}]);h.focus()}function b(){for(var a=[],b=0;bb.config?1:-1});for(var a=0;aO?H.css({position:"fixed"}):H.css({position:"relative"})})};this.remove=function(a){confirm("Are you sure you wish to delete "+w[a].name+"?")&&(delete w[a],o(),f())};this.j=function(a){var d=new Blob([window.JSON.stringify(w[a])],{type:"application/octet-stream"}),c=window.URL.createObjectURL(d),d=$(document.createElement("a"));d.attr("href",c);d.attr("download",a);a=document.createEvent("MouseEvents");a.initMouseEvent("click",s,B,window, +1,0,0,0,0,B,B,B,0,v);d[0].dispatchEvent(a);setTimeout(function(){window.URL.revokeObjectURL(c)},5E3)};this.i=function(){var e=new X(c,["Create","Cancel"],function(e){1==e||""==d.val().trim()||(a.push({name:d.val().trim(),type:"pack",version:"v1",data:[]}),k(),f())}),d=c.b({input:v,type:"text",size:"30"});e.c([{h4:"Add Pack"},{dl:[{dt:"Name:"},{dd:d}]}]);d.focus()};this.k=function(e){var d=c.save(),h=a[e],l=c.b({input:v,type:"text",val:h.name,size:"30"}),p=c.b({input:v,type:"text",val:h.version,size:"8"}), +e="";h.update!=n&&(e=h.update);var b=c.b({input:v,type:"text",val:e,size:"50"}),e=c.b({button:"Save",css:{"float":"right"}});e.click(function(){var a=l.val().trim();if(""==a)alert("You must give this pack a name");else{h.name=a;h.version=p.val().trim();a=b.val().trim();""!=a?h.update=a:delete h.update;h.data.splice(0,h.data.length);for(a=0;ab.id?1:-1:"pre"==a.type?1:-1});for(b=0;bm?q.css({position:"fixed"}):q.css({position:"relative"})});var u};this.l=function(e){confirm("Are you sure you wish to delete "+a[e].name+"?")&&(a.splice(e,1),k(),f())}};function U(){var f=$(document.createElement("div"));$(document.body).append(f);var c="select button option h1 h4 div br input dl dt dd table tr td th span a label".split(" ");this.save=function(){var c=f;c.hide();f=$(document.createElement("div"));$(document.body).append(f);return c};this.restore=function(c){f.remove();f=c;f.show()};this.clear=function(){f.empty()};this.b=function(f){for(var m=n,o=0;od;d++){a=d;for(var f=0;8>f;f++)a=a&1?a>>>1^3988292384:a>>>1;e[d]=a}a=new Date;var k=a.getFullYear()-1980<<9|a.getMonth()+1<<5|a.getDate(), +m=[];a=[];for(var b=0,d=0;d>8&255;for(var f=c[d].file,j=-1,p=0;p>>8^e[(j^f.charCodeAt(p))&255];m[d]=~j;a[b++]=m[d]&255;a[b++]=m[d]>>8&255;a[b++]=m[d]>>16&255;a[b++]=m[d]>>24&255;j=c[d].file.length;a[b++]=j&255;a[b++]=j>>8&255;a[b++]=j>>16&255;a[b++]=j>>24&255;a[b++]=j&255;a[b++]=j>>8&255;a[b++]=j>>16&255;a[b++]=j>>24&255; +a[b++]=c[d].name.length;a[b++]=0;a[b++]=0;for(f=a[b++]=0;f>8&255;a[b++]=m[d]&255;a[b++]=m[d]>>8&255;a[b++]=m[d]>>16&255;a[b++]=m[d]>>24&255;j=c[d].file.length;a[b++]=j&255;a[b++]=j>>8&255;a[b++]=j>>16&255;a[b++]=j>>24&255; +a[b++]=j&255;a[b++]=j>>8&255;a[b++]=j>>16&255;a[b++]=j>>24&255;a[b++]=c[d].name.length;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;a[b++]=0;f=c[d].offset;a[b++]=f&255;a[b++]=f>>8&255;a[b++]=f>>16&255;a[b++]=f>>24&255;for(f=0;f>8&255;a[b++]=c&255;a[b++]=c>>8&255;a[b++]=d& +255;a[b++]=d>>8&255;a[b++]=d>>16&255;a[b++]=d>>24&255;a[b++]=e&255;a[b++]=e>>8&255;a[b++]=e>>16&255;a[b++]=e>>24&255;a[b++]=0;a[b++]=0;a=new Uint8Array(a);c=q.name.toLowerCase().replace(/[^a-z0-9]/g,"")+".zip";a=new Blob([a],{type:"application/zip"});var o=window.URL.createObjectURL(a);a=$(document.createElement("a"));a.attr("href",o);a.attr("download",c);c=document.createEvent("MouseEvents");c.initMouseEvent("click",s,B,window,1,0,0,0,0,B,B,B,0,v);a[0].dispatchEvent(c);setTimeout(function(){window.URL.revokeObjectURL(o)}, +5E3)}var i,q;this.g=function(a,l){i={"pack_info.json":{type:"pack",data:[]}};q=i["pack_info.json"];if(l){var e=f.e[a];q.name=e.name;q.version=e.version;e.update!=n&&(q.update=e.update);for(var d=0;d} */ + var pack; + /** @type {Object} */ + var packInfo; + + /** + * @param {string} key + * @param {boolean} islocal + */ + this.generate=function(key,islocal) + { + pack={'pack_info.json':{'type':'pack','data':[]}}; + packInfo=pack['pack_info.json']; + if (islocal) + { + var p=mods.localPacks[key]; + packInfo['name']=p['name']; + packInfo['version']=p['version']; + if (p['update']!=undefined) + packInfo['update']=p['update']; + for (var i=0;i} + */ + function parseConfig(cfg) + { + var hash={}; + var prefix=[]; + var pendingsymbol=''; + var lines=cfg.split(/\n|\r/); + for (var i=0;i} prefix + * @param {Object.} hash + * @param {string} line + */ + function addConfigLine(prefix,hash,line) + { + if (!line.match(/=/)) + return; + var parts=line.split(/=/); + var key=parts[0]; + if (key.match(/:/)) + { + var kparts=key.split(/:/); + key=kparts[1]; + } + prefix.push(toSymbol(key)); + var val=toSymbol(parts[1]); + if ($.isNumeric(val)) + hash[prefix.join('.')]=parseInt(val,10); + prefix.pop(); + } + /** + * @param {string} sym + * @returns {string} + */ + function toSymbol(sym) + { + sym=sym.trim(); + while (sym.match(/"/)) + sym=sym.replace(/^"(.*)"$/,'$1'); + return sym; + } + + /** + * @param {string} name + * @param {string} type + * @returns {string} + */ + function makeFilename(name,type) + { + var pre=name.toLowerCase().replace(/[^a-z0-9]/g,''); + var post; + switch (type) + { + case 'block': post="_ids.json"; break; + case 'biome': post="_biomes.json"; break; + case 'dimension': post="_dims.json"; break; + } + var fn=pre+post; + var mid=1; + while (fn in pack) + { + mid++; + fn=pre+mid+post; + } + return fn; + } + + function zipPack() + { + // remove any unconfigured lines from the pack + // we do this because the pack might be using an older config + for (var f in pack) + { + if (pack[f]['type']=='pack') continue; + for (var i=pack[f]['data'].length-1;i>=0;i--) + if (pack[f]['data'][i]['config']!==undefined) + pack[f]['data'].splice(i,1); //remove it + if (pack[f]['data'].length==0) //no data? remove entire mod + { + delete pack[f]; + for (var i=0;i + +Minutor Pack Builder + + + + + + + \ No newline at end of file diff --git a/web/jquery_externs.js b/web/jquery_externs.js new file mode 100644 index 00000000..4cc2dea2 --- /dev/null +++ b/web/jquery_externs.js @@ -0,0 +1,2243 @@ +/* + * Copyright 2011 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Externs for jQuery 1.7.2 + * + * Note that some functions use different return types depending on the number + * of parameters passed in. In these cases, you may need to annotate the type + * of the result in your code, so the JSCompiler understands which type you're + * expecting. For example: + * var elt = /** @type {Element} * / (foo.get(0)); + * + * @see http://api.jquery.com/ + * @externs + */ + +/** + * @typedef {(Window|Document|Element|Array.|string|jQuery| + * NodeList)} + */ +var jQuerySelector; + +/** + * @constructor + * @param {(jQuerySelector|Element|Object|Array.|jQuery|string| + * function())=} arg1 + * @param {(Element|jQuery|Document| + * Object.)=} arg2 + * @return {!jQuery} + */ +function jQuery(arg1, arg2) {} + +/** + * @constructor + * @extends {jQuery} + * @param {(jQuerySelector|Element|Array.|Object|jQuery|string| + * function())} arg1 + * @param {(Element|jQuery|Document| + * Object.)=} arg2 + * @return {!jQuery} + */ +function $(arg1, arg2) {} + +/** + * @param {(jQuerySelector|Array.|string|jQuery)} arg1 + * @param {Element=} context + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.add = function(arg1, context) {}; + +/** + * @param {(string|function(number,String))} arg1 + * @return {!jQuery} + */ +jQuery.prototype.addClass = function(arg1) {}; + +/** + * @param {(string|Element|jQuery|function(number))} arg1 + * @param {(string|Element|Array.|jQuery)=} content + * @return {!jQuery} + */ +jQuery.prototype.after = function(arg1, content) {}; + +/** + * @param {(string|Object.)} arg1 + * @param {Object.=} settings + * @return {jQuery.jqXHR} + */ +jQuery.ajax = function(arg1, settings) {}; + +/** + * @param {(string|Object.)} arg1 + * @param {Object.=} settings + * @return {jQuery.jqXHR} + */ +$.ajax = function(arg1, settings) {}; + +/** + * @param {function(!jQuery.event,XMLHttpRequest,Object.)} handler + * @return {!jQuery} + */ +jQuery.prototype.ajaxComplete = function(handler) {}; + +/** + * @param {function(!jQuery.event,jQuery.jqXHR,Object.,*)} handler + * @return {!jQuery} + */ +jQuery.prototype.ajaxError = function(handler) {}; + +/** + * @param {(string| + * function(Object.,Object.,jQuery.jqXHR))} dataTypes + * @param {function(Object.,Object.,jQuery.jqXHR)=} handler + */ +jQuery.ajaxPrefilter = function(dataTypes, handler) {}; + +/** + * @param {(string| + * function(Object.,Object.,jQuery.jqXHR))} dataTypes + * @param {function(Object.,Object.,jQuery.jqXHR)=} handler + */ +$.ajaxPrefilter = function(dataTypes, handler) {}; + +/** + * @param {function(!jQuery.event,jQuery.jqXHR,Object.)} handler + * @return {!jQuery} + */ +jQuery.prototype.ajaxSend = function(handler) {}; + +/** @const */ +jQuery.ajaxSettings = {}; + +/** @const */ +$.ajaxSettings = {}; + +/** @type {Object.} */ +jQuery.ajaxSettings.accepts = {}; + +/** @type {Object.} */ +$.ajaxSettings.accepts = {}; + +/** @type {boolean} */ +jQuery.ajaxSettings.async; + +/** @type {boolean} */ +$.ajaxSettings.async; + +/** @type {Object.} */ +jQuery.ajaxSettings.contents = {}; + +/** @type {Object.} */ +$.ajaxSettings.contents = {}; + +/** @type {string} */ +jQuery.ajaxSettings.contentType; + +/** @type {string} */ +$.ajaxSettings.contentType; + +/** @type {Object.} */ +jQuery.ajaxSettings.converters = {}; + +/** @type {Object.} */ +$.ajaxSettings.converters = {}; + +/** @type {Object.} */ +jQuery.ajaxSettings.flatOptions = {}; + +/** @type {Object.} */ +$.ajaxSettings.flatOptions = {}; + +/** @type {boolean} */ +jQuery.ajaxSettings.global; + +/** @type {boolean} */ +$.ajaxSettings.global; + +/** @type {boolean} */ +jQuery.ajaxSettings.isLocal; + +/** @type {boolean} */ +$.ajaxSettings.isLocal; + +/** @type {boolean} */ +jQuery.ajaxSettings.processData; + +/** @type {boolean} */ +$.ajaxSettings.processData; + +/** @type {Object.} */ +jQuery.ajaxSettings.responseFields = {}; + +/** @type {Object.} */ +$.ajaxSettings.responseFields = {}; + +/** @type {boolean} */ +jQuery.ajaxSettings.traditional; + +/** @type {boolean} */ +$.ajaxSettings.traditional; + +/** @type {string} */ +jQuery.ajaxSettings.type; + +/** @type {string} */ +$.ajaxSettings.type; + +/** @type {string} */ +jQuery.ajaxSettings.url; + +/** @type {string} */ +$.ajaxSettings.url; + +/** @return {XMLHttpRequest|ActiveXObject} */ +jQuery.ajaxSettings.xhr = function() {}; + +/** @return {XMLHttpRequest|ActiveXObject} */ +$.ajaxSettings.xhr = function() {}; + +/** @param {Object.} options */ +jQuery.ajaxSetup = function(options) {}; + +/** @param {Object.} options */ +$.ajaxSetup = function(options) {}; + +/** + * @param {function()} handler + * @return {!jQuery} + */ +jQuery.prototype.ajaxStart = function(handler) {}; + +/** + * @param {function()} handler + * @return {!jQuery} + */ +jQuery.prototype.ajaxStop = function(handler) {}; + +/** + * @param {function(!jQuery.event,XMLHttpRequest,Object.)} handler + * @return {!jQuery} + */ +jQuery.prototype.ajaxSuccess = function(handler) {}; + +/** + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.andSelf = function() {}; + +/** + * @param {Object.} properties + * @param {(string|number|function()|Object.)=} arg2 + * @param {(string|function())=} easing + * @param {function()=} complete + * @return {!jQuery} + */ +jQuery.prototype.animate = function(properties, arg2, easing, complete) {}; + +/** + * @param {(string|Element|jQuery|function(number,string))} arg1 + * @param {(string|Element|Array.|jQuery)=} content + * @return {!jQuery} + */ +jQuery.prototype.append = function(arg1, content) {}; + +/** + * @param {(jQuerySelector|Element|jQuery)} target + * @return {!jQuery} + */ +jQuery.prototype.appendTo = function(target) {}; + +/** + * @param {(string|Object.)} arg1 + * @param {(string|number|function(number,string))=} arg2 + * @return {(string|!jQuery)} + */ +jQuery.prototype.attr = function(arg1, arg2) {}; + +/** + * @param {(string|Element|jQuery|function())} arg1 + * @param {(string|Element|Array.|jQuery)=} content + * @return {!jQuery} + */ +jQuery.prototype.before = function(arg1, content) {}; + +/** + * @param {(string|Object.)} arg1 + * @param {(Object.|function(!jQuery.event=)|boolean)=} eventData + * @param {(function(!jQuery.event=)|boolean)=} arg3 + * @return {!jQuery} + */ +jQuery.prototype.bind = function(arg1, eventData, arg3) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.blur = function(arg1, handler) {}; + +/** @type {boolean} */ +jQuery.boxModel; + +/** @type {boolean} */ +$.boxModel; + +/** @type {Object.} */ +jQuery.browser; + +/** @type {Object.} */ +$.browser; + +/** + * @type {boolean} + * @const + */ +jQuery.browser.mozilla; + +/** + * @type {boolean} + * @const + */ +$.browser.mozilla; + +/** + * @type {boolean} + * @const + */ +jQuery.browser.msie; + +/** + * @type {boolean} + * @const + */ +$.browser.msie; + +/** + * @type {boolean} + * @const + */ +jQuery.browser.opera; + +/** + * @type {boolean} + * @const + */ +$.browser.opera; + +/** + * @deprecated + * @type {boolean} + * @const + */ +jQuery.browser.safari; + +/** + * @deprecated + * @type {boolean} + * @const + */ +$.browser.safari; + +/** @type {string} */ +jQuery.browser.version; + +/** @type {string} */ +$.browser.version; + +/** + * @type {boolean} + * @const + */ +jQuery.browser.webkit; + +/** + * @type {boolean} + * @const + */ +$.browser.webkit; + +/** + * @constructor + * @private + */ +jQuery.callbacks = function () {}; + +/** + * @param {string=} flags + * @return {jQuery.callbacks} + */ +jQuery.Callbacks = function (flags) {}; + +/** @param {function()} callbacks */ +jQuery.callbacks.prototype.add = function(callbacks) {}; + +/** @return {undefined} */ +jQuery.callbacks.prototype.disable = function() {}; + +/** @return {undefined} */ +jQuery.callbacks.prototype.empty = function() {}; + +/** @param {...*} var_args */ +jQuery.callbacks.prototype.fire = function(var_args) {}; + +/** @return {boolean} */ +jQuery.callbacks.prototype.fired = function() {}; + +/** @param {...*} var_args */ +jQuery.callbacks.prototype.fireWith = function(var_args) {}; + +/** + * @param {function()} callback + * @return {boolean} + * @nosideeffects + */ +jQuery.callbacks.prototype.has = function(callback) {}; + +/** @return {undefined} */ +jQuery.callbacks.prototype.lock = function() {}; + +/** @return {boolean} */ +jQuery.callbacks.prototype.locked = function() {}; + +/** @param {function()} callbacks */ +jQuery.callbacks.prototype.remove = function(callbacks) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.change = function(arg1, handler) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.children = function(selector) {}; + +/** + * @param {string=} queueName + * @return {!jQuery} + */ +jQuery.prototype.clearQueue = function(queueName) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.click = function(arg1, handler) {}; + +/** + * @param {boolean=} withDataAndEvents + * @param {boolean=} deepWithDataAndEvents + * @return {!jQuery} + * @suppress {checkTypes} see issue 583 + */ +jQuery.prototype.clone = function(withDataAndEvents, deepWithDataAndEvents) {}; + +/** + * @param {(jQuerySelector|jQuery|Element|string|Array.)} arg1 + * @param {Element=} context + * @return {(!jQuery|Array.)} + * @nosideeffects + */ +jQuery.prototype.closest = function(arg1, context) {}; + +/** + * @param {Element} container + * @param {Element} contained + * @return {boolean} + */ +jQuery.contains = function(container, contained) {}; + +/** + * @param {Element} container + * @param {Element} contained + * @return {boolean} + */ +$.contains = function(container, contained) {}; + +/** + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.contents = function() {}; + +/** @type {Element} */ +jQuery.prototype.context; + +/** + * @param {(string|Object.)} arg1 + * @param {(string|number|function(number,*))=} arg2 + * @return {(string|!jQuery)} + */ +jQuery.prototype.css = function(arg1, arg2) {}; + +/** @type {Object.} */ +jQuery.cssHooks; + +/** @type {Object.} */ +$.cssHooks; + +/** + * @param {Element} elem + * @param {string=} key + * @param {*=} value + * @return {*} + */ +jQuery.data = function(elem, key, value) {}; + +/** + * @param {(string|Object.)=} arg1 + * @param {*=} value + * @return {*} + */ +jQuery.prototype.data = function(arg1, value) {}; + +/** + * @param {Element} elem + * @param {string=} key + * @param {*=} value + * @return {*} + */ +$.data = function(elem, key, value) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.dblclick = function(arg1, handler) {}; + +/** + * @constructor + * @param {function()=} opt_fn + * @see http://api.jquery.com/category/deferred-object/ + */ +jQuery.deferred = function(opt_fn) {}; + +/** + * @constructor + * @extends {jQuery.deferred} + * @param {function()=} opt_fn + * @return {jQuery.Deferred} + */ +jQuery.Deferred = function(opt_fn) {}; + +/** + * @constructor + * @extends {jQuery.deferred} + * @param {function()=} opt_fn + * @see http://api.jquery.com/category/deferred-object/ + */ +$.deferred = function(opt_fn) {}; + +/** + * @constructor + * @extends {jQuery.deferred} + * @param {function()=} opt_fn + * @return {jQuery.deferred} + */ +$.Deferred = function(opt_fn) {}; + +/** + * @param {function()} alwaysCallbacks + * @param {function()=} alwaysCallbacks2 + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.always + = function(alwaysCallbacks, alwaysCallbacks2) {}; + +/** + * @param {function()} doneCallbacks + * @param {function()=} doneCallbacks2 + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.done = function(doneCallbacks, doneCallbacks2) {}; + +/** + * @param {function()} failCallbacks + * @param {function()=} failCallbacks2 + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.fail = function(failCallbacks, failCallbacks2) {}; + +/** + * @deprecated + * @return {boolean} + * @nosideeffects + */ +jQuery.deferred.prototype.isRejected = function() {}; + +/** + * @deprecated + * @return {boolean} + * @nosideeffects + */ +jQuery.deferred.prototype.isResolved = function() {}; + +/** + * @param {...*} var_args + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.notify = function(var_args) {}; + +/** + * @param {Object} context + * @param {...*} var_args + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.notifyWith = function(context, var_args) {}; + +/** + * @param {function()=} doneFilter + * @param {function()=} failFilter + * @param {function()=} progressFilter + * @return {jQuery.Promise} + */ +jQuery.deferred.prototype.pipe + = function(doneFilter, failFilter, progressFilter) {}; + +/** + * @param {function()} progressCallbacks + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.progress = function(progressCallbacks) {}; + +/** + * @param {Object=} target + * @return {jQuery.Promise} + */ +jQuery.deferred.prototype.promise = function(target) {}; + +/** + * @param {...*} var_args + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.reject = function(var_args) {}; + +/** + * @param {Object} context + * @param {Array.<*>=} args + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.rejectWith = function(context, args) {}; + +/** + * @param {...*} var_args + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.resolve = function(var_args) {}; + +/** + * @param {Object} context + * @param {Array.<*>=} args + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.resolveWith = function(context, args) {}; + +/** @return {string} */ +jQuery.deferred.prototype.state = function() {}; + +/** + * @param {function()} doneCallbacks + * @param {function()} failCallbacks + * @param {function()=} progressCallbacks + * @return {jQuery.deferred} + */ +jQuery.deferred.prototype.then + = function(doneCallbacks, failCallbacks, progressCallbacks) {}; + +/** + * @param {number} duration + * @param {string=} queueName + * @return {!jQuery} + */ +jQuery.prototype.delay = function(duration, queueName) {}; + +/** + * @param {string} selector + * @param {(string|Object.)} arg2 + * @param {(function(!jQuery.event=)|Object.)=} arg3 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.delegate = function(selector, arg2, arg3, handler) {}; + +/** + * @param {Element} elem + * @param {string=} queueName + */ +jQuery.dequeue = function(elem, queueName) {}; + +/** + * @param {string=} queueName + * @return {!jQuery} + */ +jQuery.prototype.dequeue = function(queueName) {}; + +/** + * @param {Element} elem + * @param {string=} queueName + */ +$.dequeue = function(elem, queueName) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + */ +jQuery.prototype.detach = function(selector) {}; + +/** + * @deprecated + * @param {(string|Object.)=} arg1 + * @param {string=} handler + * @return {!jQuery} + */ +jQuery.prototype.die = function(arg1, handler) {}; + +/** + * @param {Object} collection + * @param {function(number,?)} callback + * @return {Object} + */ +jQuery.each = function(collection, callback) {}; + +/** + * @param {function(number,Element)} fnc + * @return {!jQuery} + */ +jQuery.prototype.each = function(fnc) {}; + +/** + * @param {Object} collection + * @param {function(number,?)} callback + * @return {Object} + */ +$.each = function(collection, callback) {}; + +/** @return {!jQuery} */ +jQuery.prototype.empty = function() {}; + +/** + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.end = function() {}; + +/** + * @param {number} arg1 + * @return {!jQuery} + */ +jQuery.prototype.eq = function(arg1) {}; + +/** @param {string} message */ +jQuery.error = function(message) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.error = function(arg1, handler) {}; + +/** @param {string} message */ +$.error = function(message) {}; + +/** + * @constructor + * @param {string} eventType + */ +jQuery.event = function(eventType) {}; + +/** + * @constructor + * @extends {jQuery.event} + * @param {string} eventType + * @param {Object=} properties + * @return {jQuery.Event} + */ +jQuery.Event = function(eventType, properties) {}; + +/** + * @constructor + * @extends {jQuery.event} + * @param {string} eventType + */ +$.event = function(eventType) {}; + +/** + * @constructor + * @extends {jQuery.event} + * @param {string} eventType + * @param {Object=} properties + * @return {$.Event} + */ +$.Event = function(eventType, properties) {}; + +/** @type {Element} */ +jQuery.event.prototype.currentTarget; + +/** @type {Object.} */ +jQuery.event.prototype.data; + +/** @type {Element} */ +jQuery.event.prototype.delegateTarget; + +/** + * @return {boolean} + * @nosideeffects + */ +jQuery.event.prototype.isDefaultPrevented = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +jQuery.event.prototype.isImmediatePropagationStopped = function() {}; + +/** + * @return {boolean} + * @nosideeffects + */ +jQuery.event.prototype.isPropagationStopped = function() {}; + +/** @type {string} */ +jQuery.event.prototype.namespace; + +/** @type {Event} */ +jQuery.event.prototype.originalEvent; + +/** @type {number} */ +jQuery.event.prototype.pageX; + +/** @type {number} */ +jQuery.event.prototype.pageY; + +/** @return {undefined} */ +jQuery.event.prototype.preventDefault = function() {}; + +/** @type {Object.} */ +jQuery.event.prototype.props; + +/** @type {Element} */ +jQuery.event.prototype.relatedTarget; + +/** @type {*} */ +jQuery.event.prototype.result; + +/** @return {undefined} */ +jQuery.event.prototype.stopImmediatePropagation = function() {}; + +/** @return {undefined} */ +jQuery.event.prototype.stopPropagation = function() {}; + +/** @type {Element} */ +jQuery.event.prototype.target; + +/** @type {number} */ +jQuery.event.prototype.timeStamp; + +/** @type {string} */ +jQuery.event.prototype.type; + +/** @type {number} */ +jQuery.event.prototype.which; + +/** + * @param {(Object|boolean)} arg1 + * @param {...*} var_args + * @return {Object} + */ +jQuery.extend = function(arg1, var_args) {}; + +/** + * @param {(Object|boolean)} arg1 + * @param {...*} var_args + * @return {Object} + */ +jQuery.prototype.extend = function(arg1, var_args) {}; + +/** + * @param {(Object|boolean)} arg1 + * @param {...*} var_args + * @return {Object} + */ +$.extend = function(arg1, var_args) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.fadeIn = function(duration, arg2, callback) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.fadeOut = function(duration, arg2, callback) {}; + +/** + * @param {(string|number)} duration + * @param {number} opacity + * @param {(function()|string)=} arg3 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.fadeTo = function(duration, opacity, arg3, callback) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(string|function())=} easing + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.fadeToggle = function(duration, easing, callback) {}; + +/** + * @param {(jQuerySelector|function(number)|Element|jQuery)} arg1 + * @return {!jQuery} + */ +jQuery.prototype.filter = function(arg1) {}; + +/** + * @param {(jQuerySelector|jQuery|Element)} arg1 + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.find = function(arg1) {}; + +/** @return {!jQuery} */ +jQuery.prototype.first = function() {}; + +/** @see http://docs.jquery.com/Plugins/Authoring */ +jQuery.fn; + +/** @see http://docs.jquery.com/Plugins/Authoring */ +$.fn; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.focus = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.focusin = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.focusout = function(arg1, handler) {}; + +/** @const */ +jQuery.fx = {}; + +/** @const */ +$.fx = {}; + +/** @type {number} */ +jQuery.fx.interval; + +/** @type {number} */ +$.fx.interval; + +/** @type {boolean} */ +jQuery.fx.off; + +/** @type {boolean} */ +$.fx.off; + +/** + * @param {string} url + * @param {(Object.|string| + * function(string,string,jQuery.jqXHR))=} data + * @param {(function(string,string,jQuery.jqXHR)|string)=} success + * @param {string=} dataType + * @return {jQuery.jqXHR} + */ +jQuery.get = function(url, data, success, dataType) {}; + +/** + * @param {number=} index + * @return {(Element|Array.)} + * @nosideeffects + */ +jQuery.prototype.get = function(index) {}; + +/** + * @param {string} url + * @param {(Object.|string| + * function(string,string,jQuery.jqXHR))=} data + * @param {(function(string,string,jQuery.jqXHR)|string)=} success + * @param {string=} dataType + * @return {jQuery.jqXHR} + */ +$.get = function(url, data, success, dataType) {}; + +/** + * @param {string} url + * @param {(Object.|function(string,string,jQuery.jqXHR))=} data + * @param {function(string,string,jQuery.jqXHR)=} success + * @return {jQuery.jqXHR} + */ +jQuery.getJSON = function(url, data, success) {}; + +/** + * @param {string} url + * @param {(Object.|function(string,string,jQuery.jqXHR))=} data + * @param {function(string,string,jQuery.jqXHR)=} success + * @return {jQuery.jqXHR} + */ +$.getJSON = function(url, data, success) {}; + +/** + * @param {string} url + * @param {function(Node,string,jQuery.jqXHR)=} success + * @return {jQuery.jqXHR} + */ +jQuery.getScript = function(url, success) {}; + +/** + * @param {string} url + * @param {function(Node,string,jQuery.jqXHR)=} success + * @return {jQuery.jqXHR} + */ +$.getScript = function(url, success) {}; + +/** @param {string} code */ +jQuery.globalEval = function(code) {}; + +/** @param {string} code */ +$.globalEval = function(code) {}; + +/** + * @param {Array.<*>} arr + * @param {function(*,number)} fnc + * @param {boolean=} invert + * @return {Array.<*>} + */ +jQuery.grep = function(arr, fnc, invert) {}; + +/** + * @param {Array.<*>} arr + * @param {function(*,number)} fnc + * @param {boolean=} invert + * @return {Array.<*>} + */ +$.grep = function(arr, fnc, invert) {}; + +/** + * @param {(string|Element)} arg1 + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.has = function(arg1) {}; + +/** + * @param {string} className + * @return {boolean} + * @nosideeffects + */ +jQuery.prototype.hasClass = function(className) {}; + +/** + * @param {Element} elem + * @return {boolean} + * @nosideeffects + */ +jQuery.hasData = function(elem) {}; + +/** + * @param {Element} elem + * @return {boolean} + * @nosideeffects + */ +$.hasData = function(elem) {}; + +/** + * @param {(string|number|function(number,number))=} arg1 + * @return {(number|!jQuery)} + */ +jQuery.prototype.height = function(arg1) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.hide = function(duration, arg2, callback) {}; + +/** @param {boolean} hold */ +jQuery.holdReady = function(hold) {}; + +/** @param {boolean} hold */ +$.holdReady = function(hold) {}; + +/** + * @param {function(!jQuery.event=)} arg1 + * @param {function(!jQuery.event=)=} handlerOut + * @return {!jQuery} + */ +jQuery.prototype.hover = function(arg1, handlerOut) {}; + +/** + * @param {(string|function(number,string))=} arg1 + * @return {(string|!jQuery)} + */ +jQuery.prototype.html = function(arg1) {}; + +/** + * @param {*} value + * @param {Array.<*>} arr + * @param {number=} fromIndex + * @return {number} + * @nosideeffects + */ +jQuery.inArray = function(value, arr, fromIndex) {}; + +/** + * @param {*} value + * @param {Array.<*>} arr + * @param {number=} fromIndex + * @return {number} + * @nosideeffects + */ +$.inArray = function(value, arr, fromIndex) {}; + +/** + * @param {(jQuerySelector|Element|jQuery)=} arg1 + * @return {number} + */ +jQuery.prototype.index = function(arg1) {}; + +/** + * @return {number} + * @nosideeffects + */ +jQuery.prototype.innerHeight = function() {}; + +/** + * @return {number} + * @nosideeffects + */ +jQuery.prototype.innerWidth = function() {}; + +/** + * @param {(jQuerySelector|Element|jQuery)} target + * @return {!jQuery} + */ +jQuery.prototype.insertAfter = function(target) {}; + +/** + * @param {(jQuerySelector|Element|jQuery)} target + * @return {!jQuery} + */ +jQuery.prototype.insertBefore = function(target) {}; + +/** + * @param {(jQuerySelector|function(number)|jQuery|Element)} arg1 + * @return {boolean} + */ +jQuery.prototype.is = function(arg1) {}; + +/** + * @param {*} obj + * @return {boolean} + * @nosideeffects + */ +jQuery.isArray = function(obj) {}; + +/** + * @param {*} obj + * @return {boolean} + * @nosideeffects + */ +$.isArray = function(obj) {}; + +/** + * @param {Object} obj + * @return {boolean} + * @nosideeffects + */ +jQuery.isEmptyObject = function(obj) {}; + +/** + * @param {Object} obj + * @return {boolean} + * @nosideeffects + */ +$.isEmptyObject = function(obj) {}; + +/** + * @param {*} obj + * @return {boolean} + * @nosideeffects + */ +jQuery.isFunction = function(obj) {}; + +/** + * @param {*} obj + * @return {boolean} + * @nosideeffects + */ +$.isFunction = function(obj) {}; + +/** + * @param {*} value + * @return {boolean} + * @nosideeffects + */ +jQuery.isNumeric = function(value) {}; + +/** + * @param {*} value + * @return {boolean} + * @nosideeffects + */ +$.isNumeric = function(value) {}; + +/** + * @param {Object} obj + * @return {boolean} + * @nosideeffects + */ +jQuery.isPlainObject = function(obj) {}; + +/** + * @param {Object} obj + * @return {boolean} + * @nosideeffects + */ +$.isPlainObject = function(obj) {}; + +/** + * @param {*} obj + * @return {boolean} + * @nosideeffects + */ +jQuery.isWindow = function(obj) {}; + +/** + * @param {*} obj + * @return {boolean} + * @nosideeffects + */ +$.isWindow = function(obj) {}; + +/** + * @param {Element} node + * @return {boolean} + * @nosideeffects + */ +jQuery.isXMLDoc = function(node) {}; + +/** + * @param {Element} node + * @return {boolean} + * @nosideeffects + */ +$.isXMLDoc = function(node) {}; + +/** @type {string} */ +jQuery.prototype.jquery; + +/** + * @constructor + * @extends {XMLHttpRequest} + * @implements {jQuery.Promise} + * @private + * @see http://api.jquery.com/jQuery.ajax/#jqXHR + */ +jQuery.jqXHR = function () {}; + +/** + * @deprecated + * @param {function()} callback + * @return {jQuery.jqXHR} +*/ +jQuery.jqXHR.prototype.complete = function (callback) {}; + +/** + * @override + * @param {function()} doneCallbacks + * @return {jQuery.Promise} + */ +jQuery.jqXHR.prototype.done = function(doneCallbacks) {}; + +/** + * @deprecated + * @param {function()} callback + * @return {jQuery.jqXHR} +*/ +jQuery.jqXHR.prototype.error = function (callback) {}; + +/** + * @override + * @param {function()} failCallbacks + * @return {jQuery.Promise} + */ +jQuery.jqXHR.prototype.fail = function(failCallbacks) {}; + +/** + * @deprecated + * @override + * @return {boolean} + * @nosideeffects + */ +jQuery.jqXHR.prototype.isRejected = function() {}; + +/** + * @deprecated + * @override + * @return {boolean} + * @nosideeffects + */ +jQuery.jqXHR.prototype.isResolved = function() {}; + +/** + * @deprecated + * @override + */ +jQuery.jqXHR.prototype.onreadystatechange = function (callback) {}; + +/** + * @deprecated + * @param {function()} callback + * @return {jQuery.jqXHR} +*/ +jQuery.jqXHR.prototype.success = function (callback) {}; + +/** + * @override + * @param {function()} doneCallbacks + * @param {function()} failCallbacks + * @return {jQuery.Promise} + */ +jQuery.jqXHR.prototype.then = function(doneCallbacks, failCallbacks) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.keydown = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.keypress = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.keyup = function(arg1, handler) {}; + +/** @return {!jQuery} */ +jQuery.prototype.last = function() {}; + +/** @type {number} */ +jQuery.prototype.length; + +/** + * @deprecated + * @param {(string|Object)} arg1 + * @param {(function(!jQuery.event=)|Object)=} arg2 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.live = function(arg1, arg2, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.|string)} arg1 + * @param {(function(!jQuery.event=)|Object.|string)=} arg2 + * @param {function(string,string,XMLHttpRequest)=} complete + * @return {!jQuery} + */ +jQuery.prototype.load = function(arg1, arg2, complete) {}; + +/** + * @param {*} obj + * @return {Array.<*>} + */ +jQuery.makeArray = function(obj) {}; + +/** + * @param {*} obj + * @return {Array.<*>} + */ +$.makeArray = function(obj) {}; + +/** + * @param {(Array.<*>|Object.)} arg1 + * @param {(function(*,number)|function(*,(string|number)))} callback + * @return {Array.<*>} + */ +jQuery.map = function(arg1, callback) {}; + +/** + * @param {function(number,Element)} callback + * @return {!jQuery} + */ +jQuery.prototype.map = function(callback) {}; + +/** + * @param {(Array.<*>|Object.)} arg1 + * @param {(function(*,number)|function(*,(string|number)))} callback + * @return {Array.<*>} + */ +$.map = function(arg1, callback) {}; + +/** + * @param {Array.<*>} first + * @param {Array.<*>} second + * @return {Array.<*>} + */ +jQuery.merge = function(first, second) {}; + +/** + * @param {Array.<*>} first + * @param {Array.<*>} second + * @return {Array.<*>} + */ +$.merge = function(first, second) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mousedown = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mouseenter = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mouseleave = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mousemove = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mouseout = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mouseover = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.mouseup = function(arg1, handler) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.next = function(selector) {}; + +/** + * @param {string=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.nextAll = function(selector) {}; + +/** + * @param {(jQuerySelector|Element)=} arg1 + * @param {jQuerySelector=} filter + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.nextUntil = function(arg1, filter) {}; + +/** + * @param {boolean=} removeAll + * @return {Object} + */ +jQuery.noConflict = function(removeAll) {}; + +/** + * @param {boolean=} removeAll + * @return {Object} + */ +$.noConflict = function(removeAll) {}; + +/** + * @return {function()} + * @nosideeffects + */ +jQuery.noop = function() {}; + +/** + * @return {function()} + * @nosideeffects + */ +$.noop = function() {}; + +/** + * @param {(jQuerySelector|Array.|function(number)|jQuery)} arg1 + * @return {!jQuery} + */ +jQuery.prototype.not = function(arg1) {}; + +/** + * @return {number} + * @nosideeffects + */ +jQuery.now = function() {}; + +/** + * @return {number} + * @nosideeffects + */ +$.now = function() {}; + +/** + * @param {(string|Object.)} arg1 + * @param {(string|function(!jQuery.event=))=} selector + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.off = function(arg1, selector, handler) {}; + +/** + * @param {({left:number,top:number}| + * function(number,{top:number,left:number}))=} arg1 + * @return {({left:number,top:number}|!jQuery)} + */ +jQuery.prototype.offset = function(arg1) {}; + +/** + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.offsetParent = function() {}; + +/** + * @param {(string|Object.)} arg1 + * @param {*=} selector + * @param {*=} data + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.on = function(arg1, selector, data, handler) {}; + +/** + * @param {(string|Object.)} arg1 + * @param {*=} arg2 + * @param {*=} arg3 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.one = function(arg1, arg2, arg3, handler) {}; + +/** + * @param {boolean=} includeMargin + * @return {number} + * @nosideeffects + */ +jQuery.prototype.outerHeight = function(includeMargin) {}; + +/** + * @param {boolean=} includeMargin + * @return {number} + * @nosideeffects + */ +jQuery.prototype.outerWidth = function(includeMargin) {}; + +/** + * @param {(Object.|Array.>)} obj + * @param {boolean=} traditional + * @return {string} + */ +jQuery.param = function(obj, traditional) {}; + +/** + * @param {(Object.|Array.>)} obj + * @param {boolean=} traditional + * @return {string} + */ +$.param = function(obj, traditional) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.parent = function(selector) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.parents = function(selector) {}; + +/** + * @param {(jQuerySelector|Element)=} arg1 + * @param {jQuerySelector=} filter + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.parentsUntil = function(arg1, filter) {}; + +/** + * @param {string} json + * @return {Object.} + */ +jQuery.parseJSON = function(json) {}; + +/** + * @param {string} json + * @return {Object.} + */ +$.parseJSON = function(json) {}; + +/** + * @param {string} data + * @return {Document} + */ +jQuery.parseXML = function(data) {}; + +/** + * @param {string} data + * @return {Document} + */ +$.parseXML = function(data) {}; + +/** + * @return {{left:number,top:number}} + * @nosideeffects + */ +jQuery.prototype.position = function() {}; + +/** + * @param {string} url + * @param {(Object.|string| + * function(string,string,jQuery.jqXHR))=} data + * @param {(function(string,string,jQuery.jqXHR)|string)=} success + * @param {string=} dataType + * @return {jQuery.jqXHR} + */ +jQuery.post = function(url, data, success, dataType) {}; + +/** + * @param {string} url + * @param {(Object.|string| + * function(string,string,jQuery.jqXHR))=} data + * @param {(function(string,string,jQuery.jqXHR)|string)=} success + * @param {string=} dataType + * @return {jQuery.jqXHR} + */ +$.post = function(url, data, success, dataType) {}; + +/** + * @param {(string|Element|jQuery|function(number,string))} arg1 + * @param {(string|Element|jQuery)=} content + * @return {!jQuery} + */ +jQuery.prototype.prepend = function(arg1, content) {}; + +/** + * @param {(jQuerySelector|Element|jQuery)} target + * @return {!jQuery} + */ +jQuery.prototype.prependTo = function(target) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.prev = function(selector) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.prevAll = function(selector) {}; + +/** + * @param {(jQuerySelector|Element)=} arg1 + * @param {jQuerySelector=} filter + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.prevUntil = function(arg1, filter) {}; + +/** + * @param {(string|Object)=} type + * @param {Object=} target + * @return {jQuery.Promise} + */ +jQuery.prototype.promise = function(type, target) {}; + +/** + * @interface + * @private + * @see http://api.jquery.com/Types/#Promise + */ +jQuery.Promise = function () {}; + +/** + * @param {function()} doneCallbacks + * @return {jQuery.Promise} + */ +jQuery.Promise.prototype.done = function(doneCallbacks) {}; + +/** + * @param {function()} failCallbacks + * @return {jQuery.Promise} + */ +jQuery.Promise.prototype.fail = function(failCallbacks) {}; + +/** + * @deprecated + * @return {boolean} + * @nosideeffects + */ +jQuery.Promise.prototype.isRejected = function() {}; + +/** + * @deprecated + * @return {boolean} + * @nosideeffects + */ +jQuery.Promise.prototype.isResolved = function() {}; + +/** + * @param {function()} doneCallbacks + * @param {function()} failCallbacks + * @return {jQuery.Promise} + */ +jQuery.Promise.prototype.then = function(doneCallbacks, failCallbacks) {}; + +/** + * @param {(string|Object.)} arg1 + * @param {(string|number|boolean|function(number,String))=} arg2 + * @return {(string|!jQuery)} + */ +jQuery.prototype.prop = function(arg1, arg2) {}; + +/** + * @param {...*} var_args + * @return {function()} + */ +jQuery.proxy = function(var_args) {}; + +/** + * @param {...*} var_args + * @return {function()} + */ +$.proxy = function(var_args) {}; + +/** + * @param {Array.} elements + * @param {string=} name + * @param {Array.<*>=} args + * @return {!jQuery} + */ +jQuery.prototype.pushStack = function(elements, name, args) {}; + +/** + * @param {(string|Array.|function(function()))=} queueName + * @param {(Array.|function(function()))=} arg2 + * @return {(Array.|!jQuery)} + */ +jQuery.prototype.queue = function(queueName, arg2) {}; + +/** + * @param {Element} elem + * @param {string=} queueName + * @param {(Array.|function())=} arg3 + * @return {(Array.|!jQuery)} + */ +jQuery.queue = function(elem, queueName, arg3) {}; + +/** + * @param {Element} elem + * @param {string=} queueName + * @param {(Array.|function())=} arg3 + * @return {(Array.|!jQuery)} + */ +$.queue = function(elem, queueName, arg3) {}; + +/** + * @param {function()} handler + * @return {!jQuery} + */ +jQuery.prototype.ready = function(handler) {}; + +/** + * @param {string=} selector + * @return {!jQuery} + */ +jQuery.prototype.remove = function(selector) {}; + +/** + * @param {string} attributeName + * @return {!jQuery} + */ +jQuery.prototype.removeAttr = function(attributeName) {}; + +/** + * @param {(string|function(number,string))=} arg1 + * @return {!jQuery} + */ +jQuery.prototype.removeClass = function(arg1) {}; + +/** + * @param {(string|Array.)=} arg1 + * @return {!jQuery} + */ +jQuery.prototype.removeData = function(arg1) {}; + +/** + * @param {Element} elem + * @param {string=} name + * @return {!jQuery} + */ +jQuery.removeData = function(elem, name) {}; + +/** + * @param {Element} elem + * @param {string=} name + * @return {!jQuery} + */ +$.removeData = function(elem, name) {}; + +/** + * @param {string} propertyName + * @return {!jQuery} + */ +jQuery.prototype.removeProp = function(propertyName) {}; + +/** + * @param {jQuerySelector} target + * @return {!jQuery} + */ +jQuery.prototype.replaceAll = function(target) {}; + +/** + * @param {(string|Element|jQuery|function())} arg1 + * @return {!jQuery} + */ +jQuery.prototype.replaceWith = function(arg1) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.resize = function(arg1, handler) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.scroll = function(arg1, handler) {}; + +/** + * @param {number=} value + * @return {(number|!jQuery)} + */ +jQuery.prototype.scrollLeft = function(value) {}; + +/** + * @param {number=} value + * @return {(number|!jQuery)} + */ +jQuery.prototype.scrollTop = function(value) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.select = function(arg1, handler) {}; + +/** + * @return {string} + * @nosideeffects + */ +jQuery.prototype.serialize = function() {}; + +/** + * @return {Array.>} + * @nosideeffects + */ +jQuery.prototype.serializeArray = function() {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.show = function(duration, arg2, callback) {}; + +/** + * @param {jQuerySelector=} selector + * @return {!jQuery} + * @nosideeffects + */ +jQuery.prototype.siblings = function(selector) {}; + +/** + * @return {number} + * @nosideeffects + */ +jQuery.prototype.size = function() {}; + +/** + * @param {number} start + * @param {number=} end + * @return {!jQuery} + */ +jQuery.prototype.slice = function(start, end) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.slideDown = function(duration, arg2, callback) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.slideToggle = function(duration, arg2, callback) {}; + +/** + * @param {(string|number|function())=} duration + * @param {(function()|string)=} arg2 + * @param {function()=} callback + * @return {!jQuery} + */ +jQuery.prototype.slideUp = function(duration, arg2, callback) {}; + +/** + * @param {(boolean|string)=} arg1 + * @param {boolean=} arg2 + * @param {boolean=} jumpToEnd + * @return {!jQuery} + */ +jQuery.prototype.stop = function(arg1, arg2, jumpToEnd) {}; + +/** + * @deprecated + * @return {!jQuery} + * @nosideeffects + */ +jQuery.sub = function() {}; + +/** + * @deprecated + * @return {!jQuery} + * @nosideeffects + */ +$.sub = function() {}; + +/** + * @param {(function(!jQuery.event=)|Object.)=} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.submit = function(arg1, handler) {}; + +/** @type {Object.} */ +jQuery.support; + +/** @type {Object.} */ +$.support; + +/** @type {boolean} */ +jQuery.support.boxModel; + +/** @type {boolean} */ +$.support.boxModel; + +/** @type {boolean} */ +jQuery.support.changeBubbles; + +/** @type {boolean} */ +$.support.changeBubbles; + +/** @type {boolean} */ +jQuery.support.cssFloat; + +/** @type {boolean} */ +$.support.cssFloat; + +/** @type {boolean} */ +jQuery.support.fixedPosition; + +/** @type {boolean} */ +$.support.fixedPosition; + +/** @type {boolean} */ +jQuery.support.hrefNormalized; + +/** @type {boolean} */ +$.support.hrefNormalized; + +/** @type {boolean} */ +jQuery.support.htmlSerialize; + +/** @type {boolean} */ +$.support.htmlSerialize; + +/** @type {boolean} */ +jQuery.support.leadingWhitespace; + +/** @type {boolean} */ +$.support.leadingWhitespace; + +/** @type {boolean} */ +jQuery.support.noCloneEvent; + +/** @type {boolean} */ +$.support.noCloneEvent; + +/** @type {boolean} */ +jQuery.support.opacity; + +/** @type {boolean} */ +$.support.opacity; + +/** @type {boolean} */ +jQuery.support.scriptEval; + +/** @type {boolean} */ +$.support.scriptEval; + +/** @type {boolean} */ +jQuery.support.style; + +/** @type {boolean} */ +$.support.style; + +/** @type {boolean} */ +jQuery.support.submitBubbles; + +/** @type {boolean} */ +$.support.submitBubbles; + +/** @type {boolean} */ +jQuery.support.tbody; + +/** @type {boolean} */ +$.support.tbody; + +/** + * @param {(string|function(number,string))=} arg1 + * @return {(string|!jQuery)} + */ +jQuery.prototype.text = function(arg1) {}; + +/** + * @return {Array.} + * @nosideeffects + */ +jQuery.prototype.toArray = function() {}; + +/** + * @param {(function(!jQuery.event=)|string|number|function()|boolean)=} arg1 + * @param {(function(!jQuery.event=)|function()|string)=} arg2 + * @param {(function(!jQuery.event=)|function())=} arg3 + * @return {!jQuery} + */ +jQuery.prototype.toggle = function(arg1, arg2, arg3) {}; + +/** + * @param {(string|boolean|function(number,string,boolean))=} arg1 + * @param {boolean=} flag + * @return {!jQuery} + */ +jQuery.prototype.toggleClass = function(arg1, flag) {}; + +/** + * @param {(string|jQuery.event)} arg1 + * @param {...*} var_args + * @return {!jQuery} + */ +jQuery.prototype.trigger = function(arg1, var_args) {}; + +/** + * @param {string} eventType + * @param {Array.<*>=} extraParameters + * @return {*} + */ +jQuery.prototype.triggerHandler = function(eventType, extraParameters) {}; + +/** + * @param {string} str + * @return {string} + * @nosideeffects + */ +jQuery.trim = function(str) {}; + +/** + * @param {string} str + * @return {string} + * @nosideeffects + */ +$.trim = function(str) {}; + +/** + * @param {*} obj + * @return {string} + * @nosideeffects + */ +jQuery.type = function(obj) {}; + +/** + * @param {*} obj + * @return {string} + * @nosideeffects + */ +$.type = function(obj) {}; + +/** + * @param {(string|function(!jQuery.event=)|jQuery.event)=} arg1 + * @param {(function(!jQuery.event=)|boolean)=} arg2 + * @return {!jQuery} + */ +jQuery.prototype.unbind = function(arg1, arg2) {}; + +/** + * @param {string=} arg1 + * @param {(string|Object.)=} arg2 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.undelegate = function(arg1, arg2, handler) {}; + +/** + * @param {Array.} arr + * @return {Array.} + */ +jQuery.unique = function(arr) {}; + +/** + * @param {Array.} arr + * @return {Array.} + */ +$.unique = function(arr) {}; + +/** + * @param {(function(!jQuery.event=)|Object.)} arg1 + * @param {function(!jQuery.event=)=} handler + * @return {!jQuery} + */ +jQuery.prototype.unload = function(arg1, handler) {}; + +/** @return {!jQuery} */ +jQuery.prototype.unwrap = function() {}; + +/** + * @param {(string|Array.|function(number,*))=} arg1 + * @return {(string|number|Array.|!jQuery)} + */ +jQuery.prototype.val = function(arg1) {}; + +/** + * @param {jQuery.deferred} deferred + * @param {...jQuery.deferred} deferreds + * @return {jQuery.Promise} + */ +jQuery.when = function(deferred, deferreds) {}; + +/** + * @param {jQuery.deferred} deferred + * @param {...jQuery.deferred} deferreds + * @return {jQuery.Promise} + */ +$.when = function(deferred, deferreds) {}; + +/** + * @param {(string|number|function(number,number))=} arg1 + * @return {(number|!jQuery)} + */ +jQuery.prototype.width = function(arg1) {}; + +/** + * @param {(string|jQuerySelector|Element|jQuery|function(number))} arg1 + * @return {!jQuery} + */ +jQuery.prototype.wrap = function(arg1) {}; + +/** + * @param {(string|jQuerySelector|Element|jQuery)} wrappingElement + * @return {!jQuery} + */ +jQuery.prototype.wrapAll = function(wrappingElement) {}; + +/** + * @param {(string|function(number))} arg1 + * @return {!jQuery} + */ +jQuery.prototype.wrapInner = function(arg1) {}; diff --git a/web/main.css b/web/main.css new file mode 100644 index 00000000..9fbfc6ed --- /dev/null +++ b/web/main.css @@ -0,0 +1,217 @@ +body { + background: #444; + color: #ddd; + margin: 0; + font-family: sans-serif; + font-size: 12pt; +} + +h1 { + color: #dfd; + margin-left: 40px; + margin-bottom: 5px; +} + +h4 { + margin-left: 20px; + margin-bottom: 5px; +} +select { + margin-left: 10px; + background: #000; + color: #dde; + border: 1px solid #889; + width: 20em; +} +select option { + background: #000; + color: #dde; +} +input[type='text'] { + margin-left: 10px; + background: #003; + color: #dde; + border: 1px solid #88a; +} +input[type='checkbox'] { + margin-left: 10px; +} +input[type='radio'] { + margin-left: 10px; +} +button { + border: 1px solid #004; + background: #889; + font-weight: bold; + margin-left: 10px; + display: block; +} +button[disabled=true] { + color: #888; +} +div.dropbg { + position: fixed; + width: 100%; + height: 100%; + top: 0px; + left: 0px; + background: #004; + opacity: 0.6; + z-index: 1000; +} +div.dropbg.hover { + background: #008; +} +div.dropmsg { + position: fixed; + width: 100%; + height: 100%; + top: 40%; + left: 0px; + color: #ccd; + font-weight: bold; + text-align: center; + vertical-align: middle; + font-size: 24pt; + z-index: 1001; +} +div.dropmsg div { + color: #caa; + font-weight: bold; + text-decoration: none; + font-size: 12pt; +} +div.dropbox { + position: fixed; + width: 100%; + height: 100%; + top: 0px; + left: 0px; + z-index: 1002; +} +div.dialogbg { + position: fixed; + width: 100%; + height: 100%; + top: 0px; + left: 0px; + background: #404; + opacity: 0.6; + z-index: 1000; +} +div.dialog { + position: fixed; + width: 50%; + top: 25%; + left: 25%; + background: #444; + border: 1px solid #222; + border-radius: 10px; + color: #eee; + z-index: 1001; +} +div.dialog div.buttons { + border-top: 1px solid #222; + padding-right: 10px; + background: #888; + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; +} +div.dialog div.buttons button { + float: right; +} +div.dialog dl { + margin-left: 10px; +} +div.picker { + position: absolute; + width: 420px; + z-index: 100000; + background: #222; + border: 1px solid #eef; +} +div.picker canvas { + margin: 5px; +} +div.swatch { + width: 80px; + height: 40px; + margin-top: 20px; + margin-left: 10px; + margin-bottom: 20px; + border: 1px solid #eef; + background: #000; + float: left +} +input.hexcolor { + float: left; + width: 80px; + margin-top: 30px; + font-family: monospace; +} +div.colorlabel { + width: 30px; + float: left; + clear: left; + margin-top: 2px; + text-align: right; +} +input.colorinput { + width: 40px; + float: left; + margin-left: 5px; + font-family: monospace; +} +table { + margin-left: 10px; +} +th { + text-align: right; + font-weight: normal; +} +td + td { + color: #cac; +} +tr.variant td { + font-size: 0.8em; + text-align: right; +} +tr.variant td + td { + text-align: left; + color: #aac; +} +a { + text-decoration: none; + color: #aac; + font-weight: bold; +} +div.buttonbar { + width: 50%; + background: #668; + border: 1px solid #444; + z-index: 100; + position: relative; + top: 0; + left: 0; +} +div.color { + width: 20px; + height: 20px; + background: #000; + border: 1px solid #eee; +} +div.droptarget { + background: #222; + border: 1px solid #aac; + padding: 10px; + margin: 10px; + color: #aac; + text-align: center; +} +div.droptarget.active { + background: #228; +} +label.checked { + font-weight: bold; + color: #ece; +} diff --git a/web/mods.js b/web/mods.js new file mode 100644 index 00000000..8f463048 --- /dev/null +++ b/web/mods.js @@ -0,0 +1,1002 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/** + * @constructor + * @param {Function} updatecb + * @param {Display} display + */ +function Mods(updatecb,display) +{ + /** @type {Object.} */ + var mods={}; + this.mods=mods; + /** @type {Array.} */ + var packs=[]; + this.packs=packs; + /** @type {Object.} */ + var locals={} + this.locals=locals; + /** @type {Array.} */ + var localPacks=[]; + this.localPacks=localPacks; + + /** @type {number} */ + var loading=1; + + $.getJSON("mods/mods.json",function(m) { + loading+=m.length; + for (var i=0;i0) + { + mod['configs']=[]; + for (var i=0;ibuttonTop) + buttons.css({'position':'fixed'}); + else + buttons.css({'position':'relative'}); + }); + + + function makeBlockData() + { + var tbl=[]; + for (var i=0;i>16)+','+((curC>>8)&0xff)+','+(curC&0xff)+')'); + color.click(function(){ + pickColor(color,curC,function(c){ + curC=c; + color.css('background','rgb('+(c>>16)+','+((c>>8)&0xff)+','+(c&0xff)+')'); + }); + }); + var alp=100; + if (idx!=-1) + { + if (mod['data'][idx]['color']===undefined) + alp=0; + else if (mod['data'][idx]['alpha']!==undefined) + alp=Math.round(100*mod['data'][idx]['alpha']); + } + var alpha=display.toDOM({'input':null,'type':'text','size':'4', + 'val':String(alp)}); + var flags=[ + display.toDOM({'input':null,'type':'checkbox','val':1}), + display.toDOM({'input':null,'type':'checkbox','val':2}), + display.toDOM({'input':null,'type':'checkbox','val':4}) + ]; + if (idx!=-1) + for (var i=0;i>16)+','+((curC>>8)&0xff)+','+(curC&0xff)+')'}}); + color.click(function(){ + pickColor(color,curC,function(c){ + curC=c; + color.css('background','rgb('+(c>>16)+','+((c>>8)&0xff)+','+(c&0xff)+')'); + }); + }); + dialog.draw([ + {'dl':[ + {'dt':'Damage:'}, + {'dd':dtxt}, + {'dt':'Name:'}, + {'dd':nmtxt}, + {'dt':'Color:'}, + {'dd':color} + ]} + ]); + dtxt.focus(); + function editResponse(btnidx) + { + if (btnidx==0) //save + { + if ($.isNumeric(dtxt.val())) + { + if (mod['data'][idx]['variants']===undefined) + mod['data'][idx]['variants']=[]; + if (v==-1) + { + v=mod['data'][idx]['variants'].length; + mod['data'][idx]['variants'][v]={}; + } + mod['data'][idx]['variants'][v]['data']=parseInt(dtxt.val(),10); + var nm=nmtxt.val().trim(); + if (nm!==mod['data'][idx]['name'] && nm!='') + mod['data'][idx]['variants'][v]['name']=nm; + else + delete mod['data'][idx]['variants'][v]['name']; + var c=curC.toString(16); + while (c.length<6) + c='0'+c; + if (mod['data'][idx]['color']==undefined || + c!==mod['data'][idx]['color']) + mod['data'][idx]['variants'][v]['color']=c; + else + delete mod['data'][idx]['variants'][v]['color']; + sortMod(); + refresh(); + } + } + } + } + function deleteVariant(idx,v) + { + if (confirm("Are you sure you wish to delete this variant?")) + { + mod['data'][idx]['variants'].splice(v,1); + if (mod['data'][idx]['variants'].length==0) + delete mod['data'][idx]['variants']; + refresh(); + } + } + function makeBiomeData() + { + var tbl=[]; + for (var i=0;ib['config']?1:-1; + }); + for (var i=0;ibuttonTop) + buttons.css({'position':'fixed'}); + else + buttons.css({'position':'relative'}); + }); + + var allmods; + function makePackData() + { + var tbl=[]; + allmods=[]; + for (var m in mods) + allmods.push({'type':'pre','id':m,'checked':false}); + for (var m in locals) + allmods.push({'type':'local','id':m,'checked':false}); + allmods.sort(function(a,b) { + if (a['type']==b['type']) + { + if (a['id']==b['id']) + return 0; + return a['id']>b['id']?1:-1; + } + return a['type']=='pre'?1:-1; + }); + for (var i=0;i} files + * @returns {Uint8Array} + */ +function Zip(files) +{ + var crctable=[]; + for (var i=0;i<256;i++) + { + var c=i; + for (var j=0;j<8;j++) + if (c&1) + c=(c>>>1)^0xedb88320; + else + c=(c>>>1); + crctable[i]=c; + } + function crc32(msg) + { + var c=-1; + for (var i=0;i>>8)^crctable[(c^msg.charCodeAt(i))&0xff]; + return ~c; + } + + var date=new Date(); + var dosdate=((date.getFullYear()-1980)<<9)|((date.getMonth()+1)<<5)|date.getDate(); + var crcs=[]; + var data=[]; + + var offset=0; + //local files + for (var i=0;i>8)&0xff; + //crc32 + crcs[i]=crc32(files[i].file); + data[offset++]=crcs[i]&0xff; data[offset++]=(crcs[i]>>8)&0xff; + data[offset++]=(crcs[i]>>16)&0xff; data[offset++]=(crcs[i]>>24)&0xff; + //compressed size + var size=files[i].file.length; + data[offset++]=size&0xff; data[offset++]=(size>>8)&0xff; + data[offset++]=(size>>16)&0xff; data[offset++]=(size>>24)&0xff; + //uncompressed size + data[offset++]=size&0xff; data[offset++]=(size>>8)&0xff; + data[offset++]=(size>>16)&0xff; data[offset++]=(size>>24)&0xff; + //file name length + data[offset++]=files[i].name.length; data[offset++]=0; + //extra field length + data[offset++]=0; data[offset++]=0; + //file name + for (var j=0;j>8)&0xff; + //crc-32 + data[offset++]=crcs[i]&0xff; data[offset++]=(crcs[i]>>8)&0xff; + data[offset++]=(crcs[i]>>16)&0xff; data[offset++]=(crcs[i]>>24)&0xff; + //compressed size + var size=files[i].file.length; + data[offset++]=size&0xff; data[offset++]=(size>>8)&0xff; + data[offset++]=(size>>16)&0xff; data[offset++]=(size>>24)&0xff; + //uncompressed size + data[offset++]=size&0xff; data[offset++]=(size>>8)&0xff; + data[offset++]=(size>>16)&0xff; data[offset++]=(size>>24)&0xff; + //file name length + data[offset++]=files[i].name.length; data[offset++]=0; + //extra field length + data[offset++]=0; data[offset++]=0; + //file comment length + data[offset++]=0; data[offset++]=0; + //disk number start + data[offset++]=0; data[offset++]=0; + //internal file attributes + data[offset++]=0; data[offset++]=0; + //external file attributes + data[offset++]=0; data[offset++]=0; + data[offset++]=0; data[offset++]=0; + //relative offset of local header + var ofs=files[i].offset; + data[offset++]=ofs&0xff; data[offset++]=(ofs>>8)&0xff; + data[offset++]=(ofs>>16)&0xff; data[offset++]=(ofs>>24)&0xff; + //filename + for (var j=0;j>8)&0xff; + //number of entries on all disks + data[offset++]=num&0xff; data[offset++]=(num>>8)&0xff; + //size of central directory + data[offset++]=cdlen&0xff; data[offset++]=(cdlen>>8)&0xff; + data[offset++]=(cdlen>>16)&0xff; data[offset++]=(cdlen>>24)&0xff; + //central directory start offset + data[offset++]=cdstart&0xff; data[offset++]=(cdstart>>8)&0xff; + data[offset++]=(cdstart>>16)&0xff; data[offset++]=(cdstart>>24)&0xff; + //comment length + data[offset++]=0; data[offset++]=0; + //zip comment is blank + + return new Uint8Array(data); +} diff --git a/MinutorMap/zconf.h b/zconf.h similarity index 73% rename from MinutorMap/zconf.h rename to zconf.h index 02ce56c4..8a46a58b 100644 --- a/MinutorMap/zconf.h +++ b/zconf.h @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2010 Jean-loup Gailly. + * Copyright (C) 1995-2012 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -15,6 +15,7 @@ * this permanently in zconf.h using "./configure --zprefix". */ #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET /* all linked symbols */ # define _dist_code z__dist_code @@ -27,9 +28,11 @@ # define adler32 z_adler32 # define adler32_combine z_adler32_combine # define adler32_combine64 z_adler32_combine64 -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif # define crc32 z_crc32 # define crc32_combine z_crc32_combine # define crc32_combine64 z_crc32_combine64 @@ -40,44 +43,52 @@ # define deflateInit2_ z_deflateInit2_ # define deflateInit_ z_deflateInit_ # define deflateParams z_deflateParams +# define deflatePending z_deflatePending # define deflatePrime z_deflatePrime # define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep # define deflateSetDictionary z_deflateSetDictionary # define deflateSetHeader z_deflateSetHeader # define deflateTune z_deflateTune # define deflate_copyright z_deflate_copyright # define get_crc_table z_get_crc_table -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# define gzprintf z_gzprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzwrite z_gzwrite +# endif # define inflate z_inflate # define inflateBack z_inflateBack # define inflateBackEnd z_inflateBackEnd @@ -95,13 +106,18 @@ # define inflateSync z_inflateSync # define inflateSyncPoint z_inflateSyncPoint # define inflateUndermine z_inflateUndermine +# define inflateResetKeep z_inflateResetKeep # define inflate_copyright z_inflate_copyright # define inflate_fast z_inflate_fast # define inflate_table z_inflate_table -# define uncompress z_uncompress +# ifndef Z_SOLO +# define uncompress z_uncompress +# endif # define zError z_zError -# define zcalloc z_zcalloc -# define zcfree z_zcfree +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif # define zlibCompileFlags z_zlibCompileFlags # define zlibVersion z_zlibVersion @@ -111,7 +127,9 @@ # define alloc_func z_alloc_func # define charf z_charf # define free_func z_free_func -# define gzFile z_gzFile +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif # define gz_header z_gz_header # define gz_headerp z_gz_headerp # define in_func z_in_func @@ -197,6 +215,12 @@ # endif #endif +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + /* Some Mac compilers merge all .h files incorrectly: */ #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) # define NO_DUMMY_DECL @@ -243,6 +267,14 @@ # endif #endif +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -356,12 +388,45 @@ typedef uLong FAR uLongf; typedef Byte *voidp; #endif +/* ./configure may #define Z_U4 here */ + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# else +# if (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# else +# if (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +# endif +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ # define Z_HAVE_UNISTD_H #endif +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + #ifdef STDC -# include /* for off_t */ +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#ifdef _WIN32 +# include /* for wchar_t */ #endif /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and @@ -370,21 +435,38 @@ typedef uLong FAR uLongf; * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as * equivalently requesting no 64-bit operations */ -#if -_LARGEFILE64_SOURCE - -1 == 1 +#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 # undef _LARGEFILE64_SOURCE #endif -#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) -# include /* for SEEK_* and off_t */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif # endif #endif -#ifndef SEEK_SET +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) # define SEEK_SET 0 /* Seek from beginning of file. */ # define SEEK_CUR 1 /* Seek from current position. */ # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ @@ -394,18 +476,14 @@ typedef uLong FAR uLongf; # define z_off_t long #endif -#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +#if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# define z_off64_t z_off_t -#endif - -#if defined(__OS400__) -# define NO_vsnprintf -#endif - -#if defined(__MVS__) -# define NO_vsnprintf +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif #endif /* MVS linker does not support external names larger than 8 bytes */ diff --git a/zipreader.cpp b/zipreader.cpp new file mode 100644 index 00000000..d861baf8 --- /dev/null +++ b/zipreader.cpp @@ -0,0 +1,145 @@ +/* + Copyright (c) 2013, Sean Kasun + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "zipreader.h" +#include "zlib.h" + +ZipReader::ZipReader(const QString filename) : f(filename) +{ +} + +bool ZipReader::open() +{ + if (!f.open(QIODevice::ReadOnly)) + return false; + + //locate end of central directory record + qint64 ziplen=f.size(); + qint64 maxECDlen=0xffff+22; //max comment len + ECD + if (maxECDlen>ziplen) //zip is shorter? + maxECDlen=ziplen; + + f.seek(ziplen-maxECDlen); //ECD must be after this + + QByteArray data=f.read(maxECDlen); + const quint8 *p=(const quint8 *)data.constData(); + + bool found=false; + //now scan this data for the ECD signature + for (qint64 i=0;i +#include +#include +#include + +struct ZipFileHeader +{ + qint32 compressed,uncompressed; + qint16 compression; + qint64 offset; +}; + +class ZipReader +{ +public: + ZipReader(const QString filename); + bool open(); + void close(); + QByteArray get(const QString filename); +private: + QFile f; + QHash files; +}; + +#endif diff --git a/MinutorMap/zlib.h b/zlib.h similarity index 85% rename from MinutorMap/zlib.h rename to zlib.h index bfbba83e..3edf3acd 100644 --- a/MinutorMap/zlib.h +++ b/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.5, April 19th, 2010 + version 1.2.7, May 2nd, 2012 - Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -24,8 +24,8 @@ The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). */ #ifndef ZLIB_H @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.5" -#define ZLIB_VERNUM 0x1250 +#define ZLIB_VERSION "1.2.7" +#define ZLIB_VERNUM 0x1270 #define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 5 +#define ZLIB_VER_REVISION 7 #define ZLIB_VER_SUBREVISION 0 /* @@ -83,15 +83,15 @@ typedef void (*free_func) OF((voidpf opaque, voidpf address)); struct internal_state; typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ + z_const Bytef *next_in; /* next input byte */ uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ + uLong total_in; /* total number of input bytes read so far */ Bytef *next_out; /* next output byte should be put there */ uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ + uLong total_out; /* total number of bytes output so far */ - char *msg; /* last error message, NULL if no error */ + z_const char *msg; /* last error message, NULL if no error */ struct internal_state FAR *state; /* not visible by applications */ alloc_func zalloc; /* used to allocate the internal state */ @@ -327,8 +327,9 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); Z_FINISH can be used immediately after deflateInit if all the compression is to be done in a single step. In this case, avail_out must be at least the - value returned by deflateBound (see below). If deflate does not return - Z_STREAM_END, then it must be called again as described above. + value returned by deflateBound (see below). Then deflate is guaranteed to + return Z_STREAM_END. If not enough output space is provided, deflate will + not return Z_STREAM_END, and it must be called again as described above. deflate() sets strm->adler to the adler32 checksum of all input read so far (that is, total_in bytes). @@ -451,23 +452,29 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); error. However if all decompression is to be performed in a single step (a single call of inflate), the parameter flush should be set to Z_FINISH. In this case all pending input is processed and all pending output is flushed; - avail_out must be large enough to hold all the uncompressed data. (The size - of the uncompressed data may have been saved by the compressor for this - purpose.) The next operation on this stream must be inflateEnd to deallocate - the decompression state. The use of Z_FINISH is never required, but can be - used to inform inflate that a faster approach may be used for the single - inflate() call. + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. In this implementation, inflate() always flushes as much output as possible to the output buffer, and always uses the faster approach on the - first call. So the only effect of the flush parameter in this implementation - is on the return value of inflate(), as noted below, or when it returns early - because Z_BLOCK or Z_TREES is used. + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm->adler to the adler32 checksum of the dictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the adler32 checksum of all output produced so far (that is, + strm->adler to the Adler-32 checksum of all output produced so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described below. At the end of the stream, inflate() checks that its computed adler32 checksum is equal to that saved by the compressor and returns Z_STREAM_END @@ -478,7 +485,9 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); initializing with inflateInit2(). Any information contained in the gzip header is not retained, so applications that need that information should instead use raw inflate, see inflateInit2() below, or inflateBack() and - perform their own processing of the gzip header and trailer. + perform their own processing of the gzip header and trailer. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + producted so far. The CRC-32 is checked against the gzip trailer. inflate() returns Z_OK if some progress has been made (more input processed or more output produced), Z_STREAM_END if the end of the compressed data has @@ -580,10 +589,15 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, uInt dictLength)); /* Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any call - of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed, with the most commonly @@ -610,8 +624,8 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). */ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, @@ -688,8 +702,28 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, deflation of sourceLen bytes. It must be called after deflateInit() or deflateInit2(), and after deflateSetHeader(), if used. This would be used to allocate an output buffer for deflation in a single pass, and so would be - called before deflate(). -*/ + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, int bits, @@ -703,8 +737,9 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, than or equal to 16, and that many of the least significant bits of value will be inserted in the output. - deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. */ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, @@ -790,10 +825,11 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, if that call returned Z_NEED_DICT. The dictionary chosen by the compressor can be determined from the adler32 value returned by that call of inflate. The compressor and decompressor must use exactly the same dictionary (see - deflateSetDictionary). For raw inflate, this function can be called - immediately after inflateInit2() or inflateReset() and before any call of - inflate() to set the dictionary. The application must insure that the - dictionary that was used for compression is provided. + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is @@ -805,17 +841,21 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); /* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all available input is skipped. No output is provided. - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been - found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the - success case, the application may save the current current value of total_in - which indicates where valid compressed data was found. In the error case, - the application may repeatedly call inflateSync, providing more input each - time, until success or end of the input data. + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. */ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, @@ -962,7 +1002,7 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, See inflateBack() for the usage of these routines. inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the paramaters are invalid, Z_MEM_ERROR if the internal state could not be + the parameters are invalid, Z_MEM_ERROR if the internal state could not be allocated, or Z_VERSION_ERROR if the version of the library does not match the version of the header file. */ @@ -1088,6 +1128,7 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 27-31: 0 (reserved) */ +#ifndef Z_SOLO /* utility functions */ @@ -1149,10 +1190,11 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. */ - /* gzip file access functions */ /* @@ -1162,7 +1204,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, wrapper, documented in RFC 1952, wrapped around a deflate stream. */ -typedef voidp gzFile; /* opaque gzip file descriptor */ +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); @@ -1172,13 +1214,28 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' for fixed code compression as in "wb9F". (See the description of - deflateInit2 for more information about the strategy parameter.) Also "a" - can be used instead of "w" to request that the gzip stream that will be - written be appended to the file. "+" will result in an error, since reading - and writing to the same gzip file is not supported. + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. gzopen returns NULL if the file could not be opened, if there was insufficient memory to allocate the gzFile state, or if an invalid mode was @@ -1197,7 +1254,11 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, mode);. The duplicated descriptor should be saved to avoid a leak, since - gzdopen does not close fd if it fails. + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. gzdopen returns NULL if there was insufficient memory to allocate the gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not @@ -1235,14 +1296,26 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); /* Reads the given number of uncompressed bytes from the compressed file. If - the input file was not in gzip format, gzread copies the given number of - bytes into the buffer. + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. After reaching the end of a gzip stream in the input, gzread will continue - to read, looking for another gzip stream, or failing that, reading the rest - of the input file directly without decompression. The entire input file - will be read if gzread is called until it returns less than the requested - len. + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. gzread returns the number of uncompressed bytes actually read, less than len for end of file, or -1 for error. @@ -1256,7 +1329,7 @@ ZEXTERN int ZEXPORT gzwrite OF((gzFile file, error. */ -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); /* Converts, formats, and writes the arguments to the compressed file under control of the format string, as in fprintf. gzprintf returns the number of @@ -1301,7 +1374,10 @@ ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); /* Reads one byte from the compressed file. gzgetc returns this byte or -1 - in case of end of file or error. + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. */ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); @@ -1397,9 +1473,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); /* Returns true (1) if file is being copied directly while reading, or false - (0) if file is a gzip stream being decompressed. This state can change from - false to true while reading the input file if the end of a gzip stream is - reached, but is followed by data that is not another gzip stream. + (0) if file is a gzip stream being decompressed. If the input file is empty, gzdirect() will return true, since the input does not contain a gzip stream. @@ -1408,6 +1482,13 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); cause buffers to be allocated to allow reading the file to determine if it is a gzip file. Therefore if gzbuffer() is used, it should be called before gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) */ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); @@ -1419,7 +1500,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); must not be called more than once on the same allocation. gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a - file operation error, or Z_OK on success. + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. */ ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); @@ -1457,6 +1539,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); file that is being written concurrently. */ +#endif /* !Z_SOLO */ /* checksum functions */ @@ -1492,16 +1575,17 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of - seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. */ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. If buf is Z_NULL, this function returns the required - initial value for the for the crc. Pre- and post-conditioning (one's - complement) is performed within this function so it shouldn't be done by the - application. + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. Usage example: @@ -1544,17 +1628,42 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, const char *version, int stream_size)); #define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) #define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, sizeof(z_stream)) + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) #define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) #define inflateBackInit(strm, windowBits, window) \ inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, sizeof(z_stream)) + ZLIB_VERSION, (int)sizeof(z_stream)) + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +#ifdef Z_PREFIX_SET +# undef z_gzgetc +# define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#else +# define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) +#endif /* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if @@ -1562,7 +1671,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, * functions are changed to 64 bits) -- in case these are set on systems * without large file support, _LFS64_LARGEFILE must also be true */ -#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 +#ifdef Z_LARGE64 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); @@ -1571,14 +1680,23 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); #endif -#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 -# define gzopen gzopen64 -# define gzseek gzseek64 -# define gztell gztell64 -# define gzoffset gzoffset64 -# define adler32_combine adler32_combine64 -# define crc32_combine crc32_combine64 -# ifdef _LARGEFILE64_SOURCE +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef Z_LARGE64 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); @@ -1595,6 +1713,13 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); #endif +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + /* hack for buggy compilers */ #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) struct internal_state {int dummy;}; @@ -1603,8 +1728,14 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, /* undocumented functions */ ZEXTERN const char * ZEXPORT zError OF((int)); ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#if defined(_WIN32) && !defined(Z_SOLO) +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, + const char *mode)); +#endif #ifdef __cplusplus } diff --git a/zlibstat.lib b/zlibstat.lib new file mode 100644 index 00000000..d814218c Binary files /dev/null and b/zlibstat.lib differ