Esempio n. 1
0
File: base.py Progetto: shiwano/cwpy
    def export_image(self):
        """内部画像を出力する"""
        if not hasattr(self, "image"):
            return ""

        # 画像保存ディレクトリ
        if self.xmltype == "Summary":
            imgdir = self.get_dir()
        elif self.xmltype == "BeastCard" and self.summoneffect:
            imgdir = self.get_imgdir()

            if not imgdir:
                root = self.get_root()
                name = util.check_filename(root.name)
                imgdir = util.join_paths(self.get_dir(),
                                                "Material", root.xmltype, name)
                imgdir = util.check_duplicate(imgdir)
                self.set_imgdir(imgdir)

        elif self.xmltype in ("Adventurer", "SkillCard", "ItemCard",
                                                    "BeastCard", "CastCard"):
            name = util.check_filename(self.name)
            imgdir = util.join_paths(self.get_dir(), "Material",
                                                        self.xmltype, name)
            imgdir = util.check_duplicate(imgdir)
            self.set_imgdir(imgdir)
        else:
            imgdir = util.join_paths(self.get_dir(), "Material", self.xmltype)

        # 画像保存
        if self.image:
            # 画像パス
            if self.xmltype == "Summary":
                path = util.join_paths(imgdir, self.xmltype + ".bmp")
            else:
                name = util.check_filename(self.name) + ".bmp"
                path = util.join_paths(imgdir, name)

            # 画像出力
            path = util.check_duplicate(path)

            if not os.path.isdir(imgdir):
                os.makedirs(imgdir)

            f = open(path, "wb")
            f.write(self.image)
            f.close()
            # 最後に参照パスを返す
            path = path.replace(self.get_dir() + "/", "", 1)
            return util.repl_escapechar(path)
        else:
            return ""
Esempio n. 2
0
    def string(self, multiline=False):
        """dwordの値で読み込んだバイナリをユニコード文字列にして返す。
        dwordの値が"0"だったら空の文字列を返す。
        改行コードはxml置換用のために"\\n"に置換する。
        multiline: メッセージテクストなど改行の有効なテキストかどうか。
        """
        s = self.rawstring()

        if multiline:
            s = util.repl_specialchar(s)

        s = util.repl_escapechar(s)
        return s.replace("\r\n", "\\n")