Beispiel #1
0
    def _quit(self, command):
        """
    quit [ yes | no ]
    
    Quits the program. 
    Without 'yes' or 'no', prompts to save before quitting. 
    
    In batch mode, an end of file automatically saves the level.
    """
        if len(command) == 0 or not (command[0].lower() in ("yes", "no")): 
            imp = winput("Save before exit? ").lower();
            if imp[-1:] == '\r':
                        imp = imp[:-1]
            if imp in ("yes", "y", "1", "true"):
                self._save(command);
                raise SystemExit;
        if len(command) and command[0].lower == "yes":
            self._save(command);

        raise SystemExit
Beispiel #2
0
    def _quit(self, command):
        """
    quit [ yes | no ]
    
    Quits the program. 
    Without 'yes' or 'no', prompts to save before quitting. 
    
    In batch mode, an end of file automatically saves the level.
    """
        if len(command) == 0 or not (command[0].lower() in ("yes", "no")):
            imp = winput("Save before exit? ").lower()
            if imp[-1:] == '\r':
                imp = imp[:-1]
            if imp in ("yes", "y", "1", "true"):
                self._save(command)
                raise SystemExit
        if len(command) and command[0].lower == "yes":
            self._save(command)

        raise SystemExit
Beispiel #3
0
 def run(self):
     logging.basicConfig(format='%(levelname)s:%(message)s')
     logging.getLogger().level = logging.INFO
 
     appPath = sys.argv.pop(0)
     
     if len(sys.argv):
         world = sys.argv.pop(0)
         
         if world.lower() in ("-h", "--help"):
             self.printUsageAndQuit()
             
         if len(sys.argv) and sys.argv[0].lower() == "create":
             #accept the syntax, "mce world3 create"
             self._create([world]);
             print("Created world {0}".format(world));
             
             sys.exit(0)
         else:
             self.loadWorld(world)
     else:
         self.batchMode = True;
         self.printUsage();
         
         while True:
             try:
                 world = str(winput("Please enter world name or path to world folder: "))
                 if world[-1:] == '\r':
                     world = world[:-1]
                 self.loadWorld(world)
             except EOFError as e:
                 print("End of input.")
                 raise SystemExit;
             except Exception as e:
                 print("Cannot open {0}: {1}".format(world, e));
             else:
                 break;
     
     
     
         
     if len(sys.argv):
         #process one command from command line
         try:
             self.processCommand(" ".join(sys.argv))
         except UsageError:
             self.printUsageAndQuit();
         self._save([]);
         
     else:
         #process many commands on standard input, maybe interactively
         command = [""]
         self.batchMode = True;
         while True:
             try:
                 command = str(winput("{0}> ".format(self.level.displayName)))
                 if command[-1:] == '\r':
                     command = command[:-1]
                 wprint2()
                 self.processCommand(command)
                 
             except EOFError as e:
                 print("End of file. Saving automatically.")
                 self._save([]);
                 raise SystemExit;
             except Exception as e:
                 if self.debug:
                     traceback.print_exc();
                 print('Exception during command: {0!r}'.format(e));
                 print("Use 'debug' to enable tracebacks.")
Beispiel #4
0
    def _heightmap(self,command):
        """
    heightmap <filename>

    Takes a png and imports it as the terrain starting at chunk 0,0.
    Data is internally converted to greyscale and scaled to the maximum height.
    The game will fill the terrain with trees and mineral deposits the next
    time you play the level.

    Please please please try out a small test image before using a big source.
    Using the levels tool to get a good heightmap is an art, not a science.
    A smaller map lets you experiment and get it right before having to blow
    all night generating the really big map.

    Requires the PIL library.
    """
        if len(command) == 0:
            self.printUsage("heightmap")
            return

        cont=0
        imp=""
        if not sys.stdin.isatty():
            cont=1
        else:
            imp = winput("This will destroy a large portion of the map and may take a long time.  Did you really want to do this?").lower()
            if imp[-1:] == '\r':
                imp = imp[:-1]

        if cont == 1 or imp in ("yes", "y", "1", "true"):
         
            
            from PIL import Image
            import datetime

            filename = command.pop(0)

            imgobj = Image.open(filename)
            
            greyimg = imgobj.convert("L") #luminance
            del imgobj
            
            width, height = greyimg.size
            
            water_level = 64  
            
            xchunks = int((height+15)/16)
            zchunks = int((width+15)/16)

            start = datetime.datetime.now()
            for cx in range(xchunks):
                for cz in range(zchunks):
                    try:
                        self.level.createChunk(cx,cz)
                    except:
                        pass
                    c = self.level.getChunk(cx,cz)
                    
                    imgarray = numpy.asarray(greyimg.crop( (cz*16, cx*16, cz*16+16, cx*16+16) ))
                    imgarray = imgarray / 2; #scale to 0-127
                
                    for x in range(16):
                        for z in range(16):
                            if z+(cz*16) < width-1 and x+(cx*16) < height-1:
                                #world dimension X goes north-south
                                #first array axis goes up-down
                                
                                h = imgarray[x,z]
                                
                                c.Blocks[x,z,h+1:] = 0 #air
                                c.Blocks[x,z,h:h+1] = 2 #grass
                                c.Blocks[x,z,h-4:h] = 3 #dirt
                                c.Blocks[x,z,:h-4] = 1 #rock

                                if h < water_level:
                                    c.Blocks[x,z,h+1:water_level] = 9 #water
                                if h < water_level+2:
                                    c.Blocks[x,z,h-2:h+1] = 12 #sand if it's near water level
                                    
                                c.Blocks[x,z,0] = 7 #bedrock
                                
                    c.chunkChanged()
                    c.TerrainPopulated = False
                    #the quick lighting from chunkChanged has already lit this simple terrain completely
                    c.needsLighting = False 
                    
                    logging.info( "%s Just did chunk %d,%d" % (datetime.datetime.now().strftime("[%H:%M:%S]"),cx,cz) )

            logging.info( "Done with mapping!" )
            self.needsSave = True;
            stop = datetime.datetime.now()
            logging.info( "Took %s." % str(stop-start) )
            
            spawnz = width / 2
            spawnx = height / 2;
            spawny = greyimg.getpixel((spawnx, spawnz))
            logging.info( "You probably want to change your spawn point. I suggest {0}".format( (spawnx, spawny, spawnz) ) )
