İlk commit: Stepstead Godot istemci (4.6 Mobile)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jts 2026-07-11 11:31:35 +03:00
commit 6a1706051d
346 changed files with 14415 additions and 0 deletions

88
native/README.md Normal file
View file

@ -0,0 +1,88 @@
# Stepstead — Pedometer Native Eklentiler
Adım sayar soyutlaması `autoload/pedometer.gd` içinde. Native plugin yoksa
otomatik **simülasyon** moduna düşer (editör/masaüstü test). Gerçek cihazda
adım okumak için aşağıdaki native eklentiler derlenip projeye eklenmeli.
GDScript ↔ native sözleşmesi (her iki platform aynı):
| Metot | Dönüş | Açıklama |
|---------------------|-------|--------------------------------------------|
| `is_available()` | bool | Cihazda adım sayar sensörü var mı |
| `start()` | void | Dinlemeyi başlat |
| `stop()` | void | Dinlemeyi durdur |
| `get_step_count()` | int | Açılıştan beri kümülatif adım |
Singleton adları: Android = `StepCounter`, iOS = `Pedometer`.
---
## Android (`stepcounter-android/`) — Mac'te derleme
**Gereksinim:** Mac + Android Studio (Android SDK API 34 + JDK 17) + Godot 4.6.
Gradle projesi hazır: `settings.gradle`, `build.gradle`, `gradle.properties`,
wrapper config (`gradle/wrapper/gradle-wrapper.properties` → Gradle 8.5).
Eksik tek şey wrapper binary'si ve godot-lib — aşağıda.
### 1. Android Build Template'i kur (godot-lib.aar için)
Godot editöründe projeyi aç → **Project > Install Android Build Template**.
Bu, proje köküne `android/build/` oluşturur. Godot kütüphanesini bul:
```bash
find android/build -iname "godot-lib*.aar"
# örn: android/build/libs/release/godot-lib.template_release.aar
```
Bu AAR'ı plugin libs/ içine kopyala:
```bash
mkdir -p native/stepcounter-android/libs
cp android/build/libs/release/godot-lib.*.aar native/stepcounter-android/libs/
```
### 2. SDK yolunu bildir
```bash
cd native/stepcounter-android
echo "sdk.dir=$HOME/Library/Android/sdk" > local.properties
```
### 3. Gradle wrapper'ı üret + derle
Android Studio'da klasörü açarsan wrapper'ı otomatik üretir. CLI ile:
```bash
# Homebrew gradle ile tek seferlik wrapper üret (sonra ./gradlew yeter)
brew install gradle # yoksa
gradle wrapper --gradle-version 8.5
./gradlew assembleRelease
```
### 4. AAR'ı projeye koy + etkinleştir
```bash
cp build/outputs/aar/stepcounter-release.aar \
../../addons/stepcounter/stepcounter-release.aar
```
Godot: **Project > Project Settings > Plugins > StepCounter = Enable**.
Android export'unda **Use Gradle Build**ık olmalı.
İzin: `ACTIVITY_RECOGNITION` (Android 10+). Export plugin manifest'e ekler,
`pedometer.gd` çalışma zamanında `OS.request_permission(...)` ile ister.
> Not: `libs/`, `local.properties`, `.gradle/`, `build/` ve wrapper jar'ı
> repoya girmez (bkz `.gitignore`).
---
## iOS (`pedometer-ios/`) — yazıldı
`CMPedometer` (CoreMotion) Objective-C++ plugin. Singleton `Pedometer`,
aynı 4 metot. Kaynak + `.gdip` config + build/iPhone yükleme adımları:
**`pedometer-ios/README.md`**.
> CMPedometer iOS Simulator'da çalışmaz → iPhone 13 ile gerçek cihaz testi.
> Derleme godot-ios-plugins harness (scons) ile, Xcode'da imzalı yüklenir.
---
## Test (native plugin olmadan)
Editör/masaüstünde HUD'daki **+100** butonu `Pedometer.sim_add(100)` çağırır,
ardından `/world/sync-steps` ile sunucuya gider. Sunucu dakika-başı tavan
(anti-cheat) uygular; aşan adımlar reddedilir ve `step_log`'a `accepted=false`
olarak yazılır.

View file

