|
| 1 | +# Next2D Framework |
| 2 | + |
| 3 | +Next2D Framework is an MVVM framework for building applications with Next2D Player. It provides routing for single-page applications (SPA), View/ViewModel management, and configuration management. |
| 4 | + |
| 5 | +## Key Features |
| 6 | + |
| 7 | +- **MVVM Pattern**: Separation of concerns with Model-View-ViewModel |
| 8 | +- **Single Page Application**: URL-based scene management |
| 9 | +- **Open Animation Tool Integration**: Seamless integration with Open Animation Tool assets |
| 10 | +- **TypeScript Support**: Type-safe development |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +### Create Project |
| 15 | + |
| 16 | +```bash |
| 17 | +npx create-next2d-app my-app |
| 18 | +cd my-app |
| 19 | +npm install |
| 20 | +npm run dev |
| 21 | +``` |
| 22 | + |
| 23 | +### Directory Structure |
| 24 | + |
| 25 | +``` |
| 26 | +my-app/ |
| 27 | +├── src/ |
| 28 | +│ ├── config/ |
| 29 | +│ │ └── config.json # Configuration |
| 30 | +│ ├── view/ |
| 31 | +│ │ └── TopView.ts # View class |
| 32 | +│ └── index.ts # Entry point |
| 33 | +├── asset/ |
| 34 | +│ └── content.json # Open Animation Tool output |
| 35 | +└── package.json |
| 36 | +``` |
| 37 | + |
| 38 | +## Core Concepts |
| 39 | + |
| 40 | +### View |
| 41 | + |
| 42 | +Views are responsible for screen display and correspond to MovieClips created with Open Animation Tool. |
| 43 | + |
| 44 | +```typescript |
| 45 | +import { View } from "@next2d/framework"; |
| 46 | + |
| 47 | +export class TopView extends View |
| 48 | +{ |
| 49 | + constructor() |
| 50 | + { |
| 51 | + super(); |
| 52 | + } |
| 53 | + |
| 54 | + async $setup(): Promise<void> |
| 55 | + { |
| 56 | + // Initial setup |
| 57 | + } |
| 58 | + |
| 59 | + $ready(): void |
| 60 | + { |
| 61 | + // Ready for display |
| 62 | + } |
| 63 | + |
| 64 | + $dispose(): void |
| 65 | + { |
| 66 | + // Cleanup |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### ViewModel |
| 72 | + |
| 73 | +ViewModel handles business logic for the View. |
| 74 | + |
| 75 | +```typescript |
| 76 | +import { ViewModel } from "@next2d/framework"; |
| 77 | + |
| 78 | +export class TopViewModel extends ViewModel |
| 79 | +{ |
| 80 | + async $setup(): Promise<void> |
| 81 | + { |
| 82 | + // Initialize data |
| 83 | + } |
| 84 | + |
| 85 | + $bind(): void |
| 86 | + { |
| 87 | + // Bind to View |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### Routing |
| 93 | + |
| 94 | +Configure routing in config.json: |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "routing": { |
| 99 | + "top": { |
| 100 | + "path": "/", |
| 101 | + "view": "TopView" |
| 102 | + }, |
| 103 | + "about": { |
| 104 | + "path": "/about", |
| 105 | + "view": "AboutView" |
| 106 | + }, |
| 107 | + "detail": { |
| 108 | + "path": "/detail/{id}", |
| 109 | + "view": "DetailView" |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +## Framework Flowchart |
| 116 | + |
| 117 | +Detailed flow of screen transitions using the gotoView function. |
| 118 | + |
| 119 | +```mermaid |
| 120 | +graph TD |
| 121 | + User([User]) -->|Request| GotoView[gotoView Path] |
| 122 | +
|
| 123 | + GotoView --> LoadingCheck{use loading?<br/>Default: true} |
| 124 | +
|
| 125 | + LoadingCheck -->|YES| ScreenOverlay[Screen Overlay] |
| 126 | + LoadingCheck -->|NO| RemoveResponse |
| 127 | + ScreenOverlay --> LoadingStart[Start Loading] |
| 128 | + LoadingStart --> RemoveResponse |
| 129 | +
|
| 130 | + RemoveResponse[Remove Previous Response Data] --> ParseQuery[Parse Query String] |
| 131 | + ParseQuery --> UpdateHistory{SPA mode?} |
| 132 | +
|
| 133 | + UpdateHistory -->|YES| PushState[Push History State] |
| 134 | + UpdateHistory -->|NO| RequestType |
| 135 | + PushState --> RequestType |
| 136 | +
|
| 137 | + RequestType[Request Type] |
| 138 | +
|
| 139 | + RequestType --> JSON[JSON: Get external JSON data] |
| 140 | + RequestType --> CONTENT[CONTENT: Get Animation Tool JSON] |
| 141 | + RequestType --> CUSTOM[CUSTOM: Request to external API] |
| 142 | +
|
| 143 | + JSON --> CacheCheck{use cache?<br/>Default: false} |
| 144 | + CONTENT --> CacheCheck |
| 145 | + CUSTOM --> CacheCheck |
| 146 | +
|
| 147 | + CacheCheck -->|YES| CacheData[(Cache)] |
| 148 | + CacheCheck -->|NO| GlobalData{{Global Network}} |
| 149 | +
|
| 150 | + CacheData --> Cached{Cached?} |
| 151 | +
|
| 152 | + Cached -->|NO| GlobalData |
| 153 | + Cached -->|YES| RegisterResponse |
| 154 | + GlobalData --> RegisterResponse |
| 155 | +
|
| 156 | + RegisterResponse[Register Response Data] --> RequestCallback{request callback?} |
| 157 | +
|
| 158 | + RequestCallback -->|YES| ExecRequestCallback[Execute Request Callback] |
| 159 | + RequestCallback -->|NO| UnbindView |
| 160 | + ExecRequestCallback --> UnbindView |
| 161 | +
|
| 162 | + UnbindView[Previous View: onExit & Unbind] --> BindView[New View/ViewModel: Bind] |
| 163 | + BindView --> ViewModelInit[ViewModel: initialize] |
| 164 | +
|
| 165 | + ViewModelInit --> ViewInit[View: initialize] |
| 166 | + ViewInit --> AddToStage[Add View to Stage] |
| 167 | + AddToStage --> GotoViewCallback{gotoView callback?} |
| 168 | +
|
| 169 | + GotoViewCallback -->|YES| ExecGotoViewCallback[Execute gotoView Callback] |
| 170 | + GotoViewCallback -->|NO| LoadingEndCheck |
| 171 | + ExecGotoViewCallback --> LoadingEndCheck |
| 172 | +
|
| 173 | + LoadingEndCheck{use loading?<br/>Default: true} |
| 174 | +
|
| 175 | + LoadingEndCheck -->|YES| LoadingEnd[End Loading] |
| 176 | + LoadingEndCheck -->|NO| OnEnter |
| 177 | + LoadingEnd --> DisposeOverlay[Dispose Screen Overlay] |
| 178 | + DisposeOverlay --> OnEnter |
| 179 | +
|
| 180 | + OnEnter[View: onEnter] --> StartDrawing |
| 181 | +
|
| 182 | + StartDrawing[Start Drawing] -->|Response| User |
| 183 | +
|
| 184 | + style User fill:#d5e8d4,stroke:#82b366 |
| 185 | + style StartDrawing fill:#dae8fc,stroke:#6c8ebf |
| 186 | + style CacheData fill:#fff2cc,stroke:#d6b656 |
| 187 | + style GlobalData fill:#f5f5f5,stroke:#666666 |
| 188 | +``` |
| 189 | + |
| 190 | +### Key Flow Steps |
| 191 | + |
| 192 | +| Step | Description | |
| 193 | +|------|-------------| |
| 194 | +| **gotoView** | Entry point for screen transitions | |
| 195 | +| **Loading** | Loading screen show/hide control | |
| 196 | +| **Request Type** | Three types of requests: JSON, CONTENT, CUSTOM | |
| 197 | +| **Cache** | Response data cache control | |
| 198 | +| **View/ViewModel Bind** | Binding process for new View/ViewModel | |
| 199 | +| **onEnter** | Callback after screen display is complete | |
| 200 | + |
| 201 | +## Related Documentation |
| 202 | + |
| 203 | +### Basics |
| 204 | +- [View/ViewModel](./view.md) - Screen display and data binding |
| 205 | +- [Routing](./routing.md) - URL-based screen transitions |
| 206 | +- [Configuration](./config.md) - Environment and stage settings |
| 207 | + |
| 208 | +### Next2D Player Integration |
| 209 | +- [Next2D Player](../../player/specs/en/index.md) - Rendering engine |
| 210 | +- [MovieClip](../../player/specs/en/movie-clip.md) - Timeline animation |
| 211 | +- [Event System](../../player/specs/en/events.md) - User interaction |
0 commit comments