Beispiel #5
0
    def run(self):
        logging.basicConfig(format='%(levelname)s:%(message)s')
        logging.getLogger().level = logging.INFO

        appPath = sys.argv.pop(0)

        if len(sys.argv):
            world = sys.argv.pop(0)

            if world.lower() in ("-h", "--help"):
                self.printUsageAndQuit()

            if len(sys.argv) and sys.argv[0].lower() == "create":
                #accept the syntax, "mce world3 create"
                self._create([world])
                print("Created world {0}".format(world))

                sys.exit(0)
            else:
                self.loadWorld(world)
        else:
            self.batchMode = True
            self.printUsage()

            while True:
                try:
                    world = str(
                        winput(
                            "Please enter world name or path to world folder: "
                        ))
                    if world[-1:] == '\r':
                        world = world[:-1]
                    self.loadWorld(world)
                except EOFError as e:
                    print("End of input.")
                    raise SystemExit
                except Exception as e:
                    print("Cannot open {0}: {1}".format(world, e))
                else:
                    break

        if len(sys.argv):
            #process one command from command line
            try:
                self.processCommand(" ".join(sys.argv))
            except UsageError:
                self.printUsageAndQuit()
            self._save([])

        else:
            #process many commands on standard input, maybe interactively
            command = [""]
            self.batchMode = True
            while True:
                try:
                    command = str(
                        winput("{0}> ".format(self.level.displayName)))
                    if command[-1:] == '\r':
                        command = command[:-1]
                    wprint2()
                    self.processCommand(command)

                except EOFError as e:
                    print("End of file. Saving automatically.")
                    self._save([])
                    raise SystemExit
                except Exception as e:
                    if self.debug:
                        traceback.print_exc()
                    print('Exception during command: {0!r}'.format(e))
                    print("Use 'debug' to enable tracebacks.")
Beispiel #6
0
    def _heightmap(self, command):
        """
    heightmap <filename>

    Takes a png and imports it as the terrain starting at chunk 0,0.
    Data is internally converted to greyscale and scaled to the maximum height.
    The game will fill the terrain with trees and mineral deposits the next
    time you play the level.

    Please please please try out a small test image before using a big source.
    Using the levels tool to get a good heightmap is an art, not a science.
    A smaller map lets you experiment and get it right before having to blow
    all night generating the really big map.

    Requires the PIL library.
    """
        if len(command) == 0:
            self.printUsage("heightmap")
            return

        cont = 0
        imp = ""
        if not sys.stdin.isatty():
            cont = 1
        else:
            imp = winput(
                "This will destroy a large portion of the map and may take a long time.  Did you really want to do this?"
            ).lower()
            if imp[-1:] == '\r':
                imp = imp[:-1]

        if cont == 1 or imp in ("yes", "y", "1", "true"):

            from PIL import Image
            import datetime

            filename = command.pop(0)

            imgobj = Image.open(filename)

            greyimg = imgobj.convert("L")  #luminance
            del imgobj

            width, height = greyimg.size

            water_level = 64

            xchunks = int((height + 15) / 16)
            zchunks = int((width + 15) / 16)

            start = datetime.datetime.now()
            for cx in range(xchunks):
                for cz in range(zchunks):
                    try:
                        self.level.createChunk(cx, cz)
                    except:
                        pass
                    c = self.level.getChunk(cx, cz)

                    imgarray = numpy.asarray(
                        greyimg.crop(
                            (cz * 16, cx * 16, cz * 16 + 16, cx * 16 + 16)))
                    imgarray = imgarray / 2
                    #scale to 0-127

                    for x in range(16):
                        for z in range(16):
                            if z + (cz * 16) < width - 1 and x + (
                                    cx * 16) < height - 1:
                                #world dimension X goes north-south
                                #first array axis goes up-down

                                h = imgarray[x, z]

                                c.Blocks[x, z, h + 1:] = 0  #air
                                c.Blocks[x, z, h:h + 1] = 2  #grass
                                c.Blocks[x, z, h - 4:h] = 3  #dirt
                                c.Blocks[x, z, :h - 4] = 1  #rock

                                if h < water_level:
                                    c.Blocks[x, z,
                                             h + 1:water_level] = 9  #water
                                if h < water_level + 2:
                                    c.Blocks[
                                        x, z, h - 2:h +
                                        1] = 12  #sand if it's near water level

                                c.Blocks[x, z, 0] = 7  #bedrock

                    c.chunkChanged()
                    c.TerrainPopulated = False
                    #the quick lighting from chunkChanged has already lit this simple terrain completely
                    c.needsLighting = False

                    logging.info(
                        "%s Just did chunk %d,%d" %
                        (datetime.datetime.now().strftime("[%H:%M:%S]"), cx,
                         cz))

            logging.info("Done with mapping!")
            self.needsSave = True
            stop = datetime.datetime.now()
            logging.info("Took %s." % str(stop - start))

            spawnz = width / 2
            spawnx = height / 2
            spawny = greyimg.getpixel((spawnx, spawnz))
            logging.info(
                "You probably want to change your spawn point. I suggest {0}".
                format((spawnx, spawny, spawnz)))