@ -0,0 +1,75 @@
# Stepstead — iOS Pedometer Plugin (CMPedometer)
Godot 4 iOS plugin. `Pedometer` singleton'ı, `autoload/pedometer.gd` ile aynı
sözleşmeyi sağlar: `is_available / start / stop / get_step_count`.
**Kaynak dosyalar:**
- `pedometer.h`, `pedometer.mm` — singleton + CMPedometer mantığı
- `pedometer_module.h`, `pedometer_module.mm` — init/deinit (singleton kaydı)
- `pedometer.gdip` — plugin config (CoreMotion.framework + NSMotionUsageDescription)
> ⚠️ CMPedometer **iOS Simulator'da çalışmaz** (`is_available()` = false).
> Gerçek cihaz gerekir → **iPhone 13 ile test.**
---
## Derleme — godot-ios-plugins harness (Mac, önerilen)
**Gereksinim:** Mac + Xcode + command line tools + SCons (`brew install scons`).
```bash
# 1. Resmi iOS plugin harness'ını klonla
git clone https://github.com/godotengine/godot-ios-plugins.git
cd godot-ios-plugins
# 2. Godot 4.6 başlık dosyalarını üret (godot kaynağını çeker)
./scripts/generate_headers.sh 4.6.0.stable # repo README'sindeki sürüm formatı
# 3. Bu plugin'i plugins/ altına kopyala
cp -r /path/Stepstead/native/pedometer-ios plugins/pedometer
# 4. Derle (arm64, release) — çıktı bin/pedometer.*.a
scons target=template_release arch=arm64 plugin=pedometer version=4.6
scons target=template_debug arch=arm64 plugin=pedometer version=4.6
```
> SCons komutunun tam imzası harness sürümüne göre değişebilir; repo
> README'sini esas al. Çatı `plugins/pedometer/` altındaki tüm `.mm`
> dosyalarını otomatik derler.
---
## Godot projesine ekleme
1. Çıktıları projeye koy:
```
res://ios/plugins/pedometer/pedometer.a
res://ios/plugins/pedometer/pedometer.gdip
```
(`.gdip` zaten bu klasörde — `.a` ile birlikte kopyala.)
2. Godot: **Project > Export > iOS** preset'inde **Plugins** sekmesinde
`Pedometer` işaretli olmalı.
3. `.gdip` `NSMotionUsageDescription`'ı otomatik Info.plist'e ekler.
(Apple izni: ilk `start()` çağrısında sistem motion izni sorar.)
---
## iPhone 13'e yükleme (gerçek test)
1. Godot'ta iOS export → Xcode projesi üretir.
2. Xcode'da aç → **Signing & Capabilities**'da Apple ID (ücretsiz hesap olur,
7 günlük provisioning) ile imzala.
3. iPhone 13'ü kabloyla bağla → Xcode'da hedef cihaz seç → **Run**.
4. Oyunda login → `Pedometer.start()` (world.gd otomatik çağırır) →
sistem "Motion & Fitness" izni sorar → izin ver.
5. Telefonu cebe at, yürü → adım bakiyesi 30 sn'de bir `/world/sync-steps`
ile artar (sunucu anti-cheat tavanı 250/dk uygular).
---
## İleride (enhancement)
`startPedometerUpdatesFromDate:` uygulama açıkken sayar. Arka planda/kapalıyken
atılan adımları toparlamak için `queryPedometerDataFromDate:toDate:withHandler:`
ile son sync zamanından şu ana kadarki geçmişi çekmek gerekir (iOS 7 günlük
adım geçmişi tutar). MVP'de yok — `get_step_count` sadece oturum sayımı.

View file

@ -0,0 +1,15 @@
[config]
name="Pedometer"
binary="pedometer.a"
initialization="pedometer_init_module"
deinitialization="pedometer_deinit_module"
[dependencies]
linked=[]
embedded=[]
system=["CoreMotion.framework"]
capabilities=[]
files=[]
[plist]
NSMotionUsageDescription:string="Yürüyüş adımlarınızı sayarak oyunda ilerlemenizi sağlar."

View file

