Changeset 11928 for lang/d

Show
Ignore:
Timestamp:
05/18/08 21:39:24 (6 months ago)
Author:
omega
Message:

save/load実装

Location:
lang/d/koke/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • lang/d/koke/trunk/boot.d

    r11602 r11928  
    2828const char[] g_title = "hoge";          // タイトルバー 
    2929 
     30enum BOOTMODE{ 
     31        NORMAL, 
     32        SCREENSAVER, 
     33} 
     34private BOOTMODE g_bootmode = BOOTMODE.NORMAL; 
     35bool isScreenSaver() {return g_bootmode == BOOTMODE.SCREENSAVER;} 
    3036 
    3137/* Hell_main ********************************************************************/ 
     
    4248        int g_width = 640; 
    4349        int g_height = 480; 
     50        g_bootmode = BOOTMODE.NORMAL; 
    4451        foreach(int t,string buf;args) 
    4552        { 
    46                 if(buf == "/s" || buf == "/S") is_fullscreen = true;    // スクリーンセーバとして起動 
     53                if(buf == "/s" || buf == "/S"){ 
     54                        // スクリーンセーバとして起動 
     55                        is_fullscreen = true; 
     56                        g_bootmode = BOOTMODE.SCREENSAVER; 
     57                } 
    4758                if(buf == "-window") is_fullscreen = false; 
    4859                if(buf == "-fullscreen") is_fullscreen = true; 
  • lang/d/koke/trunk/clickable.d

    r11613 r11928  
    3737                ECONOMY,                // エコノミー 
    3838                CHART,                  // チャート 
     39                SAVE,                   // SAVE 
     40                LOAD,                   // LOAD 
    3941                 
    4042                STOP,                   // 停止 
     
    4951                MIN,    // 極小 
    5052        } 
    51         //                                                  del    he    ray   ni    up   fen   eco   crt   stp   ply   ksk   dgr 
    52         const int type_width[]  = [  80 ,  80 ,  80 ,  80 ,  80 ,  80 ,  64 ,  64 ,  32 ,  32 ,  32 ,  32 ]; 
    53         const int type_height[] = [  32 ,  32 ,  32 ,  32 ,  32 ,  32 ,  16 ,  16 ,  16 ,  16 ,  16 ,  16 ]; 
    54         const int type_style[]  = [ LRG , LRG , LRG , LRG , LRG , LRG , SML , SML , MIN , MIN , MIN , MIN ]; 
     53        //                                                  del    he    ray   ni    up   fen   eco   crt  save  load   stp   ply   ksk   dgr  
     54        const int type_width[]  = [  80 ,  80 ,  80 ,  80 ,  80 ,  80 ,  64 ,  64 ,  64 ,  64 ,  32 ,  32 ,  32 ,  32 ]; 
     55        const int type_height[] = [  32 ,  32 ,  32 ,  32 ,  32 ,  32 ,  16 ,  16 ,  16 ,  16 ,  16 ,  16 ,  16 ,  16 ]; 
     56        const int type_style[]  = [ LRG , LRG , LRG , LRG , LRG , LRG , SML , SML , SML , SML , MIN , MIN , MIN , MIN ]; 
    5557         
    5658        this(TYPE type){ 
     
    196198         
    197199        string getSelected(){return selected;} 
     200        void setSelected(string str){selected = str;} 
    198201         
    199202        void draw(){ 
  • lang/d/koke/trunk/config.d

    r6941 r11928  
    1 /********************************************************************************/ 
     1/********************************************************************************/ 
    22/*      config.d                                                                                                                                        */ 
    33/*------------------------------------------------------------------------------*/ 
     
    2828        char[][char[]] _data;     // データ(キーと値) 
    2929        char[]         _filepath; // ファイルパス 
    30         d_time         _fta;      // ファイルの最終更新時間(監視用) 
     30        d_time         _ftm;      // ファイルの最終更新時間(監視用) ftaからftmへ変更 
    3131public: 
    3232        this() {} 
     
    6363                getTimes(filepath , current_ftc , current_fta , current_ftm); 
    6464                 
    65                 _fta = current_fta; 
     65                _ftm = current_ftm; 
    6666        } 
    6767        char[] get(char[] key)        { checkKey(key);         return _data[key];             } // 文字列で取得 
     
    9898                getTimes(_filepath , current_ftc , current_fta , current_ftm); 
    9999                 
    100                 if(current_fta > _fta) return false; 
     100                if(current_ftm > _ftm) return false; 
    101101                return true; 
    102102        } 
  • lang/d/koke/trunk/config.ini

    r7148 r11928  
    3131MAP_HEIGHT = 48 
    3232 
     33 
     34 
     35# -------------------------------------------------------------------- 
     36# MAP_SAVE_FILE 
     37# �@�}�b�v�f�[�^��[�u�����@�C���� 
     38MAP_SAVE_FILE = mapdata.txt 
     39 
     40# MAP_LOAD_FILE 
     41# �@�}�b�v�f�[�^��[�h�����@�C���� 
     42MAP_LOAD_FILE = mapdata.txt 
    3343 
    3444 
  • lang/d/koke/trunk/gamecore.d

    r11612 r11928  
    4949        ClickablePool economy_switch;   // エコノミーのON/OFFスイッチ(右上 
    5050        ClickablePool speed_switch;             // 速度スイッチ(右上 
     51        ClickablePool save_switch;              // セーブ 
     52        ClickablePool load_switch;              // ロード 
    5153         
    5254        int cursor_x;                                   // マウス直下の座標x(マップチップ座標系) 
     
    6668        int message_timer;                              // システムメッセージ表示用タイマ 
    6769        string message;                                 // システムメッセージ 
     70        enum MESSAGE_COLOR{ 
     71                NORMAL, 
     72                ERROR, 
     73        } 
     74        MESSAGE_COLOR message_color;    // システムメッセージの色 
    6875         
    6976        int mray_timer;                                 // 運営レーザー用タイマ 
     
    7178        int shake_power;                                // 画面ゆれ強度 
    7279         
    73         static const int CONFIG_RELOAD_CHECK_INTERVAL = 40 * 5;                 // コンフィグ再読み込み確認 
    74         static const int MESSAGE_SHOW_INTERVAL = 40 * 3;                        // 「コンフィグ読み込んだ」表示時間 
     80        static const int CONFIG_RELOAD_CHECK_INTERVAL = 40 * 5;         // コンフィグ再読み込み確認 
     81        static const int MESSAGE_SHOW_INTERVAL = 40 * 3;                        // システムメッセージ表示時間 
    7582         
    7683        // 運営レーザー用タイマー数値 
     
    8491                configparser = new ConfigParser(); 
    8592                configparser.load(CONFIG_PATH); 
     93                 
    8694                message_timer = 0; 
    8795                message = ""; 
     96                message_color = MESSAGE_COLOR.NORMAL; 
    8897                 
    8998                mray_timer = 0; 
     
    139148                speed_switch.add("danger" , new Vec3( -32*1 , 16 ,0) 
    140149                        , ImageButton.TYPE.DANGER); 
     150                 
     151                // save/load 
     152                save_switch = new ClickablePool(); 
     153                save_switch.add("save" , new Vec3( -32*4 , 32 , 0) 
     154                        , ImageButton.TYPE.SAVE); 
     155                 
     156                load_switch = new ClickablePool(); 
     157                load_switch.add("load" , new Vec3( -32*2 , 32 , 0) 
     158                        , ImageButton.TYPE.LOAD); 
     159                 
    141160        } 
    142161         
     
    174193                economy_switch.getMouseClick(); 
    175194                speed_switch.getMouseClick(); 
     195                save_switch.getMouseClick(); 
     196                load_switch.getMouseClick(); 
     197                 
     198                // save&load 
     199                if(load_switch.getSelected() == "load"){ 
     200                        if( map.loadFile( configparser.get("MAP_LOAD_FILE") ) ){ 
     201                                setMessage("MAP LOAD SUCCESS"); 
     202                        }else{ 
     203                                setMessage("** MAP LOAD FAIL **" , MESSAGE_COLOR.ERROR); 
     204                        } 
     205                        load_switch.setSelected(""); 
     206                } 
     207                if(save_switch.getSelected() == "save"){ 
     208                        if( map.saveFile( configparser.get("MAP_SAVE_FILE") ) ){ 
     209                                setMessage("MAP SAVE SUCCESS"); 
     210                        }else{ 
     211                                setMessage("** MAP SAVE FAIL **" , MESSAGE_COLOR.ERROR); 
     212                        } 
     213                        save_switch.setSelected(""); 
     214                } 
    176215                 
    177216                string menucmd = menu.getSelected(); 
     
    275314                        configparser.update(); 
    276315                        config_reload = 0; 
    277                         message_timer = MESSAGE_SHOW_INTERVAL; 
    278                         message = "CONFIG RELOAD"; 
     316                        setMessage("CONFIG RELOAD"); 
    279317                } 
    280318                if(message_timer > 0) message_timer--; 
     
    400438                economy_switch.draw(); 
    401439                speed_switch.draw(); 
     440                save_switch.draw();      
     441                load_switch.draw(); 
    402442                 
    403443                // チャート 
     
    406446                // message 
    407447                if(message_timer > 0 && timer % 11 < 10){ 
    408                 Hell_drawFont(message , (getScreenWidth() - 8 * message.length)/ 2 , getScreenHeight() / 2  
    409                                         , 1 , 255,128,0); 
     448                        if(message_color == MESSAGE_COLOR.ERROR){ 
     449                                Hell_drawFont(message , (getScreenWidth() - 8 * message.length)/ 2 , getScreenHeight() / 2  
     450                                                , 1 , 255,128,0); 
     451                        }else{ 
     452                                Hell_drawFont(message , (getScreenWidth() - 8 * message.length)/ 2 , getScreenHeight() / 2  
     453                                                , 1 , 128,192,255); 
     454                        } 
    410455                } 
    411456                 
     
    435480        bool onMouseMap(){ 
    436481                if(menu.getMouseOver() == "" && economy_switch.getMouseOver() == "" 
    437                         && chart_switch.getMouseOver() == "" && speed_switch.getMouseOver() == "") return true; 
     482                                && chart_switch.getMouseOver() == "" && speed_switch.getMouseOver() == "" 
     483                                && save_switch.getMouseOver() == "" && load_switch.getMouseOver() == "") return true; 
    438484                 
    439485                return false; 
     
    449495                } 
    450496                return str; 
     497        } 
     498         
     499        // システムメッセージ表示 
     500        void setMessage( string msg , MESSAGE_COLOR color = MESSAGE_COLOR.NORMAL){ 
     501                message_timer = MESSAGE_SHOW_INTERVAL; 
     502                message = msg; 
     503                message_color = color; 
    451504        } 
    452505} 
     
    480533        GameMain gamemain; 
    481534         
    482         static const int LOG_MAX = 160; 
     535        static const int LOG_MAX = 320; 
    483536        static const int LOG_VIEW_WIDTH = 4; 
    484537         
     
    526579                for(int t=0;t<logs.length - 1;t++){ 
    527580                        if(logs[t] && logs[t+1]){ 
     581                                if( gamemain.getScreenWidth() + (t+1 - logs.length) * LOG_VIEW_WIDTH < 0) break; 
     582                                                 
    528583                                for(int e;e < logs[t].param.length ; e++){ 
    529584                                        if(r[e] == 0 && g[e] == 0 && b[e] == 0) continue; 
    530585                                         
    531                                         Hell_drawLine(t * LOG_VIEW_WIDTH , gamemain.getScreenHeight() - 80 - logs[t].param[e] * scale 
    532                                                         , (t+1) * LOG_VIEW_WIDTH , gamemain.getScreenHeight() - 80 - logs[t+1].param[e] * scale 
     586                                        Hell_drawLine(gamemain.getScreenWidth() + (t - logs.length) * LOG_VIEW_WIDTH 
     587                                                        , gamemain.getScreenHeight() - 80 - logs[t].param[e] * scale 
     588                                                        , gamemain.getScreenWidth() + (t+1 - logs.length) * LOG_VIEW_WIDTH 
     589                                                        , gamemain.getScreenHeight() - 80 - logs[t+1].param[e] * scale 
    533590                                                        , 2 , r[e] , g[e] , b[e]); 
    534591                                } 
  • lang/d/koke/trunk/map.d

    r7113 r11928  
    1 /********************************************************************************/ 
     1/********************************************************************************/ 
    22/*      map.d                                                                                                                                           */ 
    33/*------------------------------------------------------------------------------*/ 
     
    3636                MOVIE = 1, 
    3737                FENCE, 
    38         } 
    39         const static string name[] = ["NONE" , "MOVIE" , "FENCE"]; 
     38                WATER, 
     39                DARK, 
     40        } 
     41        const static string name[] = ["NONE" , "MOVIE" , "FENCE" , "WATER" , "DARK" ]; 
    4042         
    4143        const static int TYPEDRAW_LOOP = 16; 
     
    110112                        return 4; 
    111113                } 
     114        } 
     115         
     116        char toSerializedChar(){ 
     117                if( type == TYPE.NONE )         return ' '; 
     118                if( type == TYPE.MOVIE )        return 'W'; 
     119                if( type == TYPE.FENCE )        return 'F'; 
     120                if( type == TYPE.WATER )        return 'M'; 
     121                if( type == TYPE.DARK )         return 'D'; 
     122                Hell_write("Undefined mapdata serialize to char."); 
     123                return ' '; 
     124        } 
     125         
     126        bool setSerializedChar( char ch ){ 
     127                if( ch == ' ' )         return set( TYPE.NONE , 0 ); 
     128                if( ch == 'W' )         return set( TYPE.MOVIE , 0 ); 
     129                if( ch == 'F' )         return set( TYPE.FENCE , 0 ); 
     130                if( ch == 'M' )         return set( TYPE.WATER , 0 ); 
     131                if( ch == 'D' )         return set( TYPE.DARK , 0 ); 
     132                Hell_write("Undefine mapdata restore from char"); 
     133                return false; 
     134        } 
     135         
     136        bool set( TYPE type , double grass ){ 
     137                this.type = type; 
     138                this.grass = grass; 
     139                return true; 
    112140        } 
    113141} 
     
    275303        } 
    276304         
     305        // ロード 
     306        bool loadFile( string filename ){ 
     307                string[] buffer; 
     308                try{ 
     309                        buffer = std.string.split( cast(string) std.file.read(filename) , "\n" ); 
     310                }catch(Exception e){ 
     311                        Hell_write(e); 
     312                        return false; 
     313                } 
     314                 
     315                for(int y = 0 ; y < buffer.length ; y++ ){ 
     316                        string line = buffer[y]; 
     317                        for(int x = 0 ; x < line.length ; x++ ){ 
     318                                char ch = line[x]; 
     319                                MapChip m = toMap( x , y ); 
     320                                if(m) m.setSerializedChar( ch ); 
     321                        } 
     322                } 
     323                return true; 
     324        } 
     325        // セーブ 
     326        bool saveFile( string filename ){ 
     327                string buffer = ""; 
     328                for(int y = 0; y < height ; y++ ){ 
     329                        for(int x = 0 ; x <width ; x++ ){ 
     330                                MapChip m = toMap(x,y); 
     331                                buffer ~= m.toSerializedChar(); 
     332                        } 
     333                        buffer ~= "\n"; 
     334                } 
     335                 
     336                try{ 
     337                        std.file.write( filename , buffer ); 
     338                }catch(Exception e){ 
     339                        Hell_write(e); 
     340                        return false; 
     341                } 
     342                return true; 
     343        } 
     344         
     345        // マップチップを配置 
    277346        bool set(int x,int y,MapChip.TYPE type){ 
    278347                if(!inRange(x,y)) return false; 
    279348                 
    280349                MapChip m = toMap(x,y); 
    281                 m.type = type; 
    282                 m.grass = 0; 
    283                 return true; 
    284         } 
    285          
    286         // 芝刈 
     350                return m.set( type , 0 ); 
     351        } 
     352         
     353        // 芝えねるぎーを配置 
    287354        bool setGrass(int x,int y,double grass){ 
    288355                if(!inRange(x,y)) return false; 
     
    293360        } 
    294361         
     362        // 芝エネルギー値をえる 
    295363        double getGrass(int x,int y){ 
    296364                if(!inRange(x,y)) return 0;