@leejungkiin/awkit 1.7.1 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/awk.js +576 -84
- package/core/CLAUDE.md +1 -1
- package/core/GEMINI.md +148 -167
- package/core/GEMINI.md.bak +149 -116
- package/core/skill-runtime-manifest.json +3 -0
- package/docs/Claude Fable 5.md +3826 -0
- package/docs/android_kotlin_system_instruction.md +210 -0
- package/docs/brainstorm_ponytail_integration.md +146 -0
- package/docs/brainstorm_smart_setup.md +113 -0
- package/docs/deep-research-report (1).md +293 -0
- package/docs/history/GEMINI.v1.md +135 -0
- package/docs/history/brainstorm_antigravity_unified_architecture.v1.md +105 -0
- package/docs/history/implementation_plan.v1.md +58 -0
- package/package.json +4 -1
- package/scripts/artifact-storage.js +130 -0
- package/scripts/automation-gate.js +35 -2
- package/scripts/claude-plan.js +76 -0
- package/scripts/dependency-manager.js +210 -0
- package/scripts/exec-rtk.js +11 -5
- package/scripts/i18n-helper.js +381 -0
- package/scripts/multi-model-pipeline.js +144 -0
- package/skill-packs/mobile-ios/pack.json +4 -2
- package/skill-packs/reverse-engineering/pack.json +1 -0
- package/skills/CATALOG.md +20 -0
- package/skills/GEMINI.md +9 -1
- package/skills/TRIGGER_INDEX.md +10 -0
- package/skills/ai-music/SKILL.md +275 -0
- package/skills/android-re-analyzer/SKILL.md +238 -0
- package/skills/android-re-analyzer/references/api-extraction-patterns.md +119 -0
- package/skills/android-re-analyzer/references/call-flow-analysis.md +176 -0
- package/skills/android-re-analyzer/references/fernflower-usage.md +115 -0
- package/skills/android-re-analyzer/references/jadx-usage.md +116 -0
- package/skills/android-re-analyzer/references/setup-guide.md +221 -0
- package/skills/android-re-analyzer/scripts/check-deps.sh +129 -0
- package/skills/android-re-analyzer/scripts/decompile.sh +375 -0
- package/skills/android-re-analyzer/scripts/find-api-calls.sh +118 -0
- package/skills/android-re-analyzer/scripts/install-dep.sh +448 -0
- package/skills/animal-island-ui-style/SKILL.md +1450 -0
- package/skills/app-store-review-agent/SKILL.md +164 -0
- package/skills/app-store-review-agent/references/guidelines/README.md +154 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/ai_apps.md +37 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/all_apps.md +50 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/crypto_finance.md +31 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/games.md +31 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/health_fitness.md +31 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/kids.md +27 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/macos.md +38 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/social_ugc.md +32 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/subscription_iap.md +34 -0
- package/skills/app-store-review-agent/references/guidelines/by-app-type/vpn.md +18 -0
- package/skills/app-store-review-agent/references/rules/design/minimum_functionality.md +96 -0
- package/skills/app-store-review-agent/references/rules/design/sign_in_with_apple.md +54 -0
- package/skills/app-store-review-agent/references/rules/entitlements/unused_entitlements.md +83 -0
- package/skills/app-store-review-agent/references/rules/metadata/accurate_metadata.md +54 -0
- package/skills/app-store-review-agent/references/rules/metadata/apple_trademark.md +99 -0
- package/skills/app-store-review-agent/references/rules/metadata/china_storefront.md +72 -0
- package/skills/app-store-review-agent/references/rules/metadata/competitor_terms.md +56 -0
- package/skills/app-store-review-agent/references/rules/metadata/subscription_metadata.md +81 -0
- package/skills/app-store-review-agent/references/rules/privacy/privacy_manifest.md +84 -0
- package/skills/app-store-review-agent/references/rules/privacy/unnecessary_data.md +60 -0
- package/skills/app-store-review-agent/references/rules/subscription/misleading_pricing.md +63 -0
- package/skills/app-store-review-agent/references/rules/subscription/missing_tos_pp.md +54 -0
- package/skills/awf-ponytail/SKILL.md +91 -0
- package/skills/awf-ponytail-review/SKILL.md +67 -0
- package/skills/awf-session-restore/SKILL.md +3 -3
- package/skills/brainstorm-agent/SKILL.md +11 -2
- package/skills/brainstorm-agent/templates/brief-template.md +8 -0
- package/skills/claude-planner/SKILL.md +47 -0
- package/skills/code-review/SKILL.md +87 -0
- package/skills/expo-game-development/SKILL.md +163 -0
- package/skills/flutter/LICENSE.txt +202 -0
- package/skills/flutter/SKILL.md +127 -0
- package/skills/flutter-project-creater/LICENSE.txt +202 -0
- package/skills/flutter-project-creater/SKILL.md +106 -0
- package/skills/game-developer/SKILL.md +163 -0
- package/skills/game-developer/references/ecs-patterns.md +501 -0
- package/skills/game-developer/references/multiplayer-networking.md +475 -0
- package/skills/game-developer/references/performance-optimization.md +422 -0
- package/skills/game-developer/references/unity-patterns.md +271 -0
- package/skills/game-developer/references/unreal-cpp.md +352 -0
- package/skills/generate-gui-assets/SKILL.md +305 -0
- package/skills/generate-gui-assets/agents/openai.yaml +4 -0
- package/skills/generate-gui-assets/references/catalog-schema.md +58 -0
- package/skills/generate-gui-assets/references/extraction-techniques.md +21 -0
- package/skills/generate-gui-assets/references/prompt-patterns.md +58 -0
- package/skills/generate-gui-assets/scripts/__pycache__/clean_chroma_edges.cpython-311.pyc +0 -0
- package/skills/generate-gui-assets/scripts/build_gui_contact_sheet.py +51 -0
- package/skills/generate-gui-assets/scripts/clean_chroma_edges.py +262 -0
- package/skills/generate-gui-assets/scripts/copy_approved_icons.py +64 -0
- package/skills/generate-gui-assets/scripts/prepare_gui_asset_run.py +91 -0
- package/skills/generate-gui-assets/scripts/suggest_grid_options.py +63 -0
- package/skills/generate-gui-assets/scripts/validate_gui_catalog.py +50 -0
- package/skills/godot-game-development/SKILL.md +142 -0
- package/skills/hatch-pet/LICENSE.txt +201 -0
- package/skills/hatch-pet/SKILL.md +420 -0
- package/skills/hatch-pet/agents/openai.yaml +4 -0
- package/skills/hatch-pet/references/animation-rows.md +29 -0
- package/skills/hatch-pet/references/codex-pet-contract.md +35 -0
- package/skills/hatch-pet/references/qa-rubric.md +60 -0
- package/skills/hatch-pet/scripts/__pycache__/clean_chroma_edges.cpython-311.pyc +0 -0
- package/skills/hatch-pet/scripts/clean_chroma_edges.py +262 -0
- package/skills/hatch-pet/scripts/compose_atlas.py +150 -0
- package/skills/hatch-pet/scripts/derive_running_left_from_running_right.py +143 -0
- package/skills/hatch-pet/scripts/extract_strip_frames.py +323 -0
- package/skills/hatch-pet/scripts/finalize_pet_run.py +382 -0
- package/skills/hatch-pet/scripts/generate_pet_images.py +287 -0
- package/skills/hatch-pet/scripts/inspect_frames.py +246 -0
- package/skills/hatch-pet/scripts/make_contact_sheet.py +96 -0
- package/skills/hatch-pet/scripts/package_custom_pet.py +108 -0
- package/skills/hatch-pet/scripts/pet_job_status.py +117 -0
- package/skills/hatch-pet/scripts/prepare_pet_run.py +673 -0
- package/skills/hatch-pet/scripts/queue_pet_repairs.py +172 -0
- package/skills/hatch-pet/scripts/record_imagegen_result.py +250 -0
- package/skills/hatch-pet/scripts/render_animation_videos.py +134 -0
- package/skills/hatch-pet/scripts/render_animation_videos.sh +5 -0
- package/skills/hatch-pet/scripts/validate_atlas.py +139 -0
- package/skills/i18n-orchestrator/SKILL.md +37 -0
- package/skills/ios-simulator-skill/SKILL.md +390 -0
- package/skills/ios-simulator-skill/scripts/accessibility_audit.py +300 -0
- package/skills/ios-simulator-skill/scripts/app_launcher.py +326 -0
- package/skills/ios-simulator-skill/scripts/app_state_capture.py +400 -0
- package/skills/ios-simulator-skill/scripts/appearance.py +385 -0
- package/skills/ios-simulator-skill/scripts/build_and_test.py +348 -0
- package/skills/ios-simulator-skill/scripts/clipboard.py +103 -0
- package/skills/ios-simulator-skill/scripts/common/__init__.py +61 -0
- package/skills/ios-simulator-skill/scripts/common/cache_utils.py +289 -0
- package/skills/ios-simulator-skill/scripts/common/device_utils.py +462 -0
- package/skills/ios-simulator-skill/scripts/common/env_config.py +35 -0
- package/skills/ios-simulator-skill/scripts/common/hang_pipeline.py +862 -0
- package/skills/ios-simulator-skill/scripts/common/hang_sessions.py +490 -0
- package/skills/ios-simulator-skill/scripts/common/idb_utils.py +180 -0
- package/skills/ios-simulator-skill/scripts/common/screenshot_utils.py +338 -0
- package/skills/ios-simulator-skill/scripts/container.py +668 -0
- package/skills/ios-simulator-skill/scripts/gesture.py +394 -0
- package/skills/ios-simulator-skill/scripts/hang_watcher.py +1533 -0
- package/skills/ios-simulator-skill/scripts/keyboard.py +391 -0
- package/skills/ios-simulator-skill/scripts/localization_audit.py +483 -0
- package/skills/ios-simulator-skill/scripts/location.py +467 -0
- package/skills/ios-simulator-skill/scripts/log_monitor.py +493 -0
- package/skills/ios-simulator-skill/scripts/model_inspector.py +645 -0
- package/skills/ios-simulator-skill/scripts/navigator.py +461 -0
- package/skills/ios-simulator-skill/scripts/privacy_manager.py +310 -0
- package/skills/ios-simulator-skill/scripts/push_notification.py +240 -0
- package/skills/ios-simulator-skill/scripts/screen_mapper.py +296 -0
- package/skills/ios-simulator-skill/scripts/sim_health_check.sh +245 -0
- package/skills/ios-simulator-skill/scripts/sim_list.py +299 -0
- package/skills/ios-simulator-skill/scripts/simctl_boot.py +312 -0
- package/skills/ios-simulator-skill/scripts/simctl_create.py +316 -0
- package/skills/ios-simulator-skill/scripts/simctl_delete.py +357 -0
- package/skills/ios-simulator-skill/scripts/simctl_erase.py +351 -0
- package/skills/ios-simulator-skill/scripts/simctl_shutdown.py +290 -0
- package/skills/ios-simulator-skill/scripts/simulator_selector.py +375 -0
- package/skills/ios-simulator-skill/scripts/status_bar.py +250 -0
- package/skills/ios-simulator-skill/scripts/test_recorder.py +323 -0
- package/skills/ios-simulator-skill/scripts/visual_diff.py +235 -0
- package/skills/ios-simulator-skill/scripts/xcode/__init__.py +13 -0
- package/skills/ios-simulator-skill/scripts/xcode/builder.py +397 -0
- package/skills/ios-simulator-skill/scripts/xcode/cache.py +204 -0
- package/skills/ios-simulator-skill/scripts/xcode/config.py +178 -0
- package/skills/ios-simulator-skill/scripts/xcode/reporter.py +343 -0
- package/skills/ios-simulator-skill/scripts/xcode/xcresult.py +451 -0
- package/skills/ios-visual-qa-strategist/SKILL.md +111 -0
- package/skills/ios-visual-qa-strategist/agents/openai.yaml +4 -0
- package/skills/ios-visual-qa-strategist/references/ios-tool-selection.md +61 -0
- package/skills/ios-visual-qa-strategist/references/minimal-capture-policy.md +56 -0
- package/skills/ios-visual-qa-strategist/references/visual-reasoning-heuristics.md +53 -0
- package/skills/orchestrator/SKILL.md +0 -20
- package/skills/persistent-storage/SKILL.md +55 -0
- package/skills/short-maker/SKILL.md +23 -0
- package/skills/short-maker/scripts/effects.js +56 -0
- package/skills/short-maker/scripts/shortmaker-bridge.js +332 -0
- package/skills/short-maker/scripts/videomix.js +601 -0
- package/skills/short-maker/templates/hyperframes/cinematic-character.template.html +172 -0
- package/skills/short-maker/templates/hyperframes/index.template.html +194 -0
- package/skills/smali-to-kotlin/SKILL.md +128 -0
- package/skills/smali-to-kotlin/examples/getting-started/tech-stack.md +58 -0
- package/skills/smali-to-kotlin/examples/pipeline/data-ui-parity.md +118 -0
- package/skills/smali-to-kotlin/examples/pipeline/scanner-and-bootstrap.md +106 -0
- package/skills/smali-to-kotlin/library-patterns.md +189 -0
- package/skills/smali-to-kotlin/phase-0-discovery.md +128 -0
- package/skills/smali-to-kotlin/phase-1-architecture.md +166 -0
- package/skills/smali-to-kotlin/phase-2-blueprint-ui.md +347 -0
- package/skills/smali-to-kotlin/phase-2-blueprint.md +228 -0
- package/skills/smali-to-kotlin/phase-3-build.md +248 -0
- package/skills/smali-to-kotlin/phase-3-logic-build.md +268 -0
- package/skills/smali-to-kotlin/smali-reading-guide.md +310 -0
- package/skills/smali-to-kotlin/templates/app-map.md +101 -0
- package/skills/smali-to-kotlin/templates/architecture.md +142 -0
- package/skills/smali-to-kotlin/templates/blueprint.md +145 -0
- package/skills/spec-gate/SKILL.md +6 -2
- package/skills/symphony-enforcer/SKILL.md +8 -0
- package/skills/symphony-enforcer/examples/mindful-stop.md +2 -0
- package/skills/symphony-enforcer/examples/three-phase.md +16 -0
- package/skills/symphony-enforcer/examples/trigger-points.md +7 -1
- package/skills/unity-game-development/SKILL.md +231 -0
- package/skills/video-edit/SKILL.md +36 -0
- package/skills/video-edit/scripts/video_edit.py +324 -0
- package/templates/project-identity/android.json +2 -2
- package/templates/project-identity/backend-nestjs.json +2 -2
- package/templates/project-identity/expo.json +2 -2
- package/templates/project-identity/ios.json +2 -2
- package/templates/project-identity/web-nextjs.json +2 -2
- package/templates/setup-mapping.json +48 -0
- package/templates/specs/design-template.md +161 -71
- package/templates/specs/requirements-template.md +65 -133
- package/templates/specs/task-spec-template.xml +3 -0
- package/workflows/_uncategorized/critic.md +40 -0
- package/workflows/_uncategorized/git-rebase-flow.md +81 -0
- package/workflows/_uncategorized/image-gen.md +118 -0
- package/workflows/_uncategorized/multi-model-pipeline.md +60 -0
- package/workflows/_uncategorized/pixel-gen.md +86 -0
- package/workflows/_uncategorized/pixel-setup.md +90 -0
- package/workflows/_uncategorized/ponytail-review.md +59 -0
- package/workflows/_uncategorized/reverse-android-build.md +222 -0
- package/workflows/_uncategorized/reverse-android-design.md +139 -0
- package/workflows/_uncategorized/reverse-android-discover.md +150 -0
- package/workflows/_uncategorized/reverse-android-scan.md +158 -0
- package/workflows/_uncategorized/reverse-android.md +143 -0
- package/workflows/_uncategorized/reverse-ios-build.md +240 -0
- package/workflows/_uncategorized/reverse-ios-design.md +112 -0
- package/workflows/_uncategorized/reverse-ios-discover.md +120 -0
- package/workflows/_uncategorized/reverse-ios-scan.md +155 -0
- package/workflows/_uncategorized/reverse-ios.md +152 -0
- package/workflows/_uncategorized/safety-router.md +34 -0
- package/workflows/_uncategorized/teach.md +89 -0
- package/workflows/_uncategorized/verify-ui.md +53 -0
- package/workflows/_uncategorized/visualize-screenshots.md +34 -0
- package/workflows/ads/ads-analyst.md +201 -0
- package/workflows/ads/ads-audit.md +106 -0
- package/workflows/ads/ads-optimize.md +97 -0
- package/workflows/ads/ads-targeting.md +241 -0
- package/workflows/ads/adsExpert.md +160 -0
- package/workflows/ads/smali-ads-config.md +400 -0
- package/workflows/ads/smali-ads-flow.md +331 -0
- package/workflows/ads/smali-ads-interstitial.md +377 -0
- package/workflows/ads/smali-ads-native.md +382 -0
- package/workflows/context/teach.md +89 -0
- package/workflows/gitnexus.md +8 -8
- package/workflows/lifecycle/brainstorm.md +43 -0
- package/workflows/lifecycle/code.md +5 -0
- package/workflows/lifecycle/init.md +23 -5
- package/workflows/lifecycle/multi-model-pipeline.md +60 -0
- package/workflows/quality/ponytail-review.md +59 -0
- package/workflows/roles/critic.md +40 -0
- package/workflows/roles/safety-router.md +34 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
# ECS Architecture and Game Patterns
|
|
2
|
+
|
|
3
|
+
## Entity Component System (ECS)
|
|
4
|
+
|
|
5
|
+
```csharp
|
|
6
|
+
// Component = pure data (no logic)
|
|
7
|
+
public struct PositionComponent
|
|
8
|
+
{
|
|
9
|
+
public float X;
|
|
10
|
+
public float Y;
|
|
11
|
+
public float Z;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public struct VelocityComponent
|
|
15
|
+
{
|
|
16
|
+
public float X;
|
|
17
|
+
public float Y;
|
|
18
|
+
public float Z;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public struct HealthComponent
|
|
22
|
+
{
|
|
23
|
+
public int Current;
|
|
24
|
+
public int Max;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public struct PlayerTag { } // Marker component
|
|
28
|
+
|
|
29
|
+
// Entity = just an ID
|
|
30
|
+
public struct Entity
|
|
31
|
+
{
|
|
32
|
+
public int Id;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// System = logic operating on components
|
|
36
|
+
public class MovementSystem
|
|
37
|
+
{
|
|
38
|
+
public void Update(float deltaTime,
|
|
39
|
+
Span<PositionComponent> positions,
|
|
40
|
+
Span<VelocityComponent> velocities)
|
|
41
|
+
{
|
|
42
|
+
for (int i = 0; i < positions.Length; i++)
|
|
43
|
+
{
|
|
44
|
+
positions[i].X += velocities[i].X * deltaTime;
|
|
45
|
+
positions[i].Y += velocities[i].Y * deltaTime;
|
|
46
|
+
positions[i].Z += velocities[i].Z * deltaTime;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Simple ECS World
|
|
52
|
+
public class World
|
|
53
|
+
{
|
|
54
|
+
private int nextEntityId = 0;
|
|
55
|
+
private Dictionary<int, PositionComponent> positions = new();
|
|
56
|
+
private Dictionary<int, VelocityComponent> velocities = new();
|
|
57
|
+
private Dictionary<int, HealthComponent> healths = new();
|
|
58
|
+
|
|
59
|
+
public Entity CreateEntity()
|
|
60
|
+
{
|
|
61
|
+
return new Entity { Id = nextEntityId++ };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public void AddComponent<T>(Entity entity, T component)
|
|
65
|
+
{
|
|
66
|
+
// Store component by entity ID
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public T GetComponent<T>(Entity entity)
|
|
70
|
+
{
|
|
71
|
+
// Retrieve component for entity
|
|
72
|
+
return default;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Object Pool Pattern
|
|
78
|
+
|
|
79
|
+
```csharp
|
|
80
|
+
public class ObjectPool<T> where T : class, new()
|
|
81
|
+
{
|
|
82
|
+
private readonly Stack<T> pool = new();
|
|
83
|
+
private readonly Func<T> createFunc;
|
|
84
|
+
private readonly Action<T> resetAction;
|
|
85
|
+
private readonly int maxSize;
|
|
86
|
+
|
|
87
|
+
public ObjectPool(Func<T> createFunc, Action<T> resetAction, int initialSize = 10, int maxSize = 100)
|
|
88
|
+
{
|
|
89
|
+
this.createFunc = createFunc;
|
|
90
|
+
this.resetAction = resetAction;
|
|
91
|
+
this.maxSize = maxSize;
|
|
92
|
+
|
|
93
|
+
// Pre-populate pool
|
|
94
|
+
for (int i = 0; i < initialSize; i++)
|
|
95
|
+
{
|
|
96
|
+
pool.Push(createFunc());
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public T Get()
|
|
101
|
+
{
|
|
102
|
+
if (pool.Count > 0)
|
|
103
|
+
return pool.Pop();
|
|
104
|
+
|
|
105
|
+
return createFunc();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public void Return(T obj)
|
|
109
|
+
{
|
|
110
|
+
if (pool.Count < maxSize)
|
|
111
|
+
{
|
|
112
|
+
resetAction?.Invoke(obj);
|
|
113
|
+
pool.Push(obj);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Usage example
|
|
119
|
+
public class BulletManager
|
|
120
|
+
{
|
|
121
|
+
private ObjectPool<Bullet> bulletPool;
|
|
122
|
+
|
|
123
|
+
public void Initialize()
|
|
124
|
+
{
|
|
125
|
+
bulletPool = new ObjectPool<Bullet>(
|
|
126
|
+
createFunc: () => new Bullet(),
|
|
127
|
+
resetAction: (bullet) => bullet.Reset(),
|
|
128
|
+
initialSize: 50,
|
|
129
|
+
maxSize: 200
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public Bullet SpawnBullet()
|
|
134
|
+
{
|
|
135
|
+
Bullet bullet = bulletPool.Get();
|
|
136
|
+
bullet.Activate();
|
|
137
|
+
return bullet;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public void ReturnBullet(Bullet bullet)
|
|
141
|
+
{
|
|
142
|
+
bullet.Deactivate();
|
|
143
|
+
bulletPool.Return(bullet);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## State Machine Pattern
|
|
149
|
+
|
|
150
|
+
```csharp
|
|
151
|
+
public interface IState
|
|
152
|
+
{
|
|
153
|
+
void Enter();
|
|
154
|
+
void Update(float deltaTime);
|
|
155
|
+
void Exit();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public class StateMachine
|
|
159
|
+
{
|
|
160
|
+
private IState currentState;
|
|
161
|
+
|
|
162
|
+
public void ChangeState(IState newState)
|
|
163
|
+
{
|
|
164
|
+
currentState?.Exit();
|
|
165
|
+
currentState = newState;
|
|
166
|
+
currentState?.Enter();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public void Update(float deltaTime)
|
|
170
|
+
{
|
|
171
|
+
currentState?.Update(deltaTime);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Example: Enemy AI States
|
|
176
|
+
public class IdleState : IState
|
|
177
|
+
{
|
|
178
|
+
private readonly EnemyController enemy;
|
|
179
|
+
|
|
180
|
+
public IdleState(EnemyController enemy) => this.enemy = enemy;
|
|
181
|
+
|
|
182
|
+
public void Enter()
|
|
183
|
+
{
|
|
184
|
+
enemy.PlayAnimation("Idle");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public void Update(float deltaTime)
|
|
188
|
+
{
|
|
189
|
+
if (enemy.PlayerInRange())
|
|
190
|
+
enemy.StateMachine.ChangeState(new ChaseState(enemy));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public void Exit() { }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public class ChaseState : IState
|
|
197
|
+
{
|
|
198
|
+
private readonly EnemyController enemy;
|
|
199
|
+
|
|
200
|
+
public ChaseState(EnemyController enemy) => this.enemy = enemy;
|
|
201
|
+
|
|
202
|
+
public void Enter()
|
|
203
|
+
{
|
|
204
|
+
enemy.PlayAnimation("Run");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public void Update(float deltaTime)
|
|
208
|
+
{
|
|
209
|
+
if (!enemy.PlayerInRange())
|
|
210
|
+
enemy.StateMachine.ChangeState(new IdleState(enemy));
|
|
211
|
+
else if (enemy.InAttackRange())
|
|
212
|
+
enemy.StateMachine.ChangeState(new AttackState(enemy));
|
|
213
|
+
else
|
|
214
|
+
enemy.MoveTowardsPlayer(deltaTime);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public void Exit() { }
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Command Pattern (Input Handling)
|
|
222
|
+
|
|
223
|
+
```csharp
|
|
224
|
+
public interface ICommand
|
|
225
|
+
{
|
|
226
|
+
void Execute();
|
|
227
|
+
void Undo();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public class MoveCommand : ICommand
|
|
231
|
+
{
|
|
232
|
+
private readonly Transform transform;
|
|
233
|
+
private readonly Vector3 movement;
|
|
234
|
+
private Vector3 previousPosition;
|
|
235
|
+
|
|
236
|
+
public MoveCommand(Transform transform, Vector3 movement)
|
|
237
|
+
{
|
|
238
|
+
this.transform = transform;
|
|
239
|
+
this.movement = movement;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public void Execute()
|
|
243
|
+
{
|
|
244
|
+
previousPosition = transform.position;
|
|
245
|
+
transform.position += movement;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public void Undo()
|
|
249
|
+
{
|
|
250
|
+
transform.position = previousPosition;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public class InputHandler
|
|
255
|
+
{
|
|
256
|
+
private Stack<ICommand> commandHistory = new();
|
|
257
|
+
|
|
258
|
+
public void ExecuteCommand(ICommand command)
|
|
259
|
+
{
|
|
260
|
+
command.Execute();
|
|
261
|
+
commandHistory.Push(command);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public void UndoLastCommand()
|
|
265
|
+
{
|
|
266
|
+
if (commandHistory.Count > 0)
|
|
267
|
+
{
|
|
268
|
+
ICommand command = commandHistory.Pop();
|
|
269
|
+
command.Undo();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Observer Pattern (Event System)
|
|
276
|
+
|
|
277
|
+
```csharp
|
|
278
|
+
public class GameEvent<T>
|
|
279
|
+
{
|
|
280
|
+
private event Action<T> listeners;
|
|
281
|
+
|
|
282
|
+
public void Subscribe(Action<T> listener)
|
|
283
|
+
{
|
|
284
|
+
listeners += listener;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public void Unsubscribe(Action<T> listener)
|
|
288
|
+
{
|
|
289
|
+
listeners -= listener;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public void Trigger(T data)
|
|
293
|
+
{
|
|
294
|
+
listeners?.Invoke(data);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Event hub
|
|
299
|
+
public static class GameEvents
|
|
300
|
+
{
|
|
301
|
+
public static readonly GameEvent<int> OnScoreChanged = new();
|
|
302
|
+
public static readonly GameEvent<float> OnHealthChanged = new();
|
|
303
|
+
public static readonly GameEvent<string> OnGameOver = new();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Subscriber
|
|
307
|
+
public class UIController
|
|
308
|
+
{
|
|
309
|
+
private void OnEnable()
|
|
310
|
+
{
|
|
311
|
+
GameEvents.OnScoreChanged.Subscribe(UpdateScoreDisplay);
|
|
312
|
+
GameEvents.OnHealthChanged.Subscribe(UpdateHealthBar);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private void OnDisable()
|
|
316
|
+
{
|
|
317
|
+
GameEvents.OnScoreChanged.Unsubscribe(UpdateScoreDisplay);
|
|
318
|
+
GameEvents.OnHealthChanged.Unsubscribe(UpdateHealthBar);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private void UpdateScoreDisplay(int score)
|
|
322
|
+
{
|
|
323
|
+
// Update UI
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private void UpdateHealthBar(float health)
|
|
327
|
+
{
|
|
328
|
+
// Update UI
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Publisher
|
|
333
|
+
public class Player
|
|
334
|
+
{
|
|
335
|
+
public void TakeDamage(float damage)
|
|
336
|
+
{
|
|
337
|
+
health -= damage;
|
|
338
|
+
GameEvents.OnHealthChanged.Trigger(health);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Service Locator Pattern
|
|
344
|
+
|
|
345
|
+
```csharp
|
|
346
|
+
public static class ServiceLocator
|
|
347
|
+
{
|
|
348
|
+
private static Dictionary<Type, object> services = new();
|
|
349
|
+
|
|
350
|
+
public static void Register<T>(T service)
|
|
351
|
+
{
|
|
352
|
+
services[typeof(T)] = service;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public static T Get<T>()
|
|
356
|
+
{
|
|
357
|
+
if (services.TryGetValue(typeof(T), out object service))
|
|
358
|
+
return (T)service;
|
|
359
|
+
|
|
360
|
+
throw new Exception($"Service {typeof(T)} not found");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
public static bool TryGet<T>(out T service)
|
|
364
|
+
{
|
|
365
|
+
if (services.TryGetValue(typeof(T), out object obj))
|
|
366
|
+
{
|
|
367
|
+
service = (T)obj;
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
service = default;
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
public static void Clear()
|
|
376
|
+
{
|
|
377
|
+
services.Clear();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Usage
|
|
382
|
+
public class GameInitializer
|
|
383
|
+
{
|
|
384
|
+
public void Initialize()
|
|
385
|
+
{
|
|
386
|
+
ServiceLocator.Register<IAudioManager>(new AudioManager());
|
|
387
|
+
ServiceLocator.Register<ISaveSystem>(new SaveSystem());
|
|
388
|
+
ServiceLocator.Register<IInputManager>(new InputManager());
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
public class Player
|
|
393
|
+
{
|
|
394
|
+
private IAudioManager audioManager;
|
|
395
|
+
|
|
396
|
+
public void Start()
|
|
397
|
+
{
|
|
398
|
+
audioManager = ServiceLocator.Get<IAudioManager>();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
public void PlaySound(string soundName)
|
|
402
|
+
{
|
|
403
|
+
audioManager.PlaySound(soundName);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Spatial Partitioning (Grid)
|
|
409
|
+
|
|
410
|
+
```csharp
|
|
411
|
+
public class SpatialGrid<T>
|
|
412
|
+
{
|
|
413
|
+
private readonly Dictionary<(int, int), List<T>> grid = new();
|
|
414
|
+
private readonly float cellSize;
|
|
415
|
+
|
|
416
|
+
public SpatialGrid(float cellSize)
|
|
417
|
+
{
|
|
418
|
+
this.cellSize = cellSize;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
private (int, int) GetCell(Vector2 position)
|
|
422
|
+
{
|
|
423
|
+
int x = Mathf.FloorToInt(position.x / cellSize);
|
|
424
|
+
int y = Mathf.FloorToInt(position.y / cellSize);
|
|
425
|
+
return (x, y);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
public void Insert(Vector2 position, T item)
|
|
429
|
+
{
|
|
430
|
+
var cell = GetCell(position);
|
|
431
|
+
if (!grid.ContainsKey(cell))
|
|
432
|
+
grid[cell] = new List<T>();
|
|
433
|
+
|
|
434
|
+
grid[cell].Add(item);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
public List<T> Query(Vector2 position, float radius)
|
|
438
|
+
{
|
|
439
|
+
List<T> results = new();
|
|
440
|
+
int cellRadius = Mathf.CeilToInt(radius / cellSize);
|
|
441
|
+
|
|
442
|
+
var centerCell = GetCell(position);
|
|
443
|
+
|
|
444
|
+
for (int x = -cellRadius; x <= cellRadius; x++)
|
|
445
|
+
{
|
|
446
|
+
for (int y = -cellRadius; y <= cellRadius; y++)
|
|
447
|
+
{
|
|
448
|
+
var cell = (centerCell.Item1 + x, centerCell.Item2 + y);
|
|
449
|
+
if (grid.TryGetValue(cell, out List<T> items))
|
|
450
|
+
results.AddRange(items);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return results;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
public void Clear()
|
|
458
|
+
{
|
|
459
|
+
grid.Clear();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
## Double Buffer Pattern (for Rendering/Physics)
|
|
465
|
+
|
|
466
|
+
```csharp
|
|
467
|
+
public class DoubleBuffer<T>
|
|
468
|
+
{
|
|
469
|
+
private T[] buffers = new T[2];
|
|
470
|
+
private int currentIndex = 0;
|
|
471
|
+
|
|
472
|
+
public DoubleBuffer(T buffer1, T buffer2)
|
|
473
|
+
{
|
|
474
|
+
buffers[0] = buffer1;
|
|
475
|
+
buffers[1] = buffer2;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
public T Current => buffers[currentIndex];
|
|
479
|
+
public T Next => buffers[1 - currentIndex];
|
|
480
|
+
|
|
481
|
+
public void Swap()
|
|
482
|
+
{
|
|
483
|
+
currentIndex = 1 - currentIndex;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Usage for physics
|
|
488
|
+
public class PhysicsSimulation
|
|
489
|
+
{
|
|
490
|
+
private DoubleBuffer<PhysicsState> stateBuffer;
|
|
491
|
+
|
|
492
|
+
public void Update(float deltaTime)
|
|
493
|
+
{
|
|
494
|
+
// Read from current, write to next
|
|
495
|
+
ComputeNextState(stateBuffer.Current, stateBuffer.Next, deltaTime);
|
|
496
|
+
|
|
497
|
+
// Swap buffers
|
|
498
|
+
stateBuffer.Swap();
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
```
|