@ -0,0 +1,35 @@
// Stepstead — iOS Pedometer plugin (CMPedometer)
// Godot 4 iOS plugin. Singleton adı: "Pedometer"
//
// GDScript sözleşmesi (autoload/pedometer.gd ile eşleşir):
// bool is_available()
// void start()
// void stop()
// int get_step_count() -> oturum başından beri kümülatif adım
#ifndef STEPSTEAD_PEDOMETER_H
#define STEPSTEAD_PEDOMETER_H
#include "core/object/class_db.h"
#include "core/object/object.h"
class Pedometer : public Object {
GDCLASS(Pedometer, Object);
static Pedometer *instance;
protected:
static void _bind_methods();
public:
bool is_available();
void start();
void stop();
int get_step_count();
static Pedometer *get_singleton();
Pedometer();
~Pedometer();
};
#endif // STEPSTEAD_PEDOMETER_H

View file

@ -0,0 +1,85 @@
// Stepstead — iOS Pedometer plugin (CMPedometer) implementasyonu.
#import "pedometer.h"
#import <CoreMotion/CoreMotion.h>
#import <Foundation/Foundation.h>
// Objective-C tarafı: CMPedometer'ı tutar, adım sayısını günceller.
@interface StepsteadPedometer : NSObject
@property(nonatomic, strong) CMPedometer *pedometer;
@property(nonatomic, assign) int stepCount;
@property(nonatomic, strong) NSDate *sessionStart;
@property(nonatomic, assign) BOOL running;
@end
@implementation StepsteadPedometer
@end
static StepsteadPedometer *_ped = nil;
Pedometer *Pedometer::instance = nullptr;
void Pedometer::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_available"), &Pedometer::is_available);
ClassDB::bind_method(D_METHOD("start"), &Pedometer::start);
ClassDB::bind_method(D_METHOD("stop"), &Pedometer::stop);
ClassDB::bind_method(D_METHOD("get_step_count"), &Pedometer::get_step_count);
}
bool Pedometer::is_available() {
// Not: iOS Simulator'da daima false döner — gerçek cihaz gerekir.
return [CMPedometer isStepCountingAvailable] ? true : false;
}
void Pedometer::start() {
if (![CMPedometer isStepCountingAvailable]) {
return;
}
if (_ped == nil) {
_ped = [[StepsteadPedometer alloc] init];
_ped.pedometer = [[CMPedometer alloc] init];
_ped.stepCount = 0;
}
if (_ped.running) {
return;
}
_ped.running = YES;
_ped.sessionStart = [NSDate date];
_ped.stepCount = 0;
// Uygulama açıkken canlı güncelleme. numberOfSteps = sessionStart'tan beri.
[_ped.pedometer startPedometerUpdatesFromDate:_ped.sessionStart
withHandler:^(CMPedometerData *_Nullable data, NSError *_Nullable error) {
if (data != nil && error == nil) {
_ped.stepCount = [data.numberOfSteps intValue];
}
}];
}
void Pedometer::stop() {
if (_ped != nil && _ped.running) {
[_ped.pedometer stopPedometerUpdates];
_ped.running = NO;
}
}
int Pedometer::get_step_count() {
return _ped != nil ? _ped.stepCount : 0;
}
Pedometer *Pedometer::get_singleton() {
return instance;
}
Pedometer::Pedometer() {
ERR_FAIL_COND(instance != nullptr);
instance = this;
}
Pedometer::~Pedometer() {
if (_ped != nil) {
[_ped.pedometer stopPedometerUpdates];
_ped = nil;
}
instance = nullptr;
}

View file

@ -0,0 +1,8 @@
// Plugin init/deinit — godot-ios-plugins çatısı bu fonksiyonları çağırır.
#ifndef STEPSTEAD_PEDOMETER_MODULE_H
#define STEPSTEAD_PEDOMETER_MODULE_H
void pedometer_init_module();
void pedometer_deinit_module();
#endif // STEPSTEAD_PEDOMETER_MODULE_H

View file

@ -0,0 +1,20 @@
#import "pedometer_module.h"
#import "pedometer.h"
#import "core/config/engine.h"
#import "core/object/class_db.h"
Pedometer *pedometer_singleton = nullptr;
void pedometer_init_module() {
ClassDB::register_class<Pedometer>();
pedometer_singleton = memnew(Pedometer);
Engine::get_singleton()->add_singleton(Engine::Singleton("Pedometer", pedometer_singleton));
}
void pedometer_deinit_module() {
if (pedometer_singleton) {
memdelete(pedometer_singleton);
pedometer_singleton = nullptr;
}
}

