Giter Site home page Giter Site logo

tsumiji's Introduction

rrbox

主要な開発言語

  • Swift

ジャンル

  • 2Dゲーム開発

主なプラットフォーム

  • macOS
  • iOS

tsumiji's People

Contributors

rrbox avatar

Stargazers

 avatar

Watchers

 avatar

tsumiji's Issues

わかりやすい README

AttributedString や NSAttributedString のラッパーは GitHub 上に意外と存在します. では, この Tsumiji は他のツールと同じ(あるいはそれ以下)なのでしょうか? 製作者は, そんなことはないと断言できます. このツールには他にはない, フォントの指定範囲の設定方法が備わっています. これは XML(や その派生言語である HTML など) を参考にした, 文字列の構造化が利用されており, より直感的にスタイルを指定できるはずです.

このようなこのパッケージの利点をよりわかりやすく README には記述していく必要があります.

Attribute を静的型付けにできないか検討

現在の API では以下のように定義しています。

typealias Attribute = [Key: Any]

Any ではなく, Key に対応した型を固定にしたい。少なくとも Dictionary では不可能なので, 連結リストのような特殊な型を作成することになりそう。

Attribute を増やす

NSAttributedString の API を見ても, もっと制御可能であることがわかります。サポートする Attribute の範囲を広げたいです。

Attribute の最適化

Attribute をビルダーパターンで設計できるようにしていますが、AttributeContext を直接ビルドできるようにして仕舞えばいいでのはないか? という試みです。

不変性も維持したいのであればこんな感じでしょうか。

public struct Attribute {
    let context: AttributeContext
}

public extension Attribute {
    static func fontName(_ value: String) -> Attribute {
        var newContext = AttributeContext()
        newContext.fontName = value
        return .init(context: newContext)
    }
    
    static func fontSize(_ value: NSNumber) -> Attribute {
        var newContext =  AttributeContext()
        newContext.fontSize = value
        return .init(context: newContext)
    }
    
    static func foregroundColor(_ value: Scope.ForegroundColorAttribute.Value) -> Attribute {
        var newContext =  AttributeContext()
        newContext.container.foregroundColor = value
        return .init(context: newContext)
    }
    
    static func backgroundColor(_ value: Scope.BackgroundColorAttribute.Value) -> Attribute {
        var newContext =  AttributeContext()
        newContext.container.backgroundColor = value
        return .init(context: newContext)
    }
    
    static func kern(_ value: Scope.KernAttribute.Value) -> Attribute {
        var newContext =  AttributeContext()
        newContext.container.kern = value
        return .init(context: newContext)
    }
    
    static func tracking(_ value: Scope.TrackingAttribute.Value) -> Attribute {
        var newContext =  AttributeContext()
        newContext.container.tracking = value
        return .init(context: newContext)
    }
    
    static func baselineOffset(_ value: Scope.BaselineOffsetAttribute.Value) -> Attribute {
        var newContext =  AttributeContext()
        newContext.container.baselineOffset = value
        return .init(context: newContext)
    }
}

メソッドの命名を短くする提案

ビルダーパターンでだいぶコードが短くなりましたが, まだまだ長く読みづらいです.
もっと短くする案も考えた方がいいかもしれません.
注意したいのは, これ以上短くすると, コード規約に反してしまうということです.

アトリビュート `@discardableResult` は必要ない

GameWidget や SKNodeBuilder では、作成したビルダー構造体は必ず別のオブジェクトやデータに還元されるため、このアトリビュートが必要無くなりました。Tsumiji もかつては NSMuableAttributedString を使用していたので、用途がわずかにありました。しかし昨今のアプデで AttributedString を使用するようになり、value semantics を確実に持つようになったので、@discardableResult は削除しても問題ないと思います。

Version 2

release に書く内容をここに下書きします.

#27 Attribute が一新されます。

〜 version 1

let attribute = [.fontName: "times", .fontSize: 32]
  • 辞書型
  • Value は Any 型 (コード補完が効かない)

version 2 〜

let attribute = .fontName("times").fontSize(32)
  • indirect 列挙体
  • Value は静的 (コード補完が効く)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.