8
native/stepcounter-android/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
.gradle/
build/
libs/
local.properties
.idea/
*.iml
# wrapper binary makinede üretilir
gradle/wrapper/gradle-wrapper.jar

View file

@ -0,0 +1,38 @@
// StepCounter Godot 4 Android plugin (AAR)
// Derleme (Mac, Android SDK + JDK 17):
// 1. godot-lib.<sürüm>.release.aar dosyasını libs/ içine koy
// (Godot editöründen: AndroidStudio export template, veya
// https://github.com/godotengine/godot/releases içindeki
// godot-lib aar Godot 4.6 ile eşleşmeli)
// 2. ./gradlew assembleRelease
// 3. Çıktı: build/outputs/aar/stepcounter-release.aar
// 4. AAR'ı res://addons/stepcounter/ altına kopyala
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.stepstead.stepcounter'
compileSdk 34
defaultConfig {
minSdk 24 // Android 7.0 TYPE_STEP_COUNTER için yeterli
targetSdk 34
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
}
dependencies {
// Godot kütüphanesi sürüm Godot editörüyle birebir eşleşmeli (4.6)
compileOnly fileTree(dir: 'libs', include: ['godot-lib.*.aar'])
implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.1.0'
}

View file

@ -0,0 +1,6 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
android.aapt2FromMavenOverride=/home/Jts/Android/Sdk/build-tools/34.0.0/aapt2
android.disableResourceValidation=true

View file

@ -0,0 +1,6 @@
#Wed Jan 17 12:08:26 PST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
native/stepcounter-android/gradlew vendored Executable file
View file

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
native/stepcounter-android/gradlew.bat vendored Normal file
View file

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View file

@ -0,0 +1,21 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
plugins {
id 'com.android.library' version '8.2.2'
id 'org.jetbrains.kotlin.android' version '2.1.0'
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = 'stepcounter'

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Android 10+ (API 29) adım sayar için çalışma zamanı izni gerektirir -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-feature android:name="android.hardware.sensor.stepcounter" android:required="false" />
</manifest>

View file

@ -0,0 +1,75 @@
package com.stepstead.stepcounter
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import org.godotengine.godot.Godot
import org.godotengine.godot.plugin.GodotPlugin
import org.godotengine.godot.plugin.SignalInfo
import org.godotengine.godot.plugin.UsedByGodot
/**
* Godot 4 Android eklentisi TYPE_STEP_COUNTER sensörü.
*
* GDScript sözleşmesi (Pedometer.gd ile eşleşir):
* bool is_available()
* void start()
* void stop()
* int get_step_count() -> reboot'tan beri kümülatif adım (Int)
*
* Sinyal: step_count_updated(total: Int)
*
* Singleton adı: "StepCounter"
*/
class StepCounterPlugin(godot: Godot) : GodotPlugin(godot), SensorEventListener {
private var sensorManager: SensorManager? = null
private var stepSensor: Sensor? = null
private var lastTotal: Int = 0
private var listening: Boolean = false
override fun getPluginName(): String = "StepCounter"
override fun getPluginSignals(): Set<SignalInfo> =
setOf(SignalInfo("step_count_updated", Integer::class.java))
@UsedByGodot
fun is_available(): Boolean {
val ctx = activity ?: return false
val sm = ctx.getSystemService(Context.SENSOR_SERVICE) as? SensorManager ?: return false
return sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER) != null
}
@UsedByGodot
fun start() {
if (listening) return
val ctx = activity ?: return
sensorManager = ctx.getSystemService(Context.SENSOR_SERVICE) as? SensorManager
stepSensor = sensorManager?.getDefaultSensor(Sensor.TYPE_STEP_COUNTER)
if (stepSensor != null) {
sensorManager?.registerListener(this, stepSensor, SensorManager.SENSOR_DELAY_NORMAL)
listening = true
}
}
@UsedByGodot
fun stop() {
if (!listening) return
sensorManager?.unregisterListener(this)
listening = false
}
@UsedByGodot
fun get_step_count(): Int = lastTotal
override fun onSensorChanged(event: SensorEvent?) {
if (event == null || event.sensor.type != Sensor.TYPE_STEP_COUNTER) return
// event.values[0] = cihaz açılışından beri toplam adım (float)
lastTotal = event.values[0].toInt()
emitSignal("step_count_updated", lastTotal)
}
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
}